Просмотр исходного кода

wayland: Add support for the pointer warp event

Frank Praznik 7 месяцев назад
Родитель
Сommit
73010447c3

+ 16 - 6
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));
     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 = {
 static const struct wl_pointer_listener pointer_listener = {
     pointer_handle_enter,
     pointer_handle_enter,
     pointer_handle_leave,
     pointer_handle_leave,
     pointer_handle_motion,
     pointer_handle_motion,
     pointer_handle_button,
     pointer_handle_button,
     pointer_handle_axis,
     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,
 static void relative_pointer_handle_relative_motion(void *data,

+ 3 - 4
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);
+        }
     }
     }
 }
 }
 
 

+ 3 - 1
src/video/wayland/SDL_waylandvideo.c

@@ -86,7 +86,9 @@
 #define SDL_WL_COMPOSITOR_VERSION 4
 #define SDL_WL_COMPOSITOR_VERSION 4
 #endif
 #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
 #define SDL_WL_SEAT_VERSION 10
 #elif SDL_WAYLAND_CHECK_VERSION(1, 22, 0)
 #elif SDL_WAYLAND_CHECK_VERSION(1, 22, 0)
 #define SDL_WL_SEAT_VERSION 9
 #define SDL_WL_SEAT_VERSION 9