Skip to content

Commit 0054183

Browse files
committed
Merge pull request AvaloniaUI#8112 from AvaloniaUI/osx-nswindow-refactor-part4
[OSX] cache IsClientAreaExtendedToDecorations, and apply it when NSPa…
1 parent 369ff63 commit 0054183

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

native/Avalonia.Native/src/OSX/WindowImpl.mm

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,20 @@
5454

5555
@autoreleasepool {
5656
_isDialog = isDialog;
57+
58+
bool created = Window == nullptr;
59+
5760
WindowBaseImpl::Show(activate, isDialog);
5861

62+
if(created)
63+
{
64+
if(_isClientAreaExtended)
65+
{
66+
[GetWindowProtocol() setIsExtended:true];
67+
SetExtendClientArea(true);
68+
}
69+
}
70+
5971
HideOrShowTrafficLights();
6072

6173
return SetWindowState(_lastWindowState);
@@ -326,37 +338,39 @@
326338
@autoreleasepool {
327339
_isClientAreaExtended = enable;
328340

329-
if (enable) {
330-
Window.titleVisibility = NSWindowTitleHidden;
341+
if(Window != nullptr) {
342+
if (enable) {
343+
Window.titleVisibility = NSWindowTitleHidden;
331344

332-
[Window setTitlebarAppearsTransparent:true];
345+
[Window setTitlebarAppearsTransparent:true];
333346

334-
auto wantsTitleBar = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
347+
auto wantsTitleBar = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
335348

336-
if (wantsTitleBar) {
337-
[StandardContainer ShowTitleBar:true];
338-
} else {
339-
[StandardContainer ShowTitleBar:false];
340-
}
349+
if (wantsTitleBar) {
350+
[StandardContainer ShowTitleBar:true];
351+
} else {
352+
[StandardContainer ShowTitleBar:false];
353+
}
341354

342-
if (_extendClientHints & AvnOSXThickTitleBar) {
343-
Window.toolbar = [NSToolbar new];
344-
Window.toolbar.showsBaselineSeparator = false;
355+
if (_extendClientHints & AvnOSXThickTitleBar) {
356+
Window.toolbar = [NSToolbar new];
357+
Window.toolbar.showsBaselineSeparator = false;
358+
} else {
359+
Window.toolbar = nullptr;
360+
}
345361
} else {
362+
Window.titleVisibility = NSWindowTitleVisible;
346363
Window.toolbar = nullptr;
364+
[Window setTitlebarAppearsTransparent:false];
365+
View.layer.zPosition = 0;
347366
}
348-
} else {
349-
Window.titleVisibility = NSWindowTitleVisible;
350-
Window.toolbar = nullptr;
351-
[Window setTitlebarAppearsTransparent:false];
352-
View.layer.zPosition = 0;
353-
}
354367

355-
[GetWindowProtocol() setIsExtended:enable];
368+
[GetWindowProtocol() setIsExtended:enable];
356369

357-
HideOrShowTrafficLights();
370+
HideOrShowTrafficLights();
358371

359-
UpdateStyle();
372+
UpdateStyle();
373+
}
360374

361375
return S_OK;
362376
}

samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MainWindowViewModel : ViewModelBase
1717
private WindowState _windowState;
1818
private WindowState[] _windowStates;
1919
private int _transparencyLevel;
20-
private ExtendClientAreaChromeHints _chromeHints;
20+
private ExtendClientAreaChromeHints _chromeHints = ExtendClientAreaChromeHints.PreferSystemChrome;
2121
private bool _extendClientAreaEnabled;
2222
private bool _systemTitleBarEnabled;
2323
private bool _preferSystemChromeEnabled;

src/Avalonia.Native/WindowImpl.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ public WindowState WindowState
108108
private bool _isExtended;
109109
public bool IsClientAreaExtendedToDecorations => _isExtended;
110110

111+
public override void Show(bool activate, bool isDialog)
112+
{
113+
base.Show(activate, isDialog);
114+
115+
InvalidateExtendedMargins();
116+
}
117+
111118
protected override bool ChromeHitTest (RawPointerEventArgs e)
112119
{
113120
if(_isExtended)

0 commit comments

Comments
 (0)