From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FEuXv-0002W2-Oe for qemu-devel@nongnu.org; Thu, 02 Mar 2006 15:37:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FEuXu-0002V0-7R for qemu-devel@nongnu.org; Thu, 02 Mar 2006 15:37:10 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FEi5r-00046I-6K for qemu-devel@nongnu.org; Thu, 02 Mar 2006 02:19:23 -0500 Received: from [70.116.13.229] (helo=localhost.localdomain) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FEWBR-0001J1-Bu for qemu-devel@nongnu.org; Wed, 01 Mar 2006 13:36:21 -0500 Received: from [192.168.1.101] (helo=[192.168.1.101]) by localhost.localdomain with esmtp (Exim 4.52) id 1FEW86-0002se-MW for qemu-devel@nongnu.org; Wed, 01 Mar 2006 12:32:55 -0600 Message-ID: <4405E92B.5020009@codemonkey.ws> Date: Wed, 01 Mar 2006 12:34:19 -0600 From: Anthony Liguori MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080605030002070101090701" Subject: [Qemu-devel] [PATCH] Work around bug in SDL_ShowCursor(0) in libsdl-1.2.9 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 This is a multi-part message in MIME format. --------------080605030002070101090701 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, There appears to bug a bug in the latest version of SDL (1.2.9) that causes the position of the cursor to be wrongly reported after calling SDL_ShowCursor(0). When the cursor is disabled, relative and absolute mouse events are reported as garbage. This patch works around this by using a invisible cursor instead of disabling the cursor. This has the same functionality of disabling the cursor but avoids these problems. For what it's worth, disabling the cursor in older versions of SDL also has strange side effects. For instance, the cursor gets warped when you hit the edge of the bounding box. If you're using an absolute input device (emulating a Wacom or Synaptics touchpad for instance), this results in weird mouse behavior (when you exit this window, your mouse ends up in the middle of the window!). Avoiding SDL_ShowCursor(0) is probably a good idea regardless of this particular bug. Regards, Anthony Liguori --------------080605030002070101090701 Content-Type: text/plain; name="qemu-sdl-show-cursor.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-sdl-show-cursor.diff" diff -r 7d667b53ca2c sdl.c --- a/sdl.c Wed Mar 1 12:44:52 2006 -0500 +++ b/sdl.c Wed Mar 1 13:17:26 2006 -0500 @@ -39,6 +39,8 @@ static int gui_fullscreen_initial_grab; static int gui_grab_code = KMOD_LALT | KMOD_LCTRL; static uint8_t modifiers_state[256]; +static SDL_Cursor *sdl_cursor_normal; +static SDL_Cursor *sdl_cursor_hidden; static void sdl_update(DisplayState *ds, int x, int y, int w, int h) { @@ -273,7 +275,8 @@ static void sdl_grab_start(void) { - SDL_ShowCursor(0); + sdl_cursor_normal = SDL_GetCursor(); + SDL_SetCursor(sdl_cursor_hidden); SDL_WM_GrabInput(SDL_GRAB_ON); /* dummy read to avoid moving the mouse */ SDL_GetRelativeMouseState(NULL, NULL); @@ -284,7 +287,7 @@ static void sdl_grab_end(void) { SDL_WM_GrabInput(SDL_GRAB_OFF); - SDL_ShowCursor(1); + SDL_SetCursor(sdl_cursor_normal); gui_grab = 0; sdl_update_caption(); } @@ -475,6 +478,7 @@ void sdl_display_init(DisplayState *ds, int full_screen) { int flags; + uint8_t data = 0; #if defined(__APPLE__) /* always use generic keymaps */ @@ -508,6 +512,12 @@ SDL_EnableUNICODE(1); gui_grab = 0; + /* work around a bug in libsdl that causes mouse position to be reported + relative to the upper left corner of the screen instead of the window + after SDL_ShowCursor(0) by using a custom invisible cursor. + */ + sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0); + atexit(sdl_cleanup); if (full_screen) { gui_fullscreen = 1; --------------080605030002070101090701--