[gtk/wip/chergert/for-main] macos: improve initial positioning of toplevel with parent



commit 1e4ebccb9e4a8aa87dbab76e75c0bcea15370eaa
Author: Christian Hergert <christian hergert me>
Date:   Tue Mar 1 00:05:52 2022 -0800

    macos: improve initial positioning of toplevel with parent
    
    This does not happen very often, but if we do get a topleve with a parent
    on the initial creation, try to position it a bit better for the screen
    coordinates (as they need to be relative to the NSScreen provided).

 gdk/macos/gdkmacostoplevelsurface.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/gdk/macos/gdkmacostoplevelsurface.c b/gdk/macos/gdkmacostoplevelsurface.c
index d89434593b..956673e89f 100644
--- a/gdk/macos/gdkmacostoplevelsurface.c
+++ b/gdk/macos/gdkmacostoplevelsurface.c
@@ -648,10 +648,10 @@ _gdk_macos_toplevel_surface_new (GdkMacosDisplay *display,
 
   GdkMacosWindow *window;
   GdkMacosSurface *self;
-  NSScreen *screen;
   NSUInteger style_mask;
   NSRect content_rect;
-  NSRect screen_rect;
+  NSRect visible_frame;
+  NSScreen *screen;
   int nx;
   int ny;
 
@@ -664,14 +664,17 @@ _gdk_macos_toplevel_surface_new (GdkMacosDisplay *display,
                 NSWindowStyleMaskMiniaturizable |
                 NSWindowStyleMaskResizable);
 
-  _gdk_macos_display_to_display_coords (display, x, y, &nx, &ny);
+  if (parent != NULL)
+    {
+      x += GDK_MACOS_SURFACE (parent)->root_x;
+      y += GDK_MACOS_SURFACE (parent)->root_y;
+    }
+
+  _gdk_macos_display_to_display_coords (display, x, y + height, &nx, &ny);
 
   screen = _gdk_macos_display_get_screen_at_display_coords (display, nx, ny);
-  screen_rect = [screen visibleFrame];
-  nx -= screen_rect.origin.x;
-  ny -= screen_rect.origin.y;
-  content_rect = NSMakeRect (nx, ny - height, width, height);
-
+  visible_frame = [screen visibleFrame];
+  content_rect = NSMakeRect (nx - visible_frame.origin.x, ny - visible_frame.origin.y, width, height);
   window = [[GdkMacosWindow alloc] initWithContentRect:content_rect
                                              styleMask:style_mask
                                                backing:NSBackingStoreBuffered


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