]> Pileus Git - ~andy/gtk/commitdiff
Fix up keyboard grab handling
authorAlexander Larsson <alexl@redhat.com>
Thu, 4 Dec 2008 11:44:09 +0000 (12:44 +0100)
committerAlexander Larsson <alex@localhost.localdomain>
Thu, 2 Apr 2009 08:14:05 +0000 (10:14 +0200)
gdk/x11/gdkevents-x11.c
gdk/x11/gdkmain-x11.c

index b2a438c2811c79ddbbebb88ea7f31131cc29ba15..26e5de456b31b85efeb428b85cf5e5e9eddc96b9 100644 (file)
@@ -867,6 +867,24 @@ set_user_time (GdkWindow *window,
                                   gdk_event_get_time (event));
 }
 
+static gboolean
+is_parent_of (GdkWindow *parent,
+              GdkWindow *child)
+{
+  GdkWindow *w;
+
+  w = child;
+  while (w != NULL)
+    {
+      if (w == parent)
+       return TRUE;
+
+      w = gdk_window_get_parent (w);
+    }
+
+  return FALSE;
+}
+
 static gboolean
 gdk_event_translate (GdkDisplay *display,
                     GdkEvent   *event,
@@ -941,10 +959,20 @@ gdk_event_translate (GdkDisplay *display,
     
   if (window != NULL)
     {
-      /* Rewrite keyboard grabs to offscreen windows */
-      if ((xevent->type == KeyPress || xevent->type == KeyRelease) &&
-          window_private == display_x11->keyboard_xgrab_native_window)
+      /* Apply keyboard grabs to non-native windows */
+      if (/* Is key event */
+         (xevent->type == KeyPress || xevent->type == KeyRelease) &&
+         /* And we have a grab */
+         display_x11->keyboard_xgrab_window != NULL &&
+         (
+          /* The window is not a descendant of the grabbed window */
+          !is_parent_of (display_x11->keyboard_xgrab_window, window) ||
+          /* Or owner event is false */
+          !display_x11->keyboard_xgrab_owner_events
+          )
+         )
         {
+         /* Report key event against grab window */
           window_private = display_x11->keyboard_xgrab_window;
           window = (GdkWindow *) window_private;
         }
index 2ab67c74a48fd59ea3b27ecc30c621766cc765ef..89a9c75f552521101d4fc7cd91e706ed6f77cdc0 100644 (file)
@@ -206,6 +206,10 @@ gdk_pointer_grab (GdkWindow *        window,
 
   native = gdk_window_get_toplevel (window);
 
+  /* TODO: What do we do for offscreens and  children? We need to proxy the grab somehow */
+  if (!GDK_IS_WINDOW_IMPL_X11 (GDK_WINDOW_OBJECT (native)->impl))
+    return GDK_GRAB_SUCCESS;
+  
   if (confine_to)
     confine_to = _gdk_window_get_impl_window (confine_to);
 
@@ -310,13 +314,15 @@ gdk_keyboard_grab (GdkWindow *       window,
   GdkDisplayX11 *display_x11;
   GdkWindow *native;
 
-  if (1) return 0; /* TODO: fix */
-  
   g_return_val_if_fail (window != NULL, 0);
   g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
 
-  native = _gdk_window_get_impl_window (window);
+  native = gdk_window_get_toplevel (window);
 
+  /* TODO: What do we do for offscreens and  children? We need to proxy the grab somehow */
+  if (!GDK_IS_WINDOW_IMPL_X11 (GDK_WINDOW_OBJECT (native)->impl))
+    return GDK_GRAB_SUCCESS;
+  
   display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (native));
 
   serial = NextRequest (GDK_WINDOW_XDISPLAY (native));