Skip to content

Commit

Permalink
Merge pull request #8112 from AvaloniaUI/osx-nswindow-refactor-part4
Browse files Browse the repository at this point in the history
[OSX] cache IsClientAreaExtendedToDecorations, and apply it when NSPa…
  • Loading branch information
danwalmsley committed May 10, 2022
1 parent 369ff63 commit 0054183
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
56 changes: 35 additions & 21 deletions native/Avalonia.Native/src/OSX/WindowImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,20 @@

@autoreleasepool {
_isDialog = isDialog;

bool created = Window == nullptr;

WindowBaseImpl::Show(activate, isDialog);

if(created)
{
if(_isClientAreaExtended)
{
[GetWindowProtocol() setIsExtended:true];
SetExtendClientArea(true);
}
}

HideOrShowTrafficLights();

return SetWindowState(_lastWindowState);
Expand Down Expand Up @@ -326,37 +338,39 @@
@autoreleasepool {
_isClientAreaExtended = enable;

if (enable) {
Window.titleVisibility = NSWindowTitleHidden;
if(Window != nullptr) {
if (enable) {
Window.titleVisibility = NSWindowTitleHidden;

[Window setTitlebarAppearsTransparent:true];
[Window setTitlebarAppearsTransparent:true];

auto wantsTitleBar = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
auto wantsTitleBar = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);

if (wantsTitleBar) {
[StandardContainer ShowTitleBar:true];
} else {
[StandardContainer ShowTitleBar:false];
}
if (wantsTitleBar) {
[StandardContainer ShowTitleBar:true];
} else {
[StandardContainer ShowTitleBar:false];
}

if (_extendClientHints & AvnOSXThickTitleBar) {
Window.toolbar = [NSToolbar new];
Window.toolbar.showsBaselineSeparator = false;
if (_extendClientHints & AvnOSXThickTitleBar) {
Window.toolbar = [NSToolbar new];
Window.toolbar.showsBaselineSeparator = false;
} else {
Window.toolbar = nullptr;
}
} else {
Window.titleVisibility = NSWindowTitleVisible;
Window.toolbar = nullptr;
[Window setTitlebarAppearsTransparent:false];
View.layer.zPosition = 0;
}
} else {
Window.titleVisibility = NSWindowTitleVisible;
Window.toolbar = nullptr;
[Window setTitlebarAppearsTransparent:false];
View.layer.zPosition = 0;
}

[GetWindowProtocol() setIsExtended:enable];
[GetWindowProtocol() setIsExtended:enable];

HideOrShowTrafficLights();
HideOrShowTrafficLights();

UpdateStyle();
UpdateStyle();
}

return S_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MainWindowViewModel : ViewModelBase
private WindowState _windowState;
private WindowState[] _windowStates;
private int _transparencyLevel;
private ExtendClientAreaChromeHints _chromeHints;
private ExtendClientAreaChromeHints _chromeHints = ExtendClientAreaChromeHints.PreferSystemChrome;
private bool _extendClientAreaEnabled;
private bool _systemTitleBarEnabled;
private bool _preferSystemChromeEnabled;
Expand Down
7 changes: 7 additions & 0 deletions src/Avalonia.Native/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ public WindowState WindowState
private bool _isExtended;
public bool IsClientAreaExtendedToDecorations => _isExtended;

public override void Show(bool activate, bool isDialog)
{
base.Show(activate, isDialog);

InvalidateExtendedMargins();
}

protected override bool ChromeHitTest (RawPointerEventArgs e)
{
if(_isExtended)
Expand Down

0 comments on commit 0054183

Please sign in to comment.