|
38 | 38 | #include "cursor-shape-v1-client-protocol.h"
|
39 | 39 | #include "pointer-constraints-unstable-v1-client-protocol.h"
|
40 | 40 | #include "viewporter-client-protocol.h"
|
| 41 | +#include "pointer-warp-v1-client-protocol.h" |
41 | 42 |
|
42 | 43 | #include "../../SDL_hints_c.h"
|
43 | 44 |
|
@@ -832,43 +833,50 @@ void Wayland_SeatWarpMouse(SDL_WaylandSeat *seat, SDL_WindowData *window, float
|
832 | 833 | SDL_VideoData *d = vd->internal;
|
833 | 834 |
|
834 | 835 | if (seat->pointer.wl_pointer) {
|
835 |
| - bool toggle_lock = !seat->pointer.locked_pointer; |
836 |
| - bool update_grabs = false; |
837 |
| - |
838 |
| - /* The pointer confinement protocol allows setting a hint to warp the pointer, |
839 |
| - * but only when the pointer is locked. |
840 |
| - * |
841 |
| - * Lock the pointer, set the position hint, unlock, and hope for the best. |
842 |
| - */ |
843 |
| - if (toggle_lock) { |
844 |
| - if (seat->pointer.confined_pointer) { |
845 |
| - zwp_confined_pointer_v1_destroy(seat->pointer.confined_pointer); |
846 |
| - seat->pointer.confined_pointer = NULL; |
847 |
| - update_grabs = true; |
| 836 | + if (d->wp_pointer_warp_v1) { |
| 837 | + // It's a protocol error to warp the pointer outside of the surface, so clamp the position. |
| 838 | + const wl_fixed_t f_x = wl_fixed_from_double(SDL_clamp(x / window->pointer_scale.x, 0, window->current.logical_width)); |
| 839 | + const wl_fixed_t f_y = wl_fixed_from_double(SDL_clamp(y / window->pointer_scale.y, 0, window->current.logical_height)); |
| 840 | + wp_pointer_warp_v1_warp_pointer(d->wp_pointer_warp_v1, window->surface, seat->pointer.wl_pointer, f_x, f_y, seat->pointer.enter_serial); |
| 841 | + } else { |
| 842 | + bool toggle_lock = !seat->pointer.locked_pointer; |
| 843 | + bool update_grabs = false; |
| 844 | + |
| 845 | + /* The pointer confinement protocol allows setting a hint to warp the pointer, |
| 846 | + * but only when the pointer is locked. |
| 847 | + * |
| 848 | + * Lock the pointer, set the position hint, unlock, and hope for the best. |
| 849 | + */ |
| 850 | + if (toggle_lock) { |
| 851 | + if (seat->pointer.confined_pointer) { |
| 852 | + zwp_confined_pointer_v1_destroy(seat->pointer.confined_pointer); |
| 853 | + seat->pointer.confined_pointer = NULL; |
| 854 | + update_grabs = true; |
| 855 | + } |
| 856 | + seat->pointer.locked_pointer = zwp_pointer_constraints_v1_lock_pointer(d->pointer_constraints, window->surface, |
| 857 | + seat->pointer.wl_pointer, NULL, |
| 858 | + ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); |
848 | 859 | }
|
849 |
| - seat->pointer.locked_pointer = zwp_pointer_constraints_v1_lock_pointer(d->pointer_constraints, window->surface, |
850 |
| - seat->pointer.wl_pointer, NULL, |
851 |
| - ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); |
852 |
| - } |
853 | 860 |
|
854 |
| - const wl_fixed_t f_x = wl_fixed_from_double(x / window->pointer_scale.x); |
855 |
| - const wl_fixed_t f_y = wl_fixed_from_double(y / window->pointer_scale.y); |
856 |
| - zwp_locked_pointer_v1_set_cursor_position_hint(seat->pointer.locked_pointer, f_x, f_y); |
857 |
| - wl_surface_commit(window->surface); |
| 861 | + const wl_fixed_t f_x = wl_fixed_from_double(x / window->pointer_scale.x); |
| 862 | + const wl_fixed_t f_y = wl_fixed_from_double(y / window->pointer_scale.y); |
| 863 | + zwp_locked_pointer_v1_set_cursor_position_hint(seat->pointer.locked_pointer, f_x, f_y); |
| 864 | + wl_surface_commit(window->surface); |
858 | 865 |
|
859 |
| - if (toggle_lock) { |
860 |
| - zwp_locked_pointer_v1_destroy(seat->pointer.locked_pointer); |
861 |
| - seat->pointer.locked_pointer = NULL; |
| 866 | + if (toggle_lock) { |
| 867 | + zwp_locked_pointer_v1_destroy(seat->pointer.locked_pointer); |
| 868 | + seat->pointer.locked_pointer = NULL; |
862 | 869 |
|
863 |
| - if (update_grabs) { |
864 |
| - Wayland_SeatUpdatePointerGrab(seat); |
| 870 | + if (update_grabs) { |
| 871 | + Wayland_SeatUpdatePointerGrab(seat); |
| 872 | + } |
865 | 873 | }
|
866 |
| - } |
867 | 874 |
|
868 |
| - /* NOTE: There is a pending warp event under discussion that should replace this when available. |
869 |
| - * https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/340 |
870 |
| - */ |
871 |
| - SDL_SendMouseMotion(0, window->sdlwindow, seat->pointer.sdl_id, false, x, y); |
| 875 | + /* NOTE: There is a pending warp event under discussion that should replace this when available. |
| 876 | + * https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/340 |
| 877 | + */ |
| 878 | + SDL_SendMouseMotion(0, window->sdlwindow, seat->pointer.sdl_id, false, x, y); |
| 879 | + } |
872 | 880 | }
|
873 | 881 | }
|
874 | 882 |
|
|
0 commit comments