From 555d7dc90c12af635a38f0f9f2fa26bd90a545bb Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 9 Sep 2006 20:19:56 +0000 Subject: [PATCH] Avoid a stuck grab, preventing focus from being transferred between 2006-09-09 Elijah Newren Avoid a stuck grab, preventing focus from being transferred between windows. Thanks to Fryderyk Dziarmagowski for steps to reproduce. Fixes at least part of #354422. * src/display.c (meta_display_begin_grab_op, meta_display_end_grab_op): pass timestamp to meta_screen_ungrab_all_keys, meta_screen_ungrab_all_keys, and meta_window_ungrab_all_keys * src/keybindings.[ch] (grab_keyboard, ungrab_keyboard): add a timestamp parameter and remove call to meta_display_get_current_time(), (meta_screen_grab_all_keys, meta_screen_ungrab_all_keys, meta_window_ungrab_all_keys): add a timestamp parameter and pass it on to grab_keyboard and ungrab_keyboard --- ChangeLog | 18 ++++++++++++++++++ src/display.c | 6 +++--- src/keybindings.c | 25 ++++++++++--------------- src/keybindings.h | 9 ++++++--- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 143d32e82..b66079ed5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2006-09-09 Elijah Newren + + Avoid a stuck grab, preventing focus from being transferred + between windows. Thanks to Fryderyk Dziarmagowski for steps to + reproduce. Fixes at least part of #354422. + + * src/display.c (meta_display_begin_grab_op, + meta_display_end_grab_op): pass timestamp to + meta_screen_ungrab_all_keys, meta_screen_ungrab_all_keys, and + meta_window_ungrab_all_keys + + * src/keybindings.[ch] (grab_keyboard, ungrab_keyboard): add a + timestamp parameter and remove call to + meta_display_get_current_time(), (meta_screen_grab_all_keys, + meta_screen_ungrab_all_keys, meta_window_ungrab_all_keys): add a + timestamp parameter and pass it on to grab_keyboard and + ungrab_keyboard + 2006-09-07 Elijah Newren * src/constraints.c (update_onscreen_requirements): make sure diff --git a/src/display.c b/src/display.c index 5e64eb2f2..7a93c3be4 100644 --- a/src/display.c +++ b/src/display.c @@ -3323,7 +3323,7 @@ meta_display_begin_grab_op (MetaDisplay *display, else display->grab_have_keyboard = - meta_screen_grab_all_keys (screen); + meta_screen_grab_all_keys (screen, timestamp); if (!display->grab_have_keyboard) { @@ -3618,9 +3618,9 @@ meta_display_end_grab_op (MetaDisplay *display, meta_topic (META_DEBUG_WINDOW_OPS, "Ungrabbing all keys timestamp %lu\n", timestamp); if (display->grab_window) - meta_window_ungrab_all_keys (display->grab_window); + meta_window_ungrab_all_keys (display->grab_window, timestamp); else - meta_screen_ungrab_all_keys (display->grab_screen); + meta_screen_ungrab_all_keys (display->grab_screen, timestamp); } #ifdef HAVE_XSYNC diff --git a/src/keybindings.c b/src/keybindings.c index d749c420e..6b9aa0584 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -1208,18 +1208,17 @@ grab_status_to_string (int status) static gboolean grab_keyboard (MetaDisplay *display, - Window xwindow) + Window xwindow, + Time timestamp) { int result; int grab_status; - Time timestamp; /* Grab the keyboard, so we get key releases and all key * presses */ meta_error_trap_push_with_return (display); - timestamp = meta_display_get_current_time (display); grab_status = XGrabKeyboard (display->xdisplay, xwindow, True, GrabModeAsync, GrabModeAsync, @@ -1251,12 +1250,8 @@ grab_keyboard (MetaDisplay *display, } static void -ungrab_keyboard (MetaDisplay *display) +ungrab_keyboard (MetaDisplay *display, Time timestamp) { - Time timestamp; - - timestamp = meta_display_get_current_time (display); - meta_error_trap_push (display); meta_topic (META_DEBUG_KEYBINDINGS, @@ -1267,7 +1262,7 @@ ungrab_keyboard (MetaDisplay *display) } gboolean -meta_screen_grab_all_keys (MetaScreen *screen) +meta_screen_grab_all_keys (MetaScreen *screen, Time timestamp) { gboolean retval; @@ -1279,7 +1274,7 @@ meta_screen_grab_all_keys (MetaScreen *screen) meta_topic (META_DEBUG_KEYBINDINGS, "Grabbing all keys on RootWindow\n"); - retval = grab_keyboard (screen->display, screen->xroot); + retval = grab_keyboard (screen->display, screen->xroot, timestamp); if (retval) screen->all_keys_grabbed = TRUE; else @@ -1289,11 +1284,11 @@ meta_screen_grab_all_keys (MetaScreen *screen) } void -meta_screen_ungrab_all_keys (MetaScreen *screen) +meta_screen_ungrab_all_keys (MetaScreen *screen, Time timestamp) { if (screen->all_keys_grabbed) { - ungrab_keyboard (screen->display); + ungrab_keyboard (screen->display, timestamp); screen->all_keys_grabbed = FALSE; screen->keys_grabbed = FALSE; @@ -1328,7 +1323,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); + retval = grab_keyboard (window->display, grabwindow, timestamp); if (retval) { window->keys_grabbed = FALSE; @@ -1340,11 +1335,11 @@ meta_window_grab_all_keys (MetaWindow *window, } void -meta_window_ungrab_all_keys (MetaWindow *window) +meta_window_ungrab_all_keys (MetaWindow *window, Time timestamp) { if (window->all_keys_grabbed) { - ungrab_keyboard (window->display); + ungrab_keyboard (window->display, timestamp); window->grab_on_frame = FALSE; window->all_keys_grabbed = FALSE; diff --git a/src/keybindings.h b/src/keybindings.h index dce9ea284..5962f8071 100644 --- a/src/keybindings.h +++ b/src/keybindings.h @@ -29,13 +29,16 @@ void meta_display_init_keys (MetaDisplay *display); void meta_display_shutdown_keys (MetaDisplay *display); void meta_screen_grab_keys (MetaScreen *screen); void meta_screen_ungrab_keys (MetaScreen *screen); -gboolean meta_screen_grab_all_keys (MetaScreen *screen); -void meta_screen_ungrab_all_keys (MetaScreen *screen); +gboolean meta_screen_grab_all_keys (MetaScreen *screen, + Time timestamp); +void meta_screen_ungrab_all_keys (MetaScreen *screen, + Time timestamp); void meta_window_grab_keys (MetaWindow *window); void meta_window_ungrab_keys (MetaWindow *window); gboolean meta_window_grab_all_keys (MetaWindow *window, Time timestamp); -void meta_window_ungrab_all_keys (MetaWindow *window); +void meta_window_ungrab_all_keys (MetaWindow *window, + Time timestamp); void meta_display_process_key_event (MetaDisplay *display, MetaWindow *window, XEvent *event);