From 73010447c357ad2e5b778b4a501ef650bf44b6d8 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Thu, 5 Feb 2026 09:13:32 -0500 Subject: [PATCH] wayland: Add support for the pointer warp event --- src/video/wayland/SDL_waylandevents.c | 22 ++++++++++++++++------ src/video/wayland/SDL_waylandmouse.c | 7 +++---- src/video/wayland/SDL_waylandvideo.c | 4 +++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index 56e6b61b94..2d31def0c7 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -1336,18 +1336,28 @@ static void pointer_handle_axis_value120(void *data, struct wl_pointer *pointer, pointer_handle_axis_common(seat, SDL_WAYLAND_AXIS_EVENT_VALUE120, axis, wl_fixed_from_int(value120)); } +static void pointer_handle_warp(void *data, struct wl_pointer *wl_pointer, wl_fixed_t surface_x, wl_fixed_t surface_y) +{ + SDL_WaylandSeat *seat = (SDL_WaylandSeat *)data; + + seat->pointer.pending_frame.have_absolute = true; + seat->pointer.pending_frame.absolute.sx = surface_x; + seat->pointer.pending_frame.absolute.sy = surface_y; +} + static const struct wl_pointer_listener pointer_listener = { pointer_handle_enter, pointer_handle_leave, pointer_handle_motion, pointer_handle_button, pointer_handle_axis, - pointer_handle_frame, // Version 5 - pointer_handle_axis_source, // Version 5 - pointer_handle_axis_stop, // Version 5 - pointer_handle_axis_discrete, // Version 5 - pointer_handle_axis_value120, // Version 8 - pointer_handle_axis_relative_direction // Version 9 + pointer_handle_frame, // Version 5 + pointer_handle_axis_source, // Version 5 + pointer_handle_axis_stop, // Version 5 + pointer_handle_axis_discrete, // Version 5 + pointer_handle_axis_value120, // Version 8 + pointer_handle_axis_relative_direction, // Version 9 + pointer_handle_warp // Version 11 }; static void relative_pointer_handle_relative_motion(void *data, diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c index 5533ee7133..dea9d3ae05 100644 --- a/src/video/wayland/SDL_waylandmouse.c +++ b/src/video/wayland/SDL_waylandmouse.c @@ -1198,10 +1198,9 @@ void Wayland_SeatWarpMouse(SDL_WaylandSeat *seat, SDL_WindowData *window, float } } - /* NOTE: There is a pending warp event under discussion that should replace this when available. - * https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/340 - */ - SDL_SendMouseMotion(0, window->sdlwindow, seat->pointer.sdl_id, false, x, y); + if (wl_pointer_get_version(seat->pointer.wl_pointer) < WL_POINTER_WARP_SINCE_VERSION) { + SDL_SendMouseMotion(0, window->sdlwindow, seat->pointer.sdl_id, false, x, y); + } } } diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 6abe2ff238..ec1249dc07 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -86,7 +86,9 @@ #define SDL_WL_COMPOSITOR_VERSION 4 #endif -#if SDL_WAYLAND_CHECK_VERSION(1, 24, 0) +#if SDL_WAYLAND_CHECK_VERSION(1, 26, 0) +#define SDL_WL_SEAT_VERSION 11 +#elif SDL_WAYLAND_CHECK_VERSION(1, 24, 0) #define SDL_WL_SEAT_VERSION 10 #elif SDL_WAYLAND_CHECK_VERSION(1, 22, 0) #define SDL_WL_SEAT_VERSION 9