From a6cb7cc7cbfdebe34678337e5b448bdda77690fa Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sat, 20 Apr 2013 18:55:02 +0300 Subject: [PATCH] On menu popup only check keyboard or mouse, not both (Bug 9914) Reduce the delay on popping up menus by only grabbing the input method used to create it, i.e. grab the mouse for right-click menus and keyboard when xfdesktop --menu is invoked by keyboard shortcut. --- common/xfdesktop-common.c | 20 +++++++++++++++----- common/xfdesktop-common.h | 2 +- src/xfce-desktop.c | 3 ++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common/xfdesktop-common.c b/common/xfdesktop-common.c index 344611a..14e3315 100644 --- a/common/xfdesktop-common.c +++ b/common/xfdesktop-common.c @@ -249,7 +249,7 @@ xfdesktop_send_client_message(Window xid, const gchar *msg) * sometimes doesn't. Credit for this one goes to Olivier. */ gboolean -xfdesktop_popup_grab_available (GdkWindow *win, guint32 timestamp) +xfdesktop_popup_grab_available (GdkWindow *win, guint32 timestamp, gboolean mouse_pressed) { GdkEventMask mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | @@ -262,8 +262,18 @@ xfdesktop_popup_grab_available (GdkWindow *win, guint32 timestamp) TRACE ("entering grab_available"); - g1 = gdk_pointer_grab (win, TRUE, mask, NULL, NULL, timestamp); - g2 = gdk_keyboard_grab (win, TRUE, timestamp); + /* since either the mouse or the keyboard invoked the grab, we can + * speed things up by only checking the input method that caused it. + * We'll set the other event to TRUE so it won't be looked at */ + if(mouse_pressed) { + DBG("grabbing only the mouse"); + g1 = gdk_pointer_grab (win, TRUE, mask, NULL, NULL, timestamp); + g2 = GDK_GRAB_SUCCESS; + } else { + DBG("grabbing only the keyboard"); + g1 = GDK_GRAB_SUCCESS; + g2 = gdk_keyboard_grab (win, TRUE, timestamp); + } while ((i++ < 2500) && (grab_failed = ((g1 != GDK_GRAB_SUCCESS) || (g2 != GDK_GRAB_SUCCESS)))) @@ -283,11 +293,11 @@ xfdesktop_popup_grab_available (GdkWindow *win, guint32 timestamp) } } - if (g1 == GDK_GRAB_SUCCESS) + if (g1 == GDK_GRAB_SUCCESS && mouse_pressed) { gdk_pointer_ungrab (timestamp); } - if (g2 == GDK_GRAB_SUCCESS) + if (g2 == GDK_GRAB_SUCCESS && !mouse_pressed) { gdk_keyboard_ungrab (timestamp); } diff --git a/common/xfdesktop-common.h b/common/xfdesktop-common.h index 7c7570d..b186b93 100644 --- a/common/xfdesktop-common.h +++ b/common/xfdesktop-common.h @@ -79,7 +79,7 @@ gboolean xfdesktop_image_file_is_valid(const gchar *filename); gboolean xfdesktop_check_is_running(Window *xid); void xfdesktop_send_client_message(Window xid, const gchar *msg); -gboolean xfdesktop_popup_grab_available(GdkWindow *win, guint32 timestamp); +gboolean xfdesktop_popup_grab_available(GdkWindow *win, guint32 timestamp, gboolean mouse_pressed); G_END_DECLS diff --git a/src/xfce-desktop.c b/src/xfce-desktop.c index 95c30f6..6cf9029 100644 --- a/src/xfce-desktop.c +++ b/src/xfce-desktop.c @@ -1344,7 +1344,8 @@ xfce_desktop_do_menu_popup(XfceDesktop *desktop, screen = gdk_display_get_default_screen(gdk_display_get_default()); if(xfdesktop_popup_grab_available(gdk_screen_get_root_window(screen), - activate_time)) + activate_time, + (button > 0 ? TRUE : FALSE))) { menu = gtk_menu_new(); gtk_menu_set_screen(GTK_MENU(menu), screen); -- 1.7.10.4