From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZbgj-0000id-CZ for qemu-devel@nongnu.org; Wed, 09 Sep 2015 05:29:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZbgf-0005qQ-BM for qemu-devel@nongnu.org; Wed, 09 Sep 2015 05:29:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZbgf-0005qH-7E for qemu-devel@nongnu.org; Wed, 09 Sep 2015 05:29:05 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id E07542E837E for ; Wed, 9 Sep 2015 09:29:04 +0000 (UTC) From: Gerd Hoffmann Date: Wed, 9 Sep 2015 11:28:53 +0200 Message-Id: <1441790938-29042-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1441790938-29042-1-git-send-email-kraxel@redhat.com> References: <1441790938-29042-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 1/6] gtk: check for existing grabs in gd_grab_{pointer, keyboard} List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann If a grab is already active for our window, do nothing. If a grab is already active for another window, release it. Cleanup some checks and ungrab calls in the code which are not needed any more. Signed-off-by: Gerd Hoffmann --- ui/gtk.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index df2a79e..24a1edb 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -167,6 +167,8 @@ struct GtkDisplayState { static void gd_grab_pointer(VirtualConsole *vc); static void gd_ungrab_pointer(GtkDisplayState *s); +static void gd_grab_keyboard(VirtualConsole *vc); +static void gd_ungrab_keyboard(GtkDisplayState *s); /** Utility Functions **/ @@ -849,7 +851,6 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button, /* implicitly grab the input at the first click in the relative mode */ if (button->button == 1 && button->type == GDK_BUTTON_PRESS && !qemu_input_is_absolute() && s->ptr_owner != vc) { - gd_ungrab_pointer(s); if (!vc->window) { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), TRUE); @@ -1259,6 +1260,14 @@ static void gd_grab_devices(VirtualConsole *vc, bool grab, static void gd_grab_keyboard(VirtualConsole *vc) { + if (vc->s->kbd_owner) { + if (vc->s->kbd_owner == vc) { + return; + } else { + gd_ungrab_keyboard(vc->s); + } + } + #if GTK_CHECK_VERSION(3, 0, 0) gd_grab_devices(vc, true, GDK_SOURCE_KEYBOARD, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, @@ -1292,6 +1301,15 @@ static void gd_ungrab_keyboard(GtkDisplayState *s) static void gd_grab_pointer(VirtualConsole *vc) { GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area); + + if (vc->s->ptr_owner) { + if (vc->s->ptr_owner == vc) { + return; + } else { + gd_ungrab_pointer(vc->s); + } + } + #if GTK_CHECK_VERSION(3, 0, 0) GdkDeviceManager *mgr = gdk_display_get_device_manager(display); gd_grab_devices(vc, true, GDK_SOURCE_MOUSE, @@ -1352,9 +1370,7 @@ static void gd_menu_grab_input(GtkMenuItem *item, void *opaque) VirtualConsole *vc = gd_vc_find_current(s); if (gd_is_grab_active(s)) { - if (!gd_grab_on_hover(s)) { - gd_grab_keyboard(vc); - } + gd_grab_keyboard(vc); gd_grab_pointer(vc); } else { gd_ungrab_keyboard(s); @@ -1415,7 +1431,6 @@ static gboolean gd_enter_event(GtkWidget *widget, GdkEventCrossing *crossing, GtkDisplayState *s = vc->s; if (gd_grab_on_hover(s)) { - gd_ungrab_keyboard(s); gd_grab_keyboard(vc); gd_update_caption(s); } -- 1.8.3.1