[mutter/wip/is-switch-fixes: 2/4] keybindings: Add API to freeze/unfreeze the keyboard



commit bda4af550429fdbc5da3c048405d1f6b309587c1
Author: Rui Matos <tiagomatos gmail com>
Date:   Fri Mar 29 02:38:43 2013 +0100

    keybindings: Add API to freeze/unfreeze the keyboard
    
    We'll use this in gnome-shell to freeze the keyboard right before
    switching input source and unfreeze it after that's finished so that
    we don't lose any key events to the wrong input source.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697001

 src/core/keybindings.c |   47 +++++++++++++++++++++++++++++++++++++++++++----
 src/meta/display.h     |    8 ++++++++
 2 files changed, 51 insertions(+), 4 deletions(-)
---
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index fc9a31a..78b22a7 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -1248,7 +1248,8 @@ grab_status_to_string (int status)
 static gboolean
 grab_keyboard (MetaDisplay *display,
                Window       xwindow,
-               guint32      timestamp)
+               guint32      timestamp,
+               int          grab_mode)
 {
   int result;
   int grab_status;
@@ -1269,7 +1270,7 @@ grab_keyboard (MetaDisplay *display,
                               xwindow,
                               timestamp,
                               None,
-                              XIGrabModeAsync, XIGrabModeAsync,
+                              grab_mode, grab_mode,
                               True, /* owner_events */
                               &mask);
 
@@ -1323,7 +1324,7 @@ meta_screen_grab_all_keys (MetaScreen *screen, guint32 timestamp)
 
   meta_topic (META_DEBUG_KEYBINDINGS,
               "Grabbing all keys on RootWindow\n");
-  retval = grab_keyboard (screen->display, screen->xroot, timestamp);
+  retval = grab_keyboard (screen->display, screen->xroot, timestamp, XIGrabModeAsync);
   if (retval)
     {
       screen->all_keys_grabbed = TRUE;
@@ -1376,7 +1377,7 @@ meta_window_grab_all_keys (MetaWindow  *window,
 
   meta_topic (META_DEBUG_KEYBINDINGS,
               "Grabbing all keys on window %s\n", window->desc);
-  retval = grab_keyboard (window->display, grabwindow, timestamp);
+  retval = grab_keyboard (window->display, grabwindow, timestamp, XIGrabModeAsync);
   if (retval)
     {
       window->keys_grabbed = FALSE;
@@ -1403,6 +1404,44 @@ meta_window_ungrab_all_keys (MetaWindow *window, guint32 timestamp)
     }
 }
 
+void
+meta_display_grab_keyboard (MetaDisplay *display, guint32 timestamp)
+{
+  grab_keyboard (display, DefaultRootWindow (display->xdisplay), timestamp, XIGrabModeSync);
+}
+
+void
+meta_display_ungrab_keyboard (MetaDisplay *display, guint32 timestamp)
+{
+  ungrab_keyboard (display, timestamp);
+}
+
+void
+meta_display_freeze_keyboard (MetaDisplay *display, guint32 timestamp)
+{
+  meta_error_trap_push (display);
+
+  meta_topic (META_DEBUG_KEYBINDINGS,
+              "Freezing keyboard with timestamp %u\n",
+              timestamp);
+  XIAllowEvents (display->xdisplay, META_VIRTUAL_CORE_KEYBOARD_ID,
+                 XISyncDevice, timestamp);
+  meta_error_trap_pop (display);
+}
+
+void
+meta_display_unfreeze_keyboard (MetaDisplay *display, guint32 timestamp)
+{
+  meta_error_trap_push (display);
+
+  meta_topic (META_DEBUG_KEYBINDINGS,
+              "Unfreezing keyboard with timestamp %u\n",
+              timestamp);
+  XIAllowEvents (display->xdisplay, META_VIRTUAL_CORE_KEYBOARD_ID,
+                 XIAsyncDevice, timestamp);
+  meta_error_trap_pop (display);
+}
+
 static gboolean
 is_modifier (MetaDisplay *display,
              unsigned int keycode)
diff --git a/src/meta/display.h b/src/meta/display.h
index d4c3aae..82bb61b 100644
--- a/src/meta/display.h
+++ b/src/meta/display.h
@@ -187,4 +187,12 @@ void meta_display_unmanage_screen (MetaDisplay *display,
 
 void meta_display_clear_mouse_mode (MetaDisplay *display);
 
+void meta_display_grab_keyboard (MetaDisplay *display,
+                                 guint32      timestamp);
+void meta_display_ungrab_keyboard (MetaDisplay *display,
+                                   guint32      timestamp);
+void meta_display_freeze_keyboard (MetaDisplay *display,
+                                   guint32      timestamp);
+void meta_display_unfreeze_keyboard (MetaDisplay *display,
+                                     guint32      timestamp);
 #endif


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