Browse Source

wayland: Add support for the SDL_MOUSE_RELATIVE_SYSTEM_SCALE hint

The relative pointer protocol sends both the accelerated and unaccelerated deltas, so select between them based on the hint value.
Frank Praznik 4 months ago
parent
commit
fce922b66c
1 changed files with 10 additions and 5 deletions
  1. 10 5
      src/video/wayland/SDL_waylandevents.c

+ 10 - 5
src/video/wayland/SDL_waylandevents.c

@@ -3042,17 +3042,22 @@ static void relative_pointer_handle_relative_motion(void *data,
     struct SDL_WaylandInput *input = data;
     SDL_VideoData *d = input->display;
     SDL_WindowData *window = input->pointer_focus;
-    double dx_unaccel;
-    double dy_unaccel;
+    double dx;
+    double dy;
 
     // Relative pointer event times are in microsecond granularity.
     const Uint64 timestamp = SDL_US_TO_NS(((Uint64)time_hi << 32) | (Uint64)time_lo);
 
-    dx_unaccel = wl_fixed_to_double(dx_unaccel_w);
-    dy_unaccel = wl_fixed_to_double(dy_unaccel_w);
+    if (!SDL_GetMouse()->enable_relative_system_scale) {
+        dx = wl_fixed_to_double(dx_unaccel_w);
+        dy = wl_fixed_to_double(dy_unaccel_w);
+    } else {
+        dx = wl_fixed_to_double(dx_w);
+        dy = wl_fixed_to_double(dy_w);
+    }
 
     if (input->pointer_focus && d->relative_mouse_mode) {
-        SDL_SendMouseMotion(Wayland_GetEventTimestamp(timestamp), window->sdlwindow, input->pointer_id, true, (float)dx_unaccel, (float)dy_unaccel);
+        SDL_SendMouseMotion(Wayland_GetEventTimestamp(timestamp), window->sdlwindow, input->pointer_id, true, (float)dx, (float)dy);
     }
 }