summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hergert <christian@hergert.me>2022-03-11 18:07:34 -0800
committerChristian Hergert <chergert@redhat.com>2022-03-16 12:25:10 -0700
commita9c89fa23e883823e7967555ba905a005b5351e8 (patch)
tree69f9377e97bf5a21cd5292bd69333253174ef2ba
parent36730537cc9de22f712829b8ed10b8efc57c8be5 (diff)
downloadgtk+-a9c89fa23e883823e7967555ba905a005b5351e8.tar.gz
macos: dont steal key window from NSPanel
Or we risk making it really difficult to use native file choosers.
-rw-r--r--gdk/macos/gdkmacosdisplay-private.h5
-rw-r--r--gdk/macos/gdkmacosdisplay.c9
2 files changed, 14 insertions, 0 deletions
diff --git a/gdk/macos/gdkmacosdisplay-private.h b/gdk/macos/gdkmacosdisplay-private.h
index 1edff58d04..83ae435e49 100644
--- a/gdk/macos/gdkmacosdisplay-private.h
+++ b/gdk/macos/gdkmacosdisplay-private.h
@@ -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
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 6c51ef901e..d85a744563 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -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;