qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Work around bug in SDL_ShowCursor(0) in libsdl-1.2.9
Date: Wed, 01 Mar 2006 12:34:19 -0600	[thread overview]
Message-ID: <4405E92B.5020009@codemonkey.ws> (raw)

[-- Attachment #1: Type: text/plain, Size: 947 bytes --]

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

[-- Attachment #2: qemu-sdl-show-cursor.diff --]
[-- Type: text/plain, Size: 1546 bytes --]

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;

                 reply	other threads:[~2006-03-02 20:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4405E92B.5020009@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).