From 9667dc9166513ba0e99043920cf80562f8a8b926 Mon Sep 17 00:00:00 2001 From: Dan Raymond Date: Sat, 13 Jun 2026 22:39:37 -0600 Subject: [PATCH] Focus does not return to the main window when closing File Chooser The changes from GIMP #14901 (Wild strobing in multi window mode) introduced two regressions that made it into the 3.24.52 release: (1) Focus does not move to a newly opened dialog window. (2) Focus does not return to the main window when a dialog is closed. The changes that caused (1) have since been reverted on the gtk-3-24 branch (commit f80b61d6). This commit fixes (2). Fixes #8237 Part-of: --- gdk/quartz/gdkwindow-quartz.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git gdk/quartz/gdkwindow-quartz.c gdk/quartz/gdkwindow-quartz.c index 672103f7bd6..9fe7f4a203e 100644 --- gdk/quartz/gdkwindow-quartz.c +++ gdk/quartz/gdkwindow-quartz.c @@ -791,12 +791,27 @@ _gdk_quartz_window_did_become_main (GdkWindow *window) void _gdk_quartz_window_did_resign_main (GdkWindow *window) { - /* Don't try to make another window key when one resigns main. - * macOS handles this automatically, and GTK's attempt to manage focus - * here causes focus fighting between windows. + GdkWindow *new_window = window->transient_for; + + /* Explicitly reassign focus only if a dialog/transient is closing. + * For normal window switches, macOS handles focus automatically. + * Unconditionally reassigning focus here causes fighting in + * multi-window apps. * See: https://gitlab.gnome.org/GNOME/gimp/-/issues/14901 * https://gitlab.gnome.org/GNOME/gimp/-/issues/15480 */ + + if (new_window && + new_window != window && + GDK_WINDOW_IS_MAPPED (new_window) && + WINDOW_IS_TOPLEVEL (new_window)) + { + GdkWindowImplQuartz *impl = gdk_window_get_quartz_impl (new_window); + + if (impl) + [impl->toplevel makeKeyAndOrderFront:impl->toplevel]; + } + clear_toplevel_order (); } -- GitLab