[gtk/wip/chergert/for-main] macos: avoid size/origin changes when possible



commit 51607ce93c2d27fe1314ee54685a122a2abffac3
Author: Christian Hergert <christian hergert me>
Date:   Mon Feb 28 13:09:57 2022 -0800

    macos: avoid size/origin changes when possible
    
    If _gdk_macos_surface_move_resize() was called with various -1 parameters
    we really want to avoid changing anything even if we think we know what
    the value might be. Otherwise, we risk messing up in-flight operations that
    we have not yet been notified of yet.
    
    This improves the chances we place windows in an appropriate location as
    they don't et screwed up before window-manager placement.

 gdk/macos/gdkmacossurface.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index 4cd9994800..cb900a7328 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -963,13 +963,17 @@ _gdk_macos_surface_move_resize (GdkMacosSurface *self,
   GdkDisplay *display;
   NSRect content_rect;
   NSRect frame_rect;
+  gboolean ignore_move;
+  gboolean ignore_size;
 
   g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
 
-  if ((x == -1 || (x == self->root_x)) &&
-      (y == -1 || (y == self->root_y)) &&
-      (width == -1 || (width == surface->width)) &&
-      (height == -1 || (height == surface->height)))
+  ignore_move = (x == -1 || (x == self->root_x)) &&
+                (y == -1 || (y == self->root_y));
+  ignore_size = (width == -1 || (width == surface->width)) &&
+                (height == -1 || (height == surface->height));
+
+  if (ignore_move && ignore_size)
     return;
 
   display = gdk_surface_get_display (surface);
@@ -990,7 +994,14 @@ _gdk_macos_surface_move_resize (GdkMacosSurface *self,
                                         x, y + height,
                                         &x, &y);
 
-  content_rect = NSMakeRect (x, y, width, height);
+  content_rect = [self->window contentRectForFrameRect:[self->window frame]];
+
+  if (!ignore_move)
+    content_rect.origin = NSMakePoint (x, y);
+
+  if (!ignore_size)
+    content_rect.size = NSMakeSize (width, height);
+
   frame_rect = [self->window frameRectForContentRect:content_rect];
   [self->window setFrame:frame_rect display:YES];
 }


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