[gtk/wip/chergert/quartz4u: 112/146] macos: track monitor changes and update surface positions



commit 9904dfdfbca6ee4c136310fa37e63d3f823b2a06
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 21 11:02:25 2020 -0700

    macos: track monitor changes and update surface positions
    
    This fixes moving windows between monitors when they change
    as well as ensuring we have the right x,y coordinate for monitor
    discovery and edge snapping.

 gdk/macos/gdkmacosdisplay.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 73802dc1ce..65c2fa1967 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -191,6 +191,22 @@ gdk_macos_display_monitors_changed_cb (CFNotificationCenterRef  center,
   g_assert (GDK_IS_MACOS_DISPLAY (self));
 
   _gdk_macos_display_reload_monitors (self);
+
+  /* Now we need to update all our surface positions since they
+   * probably just changed origins. We ignore the popup surfaces
+   * since we can rely on the toplevel surfaces to handle that.
+   */
+  for (const GList *iter = _gdk_macos_display_get_surfaces (self);
+       iter != NULL;
+       iter = iter->next)
+    {
+      GdkMacosSurface *surface = iter->data;
+
+      g_assert (GDK_IS_MACOS_SURFACE (surface));
+
+      if (GDK_IS_TOPLEVEL (surface))
+        _gdk_macos_surface_update_position (surface);
+    }
 }
 
 static void
@@ -670,7 +686,7 @@ _gdk_macos_display_open (const gchar *display_name)
   gdk_macos_display_load_display_link (self);
   _gdk_macos_display_reload_monitors (self);
 
-  CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (),
+  CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter (),
                                    self,
                                    gdk_macos_display_monitors_changed_cb,
                                    CFSTR ("NSApplicationDidChangeScreenParametersNotification"),


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