Skip to content

Commit

Permalink
wayland: Add support for the SDL_MOUSE_RELATIVE_SYSTEM_SCALE hint
Browse files Browse the repository at this point in the history
The relative pointer protocol sends both the accelerated and unaccelerated deltas, so select between them based on the hint value.
  • Loading branch information
Kontrabant committed Dec 19, 2024
1 parent d6a95ae commit fce922b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/video/wayland/SDL_waylandevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit fce922b

Please sign in to comment.