[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] Work around bug in SDL_ShowCursor(0) in libsdl-1.2.
From: |
Anthony Liguori |
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 |
User-agent: |
Mail/News 1.5 (X11/20060213) |
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
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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH] Work around bug in SDL_ShowCursor(0) in libsdl-1.2.9,
Anthony Liguori <=