From patchwork Mon Mar 15 20:34:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 47781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8D952B7D62 for ; Tue, 16 Mar 2010 07:45:41 +1100 (EST) Received: from localhost ([127.0.0.1]:42696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrH8M-0007De-6k for incoming@patchwork.ozlabs.org; Mon, 15 Mar 2010 16:43:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrGzy-00051o-1v for qemu-devel@nongnu.org; Mon, 15 Mar 2010 16:34:50 -0400 Received: from [199.232.76.173] (port=53570 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrGzx-00051g-Nq for qemu-devel@nongnu.org; Mon, 15 Mar 2010 16:34:49 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrGzw-00006H-Rw for qemu-devel@nongnu.org; Mon, 15 Mar 2010 16:34:49 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:45729) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NrGzw-00006B-GT for qemu-devel@nongnu.org; Mon, 15 Mar 2010 16:34:48 -0400 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e37.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o2FKXHek014411 for ; Mon, 15 Mar 2010 14:33:17 -0600 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2FKYhKZ085472 for ; Mon, 15 Mar 2010 14:34:44 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2FKYgMj025815 for ; Mon, 15 Mar 2010 14:34:43 -0600 Received: from localhost.localdomain (sig-9-65-105-148.mts.ibm.com [9.65.105.148]) by d03av01.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2FKYTdw024992; Mon, 15 Mar 2010 14:34:41 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 15 Mar 2010 15:34:28 -0500 Message-Id: <1268685268-16881-7-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1268685268-16881-1-git-send-email-aliguori@us.ibm.com> References: <1268685268-16881-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Avi Kivity , Anthony Liguori , Gerd Hoffman , Luiz Capitulino Subject: [Qemu-devel] [PATCH 7/7] sdl: use mouse mode notifier X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Today we poll the mouse mode whenever there is a mouse movement. There is a subtle usability problem with this though. If we're in relative mode and grab is enabled, when we change to absolute mode, we break grab. This gives a user a seamless transition when the new pointer is enabled. But because we poll for mouse change, this grab break won't occur until the user attempts to move the mouse. By using notifiers, the grab break happens as soon as possible. Signed-off-by: Anthony Liguori --- sdl.c | 31 ++++++++++++++++++++----------- 1 files changed, 20 insertions(+), 11 deletions(-) diff --git a/sdl.c b/sdl.c index 1d1e100..e9edbcc 100644 --- a/sdl.c +++ b/sdl.c @@ -57,6 +57,7 @@ static SDL_Cursor *guest_sprite = NULL; static uint8_t allocator; static SDL_PixelFormat host_format; static int scaling_active = 0; +static Notifier mouse_mode_notifier; static void sdl_update(DisplayState *ds, int x, int y, int w, int h) { @@ -485,6 +486,22 @@ static void sdl_grab_end(void) sdl_update_caption(); } +static void sdl_mouse_mode_change(Notifier *notify) +{ + if (kbd_mouse_is_absolute()) { + if (!absolute_enabled) { + sdl_hide_cursor(); + if (gui_grab) { + sdl_grab_end(); + } + absolute_enabled = 1; + } + } else if (absolute_enabled) { + sdl_show_cursor(); + absolute_enabled = 0; + } +} + static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state) { int buttons; @@ -497,19 +514,8 @@ static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state buttons |= MOUSE_EVENT_MBUTTON; if (kbd_mouse_is_absolute()) { - if (!absolute_enabled) { - sdl_hide_cursor(); - if (gui_grab) { - sdl_grab_end(); - } - absolute_enabled = 1; - } - dx = x * 0x7FFF / (width - 1); dy = y * 0x7FFF / (height - 1); - } else if (absolute_enabled) { - sdl_show_cursor(); - absolute_enabled = 0; } else if (guest_cursor) { x -= guest_x; y -= guest_y; @@ -875,6 +881,9 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) dpy_resize(ds); } + mouse_mode_notifier.notify = sdl_mouse_mode_change; + qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier); + sdl_update_caption(); SDL_EnableKeyRepeat(250, 50); gui_grab = 0;