keybindings: Use meta_device_grab() for keyboard active grabs

This commit is contained in:
Carlos Garnacho 2011-06-21 18:27:39 +02:00
parent 61a7789c83
commit 2484e8cd64
4 changed files with 59 additions and 28 deletions

View File

@ -3628,12 +3628,16 @@ meta_display_begin_grab_op (MetaDisplay *display,
{ {
if (grab_window) if (grab_window)
grab_info->grab_have_keyboard = grab_info->grab_have_keyboard =
meta_window_grab_all_keys (grab_window, timestamp); meta_window_grab_all_keys (grab_window,
grab_info->grab_keyboard,
timestamp);
else else
grab_info->grab_have_keyboard = grab_info->grab_have_keyboard =
meta_screen_grab_all_keys (screen, timestamp); meta_screen_grab_all_keys (screen,
grab_info->grab_keyboard,
timestamp);
if (!grab_info->grab_have_keyboard) if (!grab_info->grab_have_keyboard)
{ {
meta_topic (META_DEBUG_WINDOW_OPS, meta_topic (META_DEBUG_WINDOW_OPS,
@ -3847,9 +3851,13 @@ meta_display_end_grab_op (MetaDisplay *display,
meta_topic (META_DEBUG_WINDOW_OPS, meta_topic (META_DEBUG_WINDOW_OPS,
"Ungrabbing all keys timestamp %u\n", timestamp); "Ungrabbing all keys timestamp %u\n", timestamp);
if (grab_info->grab_window) if (grab_info->grab_window)
meta_window_ungrab_all_keys (grab_info->grab_window, timestamp); meta_window_ungrab_all_keys (grab_info->grab_window,
grab_info->grab_keyboard,
timestamp);
else else
meta_screen_ungrab_all_keys (grab_info->grab_screen, timestamp); meta_screen_ungrab_all_keys (grab_info->grab_screen,
grab_info->grab_keyboard,
timestamp);
} }
#ifdef HAVE_XSYNC #ifdef HAVE_XSYNC

View File

@ -36,14 +36,18 @@ void meta_display_shutdown_keys (MetaDisplay *display);
void meta_screen_grab_keys (MetaScreen *screen); void meta_screen_grab_keys (MetaScreen *screen);
void meta_screen_ungrab_keys (MetaScreen *screen); void meta_screen_ungrab_keys (MetaScreen *screen);
gboolean meta_screen_grab_all_keys (MetaScreen *screen, gboolean meta_screen_grab_all_keys (MetaScreen *screen,
MetaDevice *device,
guint32 timestamp); guint32 timestamp);
void meta_screen_ungrab_all_keys (MetaScreen *screen, void meta_screen_ungrab_all_keys (MetaScreen *screen,
MetaDevice *device,
guint32 timestamp); guint32 timestamp);
void meta_window_grab_keys (MetaWindow *window); void meta_window_grab_keys (MetaWindow *window);
void meta_window_ungrab_keys (MetaWindow *window); void meta_window_ungrab_keys (MetaWindow *window);
gboolean meta_window_grab_all_keys (MetaWindow *window, gboolean meta_window_grab_all_keys (MetaWindow *window,
MetaDevice *device,
guint32 timestamp); guint32 timestamp);
void meta_window_ungrab_all_keys (MetaWindow *window, void meta_window_ungrab_all_keys (MetaWindow *window,
MetaDevice *device,
guint32 timestamp); guint32 timestamp);
gboolean meta_display_process_key_event (MetaDisplay *display, gboolean meta_display_process_key_event (MetaDisplay *display,
MetaWindow *window, MetaWindow *window,

View File

@ -926,6 +926,7 @@ meta_window_ungrab_keys (MetaWindow *window)
} }
} }
#if 0
#ifdef WITH_VERBOSE_MODE #ifdef WITH_VERBOSE_MODE
static const char* static const char*
grab_status_to_string (int status) grab_status_to_string (int status)
@ -947,31 +948,32 @@ grab_status_to_string (int status)
} }
} }
#endif /* WITH_VERBOSE_MODE */ #endif /* WITH_VERBOSE_MODE */
#endif /* 0 */
static gboolean static gboolean
grab_keyboard (MetaDisplay *display, grab_keyboard (MetaDisplay *display,
Window xwindow, Window xwindow,
MetaDevice *device,
guint32 timestamp) guint32 timestamp)
{ {
MetaGrabInfo *grab_info;
int result; int result;
int grab_status;
/* Grab the keyboard, so we get key releases and all key /* Grab the keyboard, so we get key releases and all key
* presses * presses
*/ */
meta_error_trap_push_with_return (display); meta_error_trap_push_with_return (display);
grab_info = meta_display_get_grab_info (display, device);
grab_status = XGrabKeyboard (display->xdisplay, if (!meta_device_grab (grab_info->grab_keyboard,
xwindow, True, xwindow,
GrabModeAsync, GrabModeAsync, KeyPressMask | KeyReleaseMask,
timestamp); META_CURSOR_DEFAULT,
TRUE, FALSE, timestamp))
if (grab_status != GrabSuccess)
{ {
meta_error_trap_pop_with_return (display); meta_error_trap_pop_with_return (display);
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"XGrabKeyboard() returned failure status %s time %u\n", "grabbing keyboard failed time %u\n",
grab_status_to_string (grab_status),
timestamp); timestamp);
return FALSE; return FALSE;
} }
@ -981,7 +983,7 @@ grab_keyboard (MetaDisplay *display,
if (result != Success) if (result != Success)
{ {
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"XGrabKeyboard() resulted in an error\n"); "grabbing keyboard resulted in an error\n");
return FALSE; return FALSE;
} }
} }
@ -992,19 +994,27 @@ grab_keyboard (MetaDisplay *display,
} }
static void static void
ungrab_keyboard (MetaDisplay *display, guint32 timestamp) ungrab_keyboard (MetaDisplay *display,
MetaDevice *device,
guint32 timestamp)
{ {
MetaGrabInfo *grab_info;
grab_info = meta_display_get_grab_info (display, device);
meta_error_trap_push (display); meta_error_trap_push (display);
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"Ungrabbing keyboard with timestamp %u\n", "Ungrabbing keyboard with timestamp %u\n",
timestamp); timestamp);
XUngrabKeyboard (display->xdisplay, timestamp); meta_device_ungrab (grab_info->grab_keyboard, timestamp);
meta_error_trap_pop (display); meta_error_trap_pop (display);
} }
gboolean gboolean
meta_screen_grab_all_keys (MetaScreen *screen, guint32 timestamp) meta_screen_grab_all_keys (MetaScreen *screen,
MetaDevice *device,
guint32 timestamp)
{ {
gboolean retval; gboolean retval;
@ -1016,7 +1026,7 @@ meta_screen_grab_all_keys (MetaScreen *screen, guint32 timestamp)
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"Grabbing all keys on RootWindow\n"); "Grabbing all keys on RootWindow\n");
retval = grab_keyboard (screen->display, screen->xroot, timestamp); retval = grab_keyboard (screen->display, screen->xroot, device, timestamp);
if (retval) if (retval)
{ {
screen->all_keys_grabbed = TRUE; screen->all_keys_grabbed = TRUE;
@ -1029,11 +1039,13 @@ meta_screen_grab_all_keys (MetaScreen *screen, guint32 timestamp)
} }
void void
meta_screen_ungrab_all_keys (MetaScreen *screen, guint32 timestamp) meta_screen_ungrab_all_keys (MetaScreen *screen,
MetaDevice *device,
guint32 timestamp)
{ {
if (screen->all_keys_grabbed) if (screen->all_keys_grabbed)
{ {
ungrab_keyboard (screen->display, timestamp); ungrab_keyboard (screen->display, device, timestamp);
screen->all_keys_grabbed = FALSE; screen->all_keys_grabbed = FALSE;
screen->keys_grabbed = FALSE; screen->keys_grabbed = FALSE;
@ -1046,6 +1058,7 @@ meta_screen_ungrab_all_keys (MetaScreen *screen, guint32 timestamp)
gboolean gboolean
meta_window_grab_all_keys (MetaWindow *window, meta_window_grab_all_keys (MetaWindow *window,
MetaDevice *device,
guint32 timestamp) guint32 timestamp)
{ {
Window grabwindow; Window grabwindow;
@ -1069,7 +1082,7 @@ meta_window_grab_all_keys (MetaWindow *window,
meta_topic (META_DEBUG_KEYBINDINGS, meta_topic (META_DEBUG_KEYBINDINGS,
"Grabbing all keys on window %s\n", window->desc); "Grabbing all keys on window %s\n", window->desc);
retval = grab_keyboard (window->display, grabwindow, timestamp); retval = grab_keyboard (window->display, grabwindow, device, timestamp);
if (retval) if (retval)
{ {
window->keys_grabbed = FALSE; window->keys_grabbed = FALSE;
@ -1081,11 +1094,13 @@ meta_window_grab_all_keys (MetaWindow *window,
} }
void void
meta_window_ungrab_all_keys (MetaWindow *window, guint32 timestamp) meta_window_ungrab_all_keys (MetaWindow *window,
MetaDevice *device,
guint32 timestamp)
{ {
if (window->all_keys_grabbed) if (window->all_keys_grabbed)
{ {
ungrab_keyboard (window->display, timestamp); ungrab_keyboard (window->display, device, timestamp);
window->grab_on_frame = FALSE; window->grab_on_frame = FALSE;
window->all_keys_grabbed = FALSE; window->all_keys_grabbed = FALSE;

View File

@ -67,6 +67,10 @@ void meta_keybindings_switch_window (MetaDisplay *display,
MetaKeyBinding *binding); MetaKeyBinding *binding);
void meta_screen_ungrab_all_keys (MetaScreen *screen, guint32 timestamp); void meta_screen_ungrab_all_keys (MetaScreen *screen,
gboolean meta_screen_grab_all_keys (MetaScreen *screen, guint32 timestamp); MetaDevice *device,
guint32 timestamp);
gboolean meta_screen_grab_all_keys (MetaScreen *screen,
MetaDevice *device,
guint32 timestamp);
#endif #endif