[gtk+/xi2: 512/1239] Implement keyboard grabs on offscreen windows on top of XI2.



commit a45c1c08751e16a3a8feb884279747fe0f883efb
Author: Carlos Garnacho <carlos lanedo com>
Date:   Fri Jul 10 19:52:34 2009 +0100

    Implement keyboard grabs on offscreen windows on top of XI2.

 gdk/x11/gdkdevicemanager-xi2.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 1e25120..324f376 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -42,6 +42,8 @@ static gboolean gdk_device_manager_xi2_translate_event (GdkEventTranslator *tran
                                                         GdkDisplay         *display,
                                                         GdkEvent           *event,
                                                         XEvent             *xevent);
+static Window   gdk_device_manager_xi2_get_event_window (GdkEventTranslator *translator,
+                                                         XEvent             *xevent);
 
 
 G_DEFINE_TYPE_WITH_CODE (GdkDeviceManagerXI2, gdk_device_manager_xi2, GDK_TYPE_DEVICE_MANAGER,
@@ -920,3 +922,41 @@ gdk_device_manager_xi2_translate_event (GdkEventTranslator *translator,
 
   return return_val;
 }
+
+static Window
+gdk_device_manager_xi2_get_event_window (GdkEventTranslator *translator,
+                                         XEvent             *xevent)
+{
+  GdkDisplay *display;
+  XIEvent *ev;
+
+  ev = (XIEvent *) xevent;
+
+  if (ev->type != GenericEvent || ev->extension != device_manager->opcode)
+    return None;
+
+  display = gdk_device_manager_get_display (GDK_DEVICE_MANAGER (translator));
+
+  /* Apply keyboard grabs to non-native windows */
+  if (/* Is key event */
+      (ev->evtype == XI_KeyPress || ev->evtype == XI_KeyRelease) &&
+      /* And we have a grab */
+      display->keyboard_grab.window != NULL)
+    {
+      GdkWindow *window;
+      XIDeviceEvent *xev = (XIDeviceEvent *) ev;
+
+      window = gdk_window_lookup_for_display (display, xev->event);
+
+      if (/* The window is not a descendant of the grabbed window */
+          !is_parent_of ((GdkWindow *)display->keyboard_grab.window, window) ||
+          /* Or owner event is false */
+          !display->keyboard_grab.owner_events)
+        {
+          /* Report key event against grab window */
+          return GDK_WINDOW_XID (display->keyboard_grab.window);
+        }
+    }
+
+  return None;
+}



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