Jelajahi Sumber

[OSX] cache IsClientAreaExtendedToDecorations, and apply it when NSPanel / NSWindow is created and Shown.

Dan Walmsley 3 tahun lalu
induk
melakukan
08487446d9

+ 35 - 21
native/Avalonia.Native/src/OSX/WindowImpl.mm

@@ -55,8 +55,20 @@ HRESULT WindowImpl::Show(bool activate, bool isDialog) {
 
     @autoreleasepool {
         _isDialog = isDialog;
+
+        bool created = Window == nullptr;
+
         WindowBaseImpl::Show(activate, isDialog);
 
+        if(created)
+        {
+            if(_isClientAreaExtended)
+            {
+                [GetWindowProtocol() setIsExtended:true];
+                SetExtendClientArea(true);
+            }
+        }
+
         HideOrShowTrafficLights();
 
         return SetWindowState(_lastWindowState);
@@ -327,37 +339,39 @@ HRESULT WindowImpl::SetExtendClientArea(bool enable) {
     @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;
     }

+ 1 - 1
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

@@ -18,7 +18,7 @@ namespace ControlCatalog.ViewModels
         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;

+ 7 - 0
src/Avalonia.Native/WindowImpl.cs

@@ -107,6 +107,13 @@ namespace Avalonia.Native
         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)