From patchwork Tue Apr 8 09:26:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 337596 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 F3DC31400ED for ; Tue, 8 Apr 2014 19:27:41 +1000 (EST) Received: from localhost ([::1]:38989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXSJK-0006hm-Ug for incoming@patchwork.ozlabs.org; Tue, 08 Apr 2014 05:27:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXSIx-0006fU-Ni for qemu-devel@nongnu.org; Tue, 08 Apr 2014 05:27:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WXSIn-0002vR-Oz for qemu-devel@nongnu.org; Tue, 08 Apr 2014 05:26:55 -0400 Received: from cantor2.suse.de ([195.135.220.15]:46351 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WXSIn-0002vE-IP for qemu-devel@nongnu.org; Tue, 08 Apr 2014 05:26:45 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2A831AC18; Tue, 8 Apr 2014 09:26:45 +0000 (UTC) From: Takashi Iwai To: qemu-devel@nongnu.org Date: Tue, 8 Apr 2014 11:26:45 +0200 Message-Id: <1396949205-10046-1-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.135.220.15 Cc: "Michael S. Tsirkin" , Gerd Hoffmann , Anthony Liguori , Cole Robinson Subject: [Qemu-devel] [PATCH] gtk: Implement grab-on-click behavior in relative mode 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 This patch changes the behavior in the relative mode to be compatible with other UIs, namely, grabbing the input at the first left click. It improves the usability a lot; otherwise you have to press ctl-alt-G or select from menu at each time you want to move the pointer. Also, the input grab is cleared when the current mode is switched to the absolute mode. The automatic reset of the implicit grabbing is needed since the switching to the absolute mode happens always after the click even on Gtk. That is, we cannot check whether the absolute mode is already available at the first click time even though it should have been switched in X11 input driver side. Signed-off-by: Takashi Iwai --- I tested a version with the internal implicit grab flag, but this simpler behavior is less-confusing in the end (and of course the code is simpler), so I took this version. ui/gtk.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 6668bd8226d5..00fbbccb34b9 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -476,8 +476,15 @@ static void gd_change_runstate(void *opaque, int running, RunState state) static void gd_mouse_mode_change(Notifier *notify, void *data) { - gd_update_cursor(container_of(notify, GtkDisplayState, mouse_mode_notifier), - FALSE); + GtkDisplayState *s; + + s = container_of(notify, GtkDisplayState, mouse_mode_notifier); + /* release the grab at switching to absolute mode */ + if (qemu_input_is_absolute() && gd_is_grab_active(s)) { + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), + FALSE); + } + gd_update_cursor(s, FALSE); } /** GTK Events **/ @@ -685,6 +692,14 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button, GtkDisplayState *s = opaque; InputButton btn; + /* 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() && !gd_is_grab_active(s)) { + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item), + TRUE); + return TRUE; + } + if (button->button == 1) { btn = INPUT_BUTTON_LEFT; } else if (button->button == 2) {