[gtk/wip/chergert/quartz4u: 99/142] macos: check transient-for first for focus (key window) change



commit 3ad3b1a7de01d13e20cd09da015143b74a14a094
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 20 19:47:32 2020 -0700

    macos: check transient-for first for focus (key window) change

 gdk/macos/gdkmacosdisplay.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 7b83504fb0..73802dc1ce 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -503,7 +503,7 @@ void
 _gdk_macos_display_surface_resigned_main (GdkMacosDisplay *self,
                                           GdkMacosSurface *surface)
 {
-  const GList *surfaces;
+  GdkMacosSurface *new_surface = NULL;
 
   g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
   g_return_if_fail (GDK_IS_MACOS_SURFACE (surface));
@@ -512,25 +512,39 @@ _gdk_macos_display_surface_resigned_main (GdkMacosDisplay *self,
     g_queue_unlink (&self->main_surfaces, &surface->main);
 
   _gdk_macos_display_clear_sorting (self);
-  surfaces = _gdk_macos_display_get_surfaces (self);
 
-  for (const GList *iter = surfaces; iter; iter = iter->next)
+  if (GDK_SURFACE (surface)->transient_for &&
+      gdk_surface_get_mapped (GDK_SURFACE (surface)->transient_for))
+    {
+      new_surface = GDK_MACOS_SURFACE (GDK_SURFACE (surface)->transient_for);
+    }
+  else
     {
-      GdkMacosSurface *new_surface = iter->data;
+      const GList *surfaces = _gdk_macos_display_get_surfaces (self);
 
-      g_assert (GDK_IS_MACOS_SURFACE (new_surface));
+      for (const GList *iter = surfaces; iter; iter = iter->next)
+        {
+          GdkMacosSurface *item = iter->data;
 
-      if (new_surface == surface)
-        continue;
+          g_assert (GDK_IS_MACOS_SURFACE (item));
 
-      if (GDK_SURFACE_IS_MAPPED (GDK_SURFACE (new_surface)))
-        {
-          NSWindow *nswindow = _gdk_macos_surface_get_native (new_surface);
-          [nswindow makeKeyAndOrderFront:nswindow];
-          break;
+          if (item == surface)
+            continue;
+
+          if (GDK_SURFACE_IS_MAPPED (GDK_SURFACE (item)))
+            {
+              new_surface = item;
+              break;
+            }
         }
     }
 
+  if (new_surface != NULL)
+    {
+      NSWindow *nswindow = _gdk_macos_surface_get_native (new_surface);
+      [nswindow makeKeyAndOrderFront:nswindow];
+    }
+
   _gdk_macos_display_clear_sorting (self);
 }
 


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