macos: dont steal key window from NSPanel
authorChristian Hergert <christian@hergert.me>
Sat, 12 Mar 2022 02:07:34 +0000 (18:07 -0800)
committerChristian Hergert <christian@hergert.me>
Sat, 12 Mar 2022 02:07:34 +0000 (18:07 -0800)
Or we risk making it really difficult to use native file choosers.

gdk/macos/gdkmacosdisplay-private.h
gdk/macos/gdkmacosdisplay.c

index 1edff58d042e25c3c69b64f1d96c6830ab500059..83ae435e49db2c1f0131d31377c194fdd0874da9 100644 (file)
@@ -87,6 +87,11 @@ struct _GdkMacosDisplay
 
   /* A GSource to select a new main/key window */
   guint select_key_in_idle;
+
+  /* Note if we have a key window that is not a GdkMacosWindow
+   * such as a NSPanel used for native dialogs.
+   */
+  guint key_window_is_foregin : 1;
 };
 
 struct _GdkMacosDisplayClass
index 6c51ef901ee9d60ff5f66b22b4bcb8e220c19d49..d85a744563e16a08e77b81eb659039e7d89031e5 100644 (file)
@@ -422,6 +422,10 @@ select_key_in_idle_cb (gpointer data)
 
   self->select_key_in_idle = 0;
 
+  /* Don't steal focus from NSPanel, etc */
+  if (self->key_window_is_foregin)
+    return G_SOURCE_REMOVE;
+
   if (self->keyboard_surface == NULL)
     {
       const GList *surfaces = _gdk_macos_display_get_surfaces (self);
@@ -960,11 +964,16 @@ _gdk_macos_display_get_surfaces (GdkMacosDisplay *self)
       NSArray *array = [NSApp orderedWindows];
       GQueue sorted = G_QUEUE_INIT;
 
+      self->key_window_is_foregin = FALSE;
+
       for (id obj in array)
         {
           NSWindow *nswindow = (NSWindow *)obj;
           GdkMacosSurface *surface;
 
+          if ([nswindow isKeyWindow])
+            self->key_window_is_foregin = !GDK_IS_MACOS_WINDOW (nswindow);
+
           if (!GDK_IS_MACOS_WINDOW (nswindow))
             continue;