Browse Source

Merge pull request #8165 from AvaloniaUI/fixes/position-osx

Fix more OSX regressions
Dan Walmsley 3 years ago
parent
commit
060ec9694b

+ 0 - 17
native/Avalonia.Native/src/OSX/PopupImpl.mm

@@ -34,23 +34,6 @@ protected:
         return NSWindowStyleMaskBorderless;
     }
 
-    virtual HRESULT Resize(double x, double y, AvnPlatformResizeReason reason) override
-    {
-        START_COM_CALL;
-
-        @autoreleasepool
-        {
-            if (Window != nullptr)
-            {
-                [Window setContentSize:NSSize{x, y}];
-
-                [Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(lastPositionSet))];
-            }
-
-            return S_OK;
-        }
-    }
-
 public:
     virtual bool ShouldTakeFocusOnShow() override
     {

+ 1 - 0
native/Avalonia.Native/src/OSX/WindowBaseImpl.h

@@ -35,6 +35,7 @@ BEGIN_INTERFACE_MAP()
     ComPtr<IAvnGlContext> _glContext;
     NSObject <IRenderTarget> *renderTarget;
     AvnPoint lastPositionSet;
+    bool hasPosition;
     NSSize lastSize;
     NSSize lastMinSize;
     NSSize lastMaxSize;

+ 9 - 6
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@@ -30,8 +30,8 @@ WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl)
     View = [[AvnView alloc] initWithParent:this];
     StandardContainer = [[AutoFitContentView new] initWithContent:View];
 
-    lastPositionSet.X = -1;
-    lastPositionSet.Y = -1;
+    lastPositionSet = { 0, 0 };
+    hasPosition = false;
     lastSize = NSSize { 100, 100 };
     lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX};
     lastMinSize = NSSize { 0, 0 };
@@ -92,9 +92,12 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
         CreateNSWindow(isDialog);
         InitialiseNSWindow();
 
-        if(lastPositionSet.X >= 0 && lastPositionSet.Y >= 0)
+        if(hasPosition)
         {
             SetPosition(lastPositionSet);
+        } else
+        {
+            [Window center];
         }
 
         UpdateStyle();
@@ -288,12 +291,12 @@ HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reaso
         }
 
         @try {
+            lastSize = NSSize {x, y};
+
             if (!_shown) {
                 BaseEvents->Resized(AvnSize{x, y}, reason);
             }
 
-            lastSize = NSSize {x, y};
-
             if(Window != nullptr) {
                 [Window setContentSize:lastSize];
             }
@@ -385,6 +388,7 @@ HRESULT WindowBaseImpl::SetPosition(AvnPoint point) {
 
     @autoreleasepool {
         lastPositionSet = point;
+        hasPosition = true;
 
         if(Window != nullptr) {
             [Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(point))];
@@ -577,7 +581,6 @@ void WindowBaseImpl::InitialiseNSWindow() {
         [Window setContentMaxSize:lastMaxSize];
 
         [Window setOpaque:false];
-        [Window center];
 
         if (lastMenu != nullptr) {
             [GetWindowProtocol() applyMenu:lastMenu];