Skip to contentSkip to conversation

sdl2: Fix relative mouse mode

PATCH New Cole Robinson 1 participant 3 messages Apr 1, 2014

lore
Share & tools
lore
#0 lore raw

cover sdl2: Fix relative mouse mode

sdl.c received a fix for relative mouse mode, but it wasn't copied to sdl2.c.

Patch #2 uses new SDL2 API to make relative mode behave similar to sdl.c, but I'm not fully confident that it's safe. See patch comments.

Also, relative mode is a mess in gtk as well. I started fixing these only to find that patches were already posted:

https://lists.gnu.org/archive/html/qemu-devel/2014-02/msg02278.html

Cole Robinson (2):
input: sdl2: Fix guest_cursor logic
input: sdl2: Fix relative mode to match SDL1 behavior

 ui/sdl2.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
Signature · 1 line
1.9.0
#1 lore raw

PATCH 1/2 input: sdl2: Fix guest_cursor logic

Unbreaks relative mouse mode with sdl2, just like was done with sdl.c in c3aa84b6.

---
 ui/sdl2.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
ui/sdl2.c +11 -7
index f1532e9..e4cb9fb 100644
@@ -403,13 +403,17 @@ static void sdl_send_mouse_event(struct sdl2_state *scon, int dx, int dy,
         }
         qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X, off_x + x, max_w);
         qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y, off_y + y, max_h);
-    } else if (guest_cursor) {
-        x -= guest_x;
-        y -= guest_y;
-        guest_x += x;
-        guest_y += y;
-        qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_X, x);
-        qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_Y, y);
+    } else {
+        if (guest_cursor) {
+            x -= guest_x;
+            y -= guest_y;
+            guest_x += x;
+            guest_y += y;
+            dx = x;
+            dy = y;
+        }
+        qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_X, dx);
+        qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_Y, dy);
     }
     qemu_input_event_sync();
 }
Signature · 1 line
1.9.0
#2 lore raw

RFC PATCH 2/2 input: sdl2: Fix relative mode to match SDL1 behavior

In reply to Cole Robinson

Right now relative mode accelerates too fast, and has the 'invisible wall' problem. SDL2 added an explicit API to handle this use case, so let's use it.

---
While this fixes things for me, I'm not positive it doesn't have other side effects. I didn't test transition from relative mode to absolute mode and back, which might hit issues.

 ui/sdl2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ui/sdl2.c +2 -1
index e4cb9fb..7506e2e 100644
@@ -278,7 +278,7 @@ static void sdl_hide_cursor(void)
         SDL_ShowCursor(1);
         SDL_SetCursor(sdl_cursor_hidden);
     } else {
-        SDL_ShowCursor(0);
+        SDL_SetRelativeMouseMode(SDL_TRUE);
     }
 }
 
@@ -289,6 +289,7 @@ static void sdl_show_cursor(void)
     }
 
     if (!qemu_input_is_absolute()) {
+        SDL_SetRelativeMouseMode(SDL_FALSE);
         SDL_ShowCursor(1);
         if (guest_cursor &&
             (gui_grab || qemu_input_is_absolute() || absolute_enabled)) {
Signature · 1 line
1.9.0