[gtk/wip/chergert/macos-iosurface: 2/4] macos: improve position and size during unmaximize




commit 38b9dab3850521af5fb679eda19008d6da2ea8cc
Author: Christian Hergert <christian hergert me>
Date:   Fri Feb 11 20:09:44 2022 -0800

    macos: improve position and size during unmaximize
    
    If we've unmaximized by dragging the window, it would be nice to restore
    the previous window size to the user automatically. This can happen in
    other ways too, but during drag/move it is a special case on macOS.

 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 8401f45860..3ec436e064 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -229,7 +229,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:YES];
+        }
+    }
 
   _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]