[gtk/wip/chergert/macos-iosurface: 4/7] macos: restore key window after hiding popup




commit b2de83efcbf2bf1b97f5c9804ed260199892b7f1
Author: Christian Hergert <christian hergert me>
Date:   Wed Feb 16 18:26:59 2022 -0800

    macos: restore key window after hiding popup
    
    This fixes the focus returning to the parent window after the popup has
    been hidden in the form of being a "Key Window" in macOS.

 gdk/macos/gdkmacossurface.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
---
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index cc7bbd9b9b..5404d1e3b8 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -133,6 +133,7 @@ gdk_macos_surface_hide (GdkSurface *surface)
   GdkMacosSurface *self = (GdkMacosSurface *)surface;
   GdkSeat *seat;
   gboolean was_mapped;
+  gboolean was_key;
 
   g_assert (GDK_IS_MACOS_SURFACE (self));
 
@@ -141,6 +142,7 @@ gdk_macos_surface_hide (GdkSurface *surface)
   _gdk_macos_display_remove_frame_callback (GDK_MACOS_DISPLAY (surface->display), self);
 
   was_mapped = GDK_SURFACE_IS_MAPPED (GDK_SURFACE (self));
+  was_key = [self->window isKeyWindow];
 
   seat = gdk_display_get_default_seat (surface->display);
   gdk_seat_ungrab (seat);
@@ -151,6 +153,17 @@ gdk_macos_surface_hide (GdkSurface *surface)
 
   g_clear_object (&self->buffer);
 
+  if (was_key)
+    {
+      /* Return key input to the parent window if necessary */
+      if (surface->parent != NULL && GDK_SURFACE_IS_MAPPED (surface->parent))
+        {
+          GdkMacosWindow *parentWindow = GDK_MACOS_SURFACE (surface->parent)->window;
+
+          [parentWindow showAndMakeKey:YES];
+        }
+    }
+
   if (was_mapped)
     gdk_surface_freeze_updates (GDK_SURFACE (self));
 }


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