[gtk/wip/chergert/macos-iosurface: 9/11] macos: improve position of window during unmaximize




commit 99d63e5e52df3947b0c617aa9e8da7a7fd8cd774
Author: Christian Hergert <christian hergert me>
Date:   Mon Feb 14 02:17:13 2022 -0800

    macos: improve position of window during unmaximize
    
    Previously the size would stay the same but we'd regain a shadow. This
    makes it jump back to the old size like we would on Wayland.

 gdk/macos/GdkMacosWindow.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/gdk/macos/GdkMacosWindow.c b/gdk/macos/GdkMacosWindow.c
index ba7c635b0a..8ccc22b560 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -231,7 +231,24 @@ typedef NSString *CALayerContentsGravity;
 
   /* In case the window is changed when maximized remove the maximized state */
   if (maximized && !inMaximizeTransition && !NSEqualRects (lastMaximizedFrame, [self frame]))
-    [self windowDidUnmaximize];
+    {
+      NSRect last = lastUnmaximizedFrame;
+      NSRect newFrame = [self frame];
+
+      [self windowDidUnmaximize];
+
+      /* If we had a previous position, try to give the user something
+       * that resembles they grabbed it even though our warp could have
+       * made it a bit of a jump.
+       */
+      if (!CGRectIsNull (last))
+        {
+          newFrame.size = last.size;
+          newFrame.origin = [self mouseLocationOutsideOfEventStream];
+          newFrame.origin.x -= last.size.width / 2;
+          [self setFrame:newFrame display:NO];
+        }
+    }
 
   _gdk_macos_surface_update_position (gdk_surface);
   _gdk_macos_surface_reposition_children (gdk_surface);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]