From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JWsaB-0002D3-3n for qemu-devel@nongnu.org; Wed, 05 Mar 2008 07:18:51 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JWsa7-0002Cg-9m for qemu-devel@nongnu.org; Wed, 05 Mar 2008 07:18:49 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JWsa7-0002Cd-7B for qemu-devel@nongnu.org; Wed, 05 Mar 2008 07:18:47 -0500 Received: from smtp02.citrix.com ([66.165.176.63]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JWsa6-0000DR-QM for qemu-devel@nongnu.org; Wed, 05 Mar 2008 07:18:47 -0500 Received: from implementation.famille.thibault.fr (dhcp-16-192.uk.xensource.com [172.31.16.192]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id m25CI3j0008635 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 5 Mar 2008 04:18:05 -0800 Received: from samy by implementation.famille.thibault.fr with local (Exim 4.69) (envelope-from ) id 1JWsZO-0003s7-JH for qemu-devel@nongnu.org; Wed, 05 Mar 2008 13:18:02 +0100 Date: Wed, 5 Mar 2008 12:18:02 +0000 From: Samuel Thibault Message-ID: <20080305121802.GD9747@implementation.uk.xensource.com> References: <20080305114704.GC9747@implementation.uk.xensource.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080305114704.GC9747@implementation.uk.xensource.com> Subject: [Qemu-devel] [PATCH] fix SDL mouse events processing Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hello, The patch below fixes SDL mouse events processing: - GetRelativeMouseState always returns the last position, so when the polling loop gets several mouse events in one go, we would send useless 'no move' events. - So as to make sure we don't miss any mouse click / double click, we should not use GetRelativeMouseState() to get the button state, but rather keep records of the button state ourselves (I've requested SDL developers to provide it directly in the event in SDL 1.3). Index: sdl.c =================================================================== RCS file: /sources/qemu/qemu/sdl.c,v retrieving revision 1.45 diff -u -p -r1.45 sdl.c --- sdl.c 17 Nov 2007 17:14:38 -0000 1.45 +++ sdl.c 5 Mar 2008 11:53:55 -0000 @@ -290,10 +290,9 @@ static void sdl_grab_end(void) sdl_update_caption(); } -static void sdl_send_mouse_event(int dz) +static void sdl_send_mouse_event(int dx, int dy, int dz, int state) { - int dx, dy, state, buttons; - state = SDL_GetRelativeMouseState(&dx, &dy); + int buttons; buttons = 0; if (state & SDL_BUTTON(SDL_BUTTON_LEFT)) buttons |= MOUSE_EVENT_LBUTTON; @@ -347,6 +346,7 @@ static void sdl_refresh(DisplayState *ds { SDL_Event ev1, *ev = &ev1; int mod_state; + int state; if (last_vm_running != vm_running) { last_vm_running = vm_running; @@ -355,6 +355,7 @@ static void sdl_refresh(DisplayState *ds vga_hw_update(); + state = SDL_GetMouseState(NULL, NULL); while (SDL_PollEvent(ev)) { switch (ev->type) { case SDL_VIDEOEXPOSE: @@ -474,16 +475,23 @@ static void sdl_refresh(DisplayState *ds case SDL_MOUSEMOTION: if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) { - sdl_send_mouse_event(0); + int dx, dy; + SDL_GetRelativeMouseState(&dx, &dy); + if (dx || dy) + sdl_send_mouse_event(dx, dy, 0, state); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { SDL_MouseButtonEvent *bev = &ev->button; + if (ev->type == SDL_MOUSEBUTTONDOWN) + state |= SDL_BUTTON(bev->button); + else + state &= ~SDL_BUTTON(ev->button.button); if (!gui_grab && !kbd_mouse_is_absolute()) { if (ev->type == SDL_MOUSEBUTTONDOWN && - (bev->state & SDL_BUTTON_LMASK)) { + (bev->button == SDL_BUTTON_LEFT)) { /* start grabbing all events */ sdl_grab_start(); } @@ -497,7 +505,7 @@ static void sdl_refresh(DisplayState *ds dz = 1; } #endif - sdl_send_mouse_event(dz); + sdl_send_mouse_event(0, 0, dz, state); } } break;