From fce922b66c73624b6007527bdba9960ba226251f Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Thu, 19 Dec 2024 12:04:29 -0500 Subject: [PATCH] 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. --- src/video/wayland/SDL_waylandevents.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index 7696c5e15e..9d8b4baf52 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/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); } }