From patchwork Tue May 6 12:05:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 346152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3500214013F for ; Tue, 6 May 2014 22:12:29 +1000 (EST) Received: from localhost ([::1]:34762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WheEV-0007Kt-2Q for incoming@patchwork.ozlabs.org; Tue, 06 May 2014 08:12:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whe8X-000614-5h for qemu-devel@nongnu.org; Tue, 06 May 2014 08:06:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Whe8O-0001Xq-2b for qemu-devel@nongnu.org; Tue, 06 May 2014 08:06:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whe8N-0001XS-Pz for qemu-devel@nongnu.org; Tue, 06 May 2014 08:06:08 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s46C66QO006293 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 May 2014 08:06:06 -0400 Received: from nilsson.home.kraxel.org (ovpn-116-108.ams2.redhat.com [10.36.116.108]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s46C647E024259; Tue, 6 May 2014 08:06:05 -0400 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 0D87D80843; Tue, 6 May 2014 14:06:03 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 6 May 2014 14:05:50 +0200 Message-Id: <1399377958-20076-15-git-send-email-kraxel@redhat.com> In-Reply-To: <1399377958-20076-1-git-send-email-kraxel@redhat.com> References: <1399377958-20076-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann , Anthony Liguori Subject: [Qemu-devel] [PATCH 14/22] gtk: keep track of grab owner X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Gerd Hoffmann --- ui/gtk.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index b251976..02e4685 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -185,6 +185,8 @@ struct GtkDisplayState { int last_y; int grab_x_root; int grab_y_root; + VirtualConsole *kbd_owner; + VirtualConsole *ptr_owner; gboolean full_screen; @@ -1058,11 +1060,19 @@ static void gd_grab_keyboard(VirtualConsole *vc) FALSE, GDK_CURRENT_TIME); #endif + vc->s->kbd_owner = vc; trace_gd_grab(vc->label, "kbd", true); } -static void gd_ungrab_keyboard(VirtualConsole *vc) +static void gd_ungrab_keyboard(GtkDisplayState *s) { + VirtualConsole *vc = s->kbd_owner; + + if (vc == NULL) { + return; + } + s->kbd_owner = NULL; + #if GTK_CHECK_VERSION(3, 0, 0) GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area); GdkDeviceManager *mgr = gdk_display_get_device_manager(display); @@ -1127,11 +1137,19 @@ static void gd_grab_pointer(VirtualConsole *vc) gdk_display_get_pointer(display, NULL, &vc->s->grab_x_root, &vc->s->grab_y_root, NULL); #endif + vc->s->ptr_owner = vc; trace_gd_grab(vc->label, "ptr", true); } -static void gd_ungrab_pointer(VirtualConsole *vc) +static void gd_ungrab_pointer(GtkDisplayState *s) { + VirtualConsole *vc = s->ptr_owner; + + if (vc == NULL) { + return; + } + s->ptr_owner = NULL; + GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area); #if GTK_CHECK_VERSION(3, 0, 0) GdkDeviceManager *mgr = gdk_display_get_device_manager(display); @@ -1168,8 +1186,8 @@ static void gd_menu_grab_input(GtkMenuItem *item, void *opaque) gd_grab_keyboard(vc); gd_grab_pointer(vc); } else { - gd_ungrab_keyboard(vc); - gd_ungrab_pointer(vc); + gd_ungrab_keyboard(s); + gd_ungrab_pointer(s); } gd_update_caption(s); @@ -1227,7 +1245,7 @@ static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing, GtkDisplayState *s = vc->s; if (!gd_is_grab_active(s) && gd_grab_on_hover(s)) { - gd_ungrab_keyboard(vc); + gd_ungrab_keyboard(s); } return TRUE;