-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
Add pointer warping on wayland #112287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add pointer warping on wayland #112287
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -659,6 +659,12 @@ void WaylandThread::_wl_registry_on_global(void *data, struct wl_registry *wl_re | |
| return; | ||
| } | ||
|
|
||
| if (strcmp(interface, wp_pointer_warp_v1_interface.name) == 0) { | ||
| registry->wp_pointer_warp = (struct wp_pointer_warp_v1 *)wl_registry_bind(wl_registry, name, &wp_pointer_warp_v1_interface, 1); | ||
| registry->wp_pointer_warp_name = name; | ||
| return; | ||
| } | ||
|
|
||
| if (strcmp(interface, FIFO_INTERFACE_NAME) == 0) { | ||
| registry->wp_fifo_manager_name = name; | ||
| } | ||
|
|
@@ -1023,6 +1029,17 @@ void WaylandThread::_wl_registry_on_global_remove(void *data, struct wl_registry | |
| return; | ||
| } | ||
|
|
||
| if (name == registry->wp_pointer_warp_name) { | ||
| if (registry->wp_pointer_warp) { | ||
| wp_pointer_warp_v1_destroy(registry->wp_pointer_warp); | ||
| registry->wp_pointer_warp = nullptr; | ||
| } | ||
|
|
||
| registry->wp_pointer_warp_name = 0; | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| { | ||
| // Iterate through all of the seats to find if any got removed. | ||
| List<struct wl_seat *>::Element *E = registry->wl_seats.front(); | ||
|
|
@@ -3374,6 +3391,21 @@ void WaylandThread::seat_state_set_hint(SeatState *p_ss, int p_x, int p_y) { | |
| zwp_locked_pointer_v1_set_cursor_position_hint(p_ss->wp_locked_pointer, wl_fixed_from_int(p_x), wl_fixed_from_int(p_y)); | ||
| } | ||
|
|
||
| void WaylandThread::seat_state_warp_pointer(SeatState *p_ss, int p_x, int p_y) { | ||
| if (registry.wp_pointer_warp == nullptr) { | ||
| return; | ||
| } | ||
|
|
||
| if (p_ss->pointer_data.pointed_id == DisplayServer::INVALID_WINDOW_ID) { | ||
| return; | ||
| } | ||
|
|
||
| struct wl_surface *surface = window_get_wl_surface(p_ss->pointer_data.pointed_id); | ||
Kiisu-Master marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ERR_FAIL_NULL(surface); | ||
|
|
||
| wp_pointer_warp_v1_warp_pointer(registry.wp_pointer_warp, surface, p_ss->wl_pointer, wl_fixed_from_int(p_x), wl_fixed_from_int(p_y), p_ss->pointer_enter_serial); | ||
| } | ||
|
|
||
| void WaylandThread::seat_state_confine_pointer(SeatState *p_ss) { | ||
| ERR_FAIL_NULL(p_ss); | ||
|
|
||
|
|
@@ -4400,6 +4432,44 @@ void WaylandThread::pointer_set_hint(const Point2i &p_hint) { | |
| } | ||
| } | ||
|
|
||
| void WaylandThread::pointer_warp(const Point2i &p_to) { | ||
| // NOTE: This is for compositors that don't support the pointer-warp protocol. | ||
| // It's hacked together and not guaranteed to work. | ||
| if (registry.wp_pointer_warp == nullptr) { | ||
| PointerConstraint old_constraint = pointer_get_constraint(); | ||
|
|
||
| pointer_set_constraint(PointerConstraint::LOCKED); | ||
| pointer_set_hint(p_to); | ||
|
|
||
| pointer_set_constraint(old_constraint); | ||
deralmas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return; | ||
| } | ||
|
|
||
| SeatState *ss = wl_seat_get_seat_state(wl_seat_current); | ||
| if (!ss) { | ||
| return; | ||
| } | ||
|
|
||
| WindowState *ws = window_get_state(ss->pointer_data.pointed_id); | ||
|
|
||
| int wl_pos_x = 0; | ||
| int wl_pos_y = 0; | ||
|
|
||
| if (ws) { | ||
| // NOTE: It looks like it's not really recommended to convert from | ||
| // "godot-space" to "wayland-space" and in general I received mixed feelings | ||
| // discussing about this. I'm not really sure about the maths behind this but, | ||
| // oh well. ¯\_(ツ)_/¯ | ||
| // See: https://oftc.irclog.whitequark.org/wayland/2023-08-23#1692756914-1692816818 | ||
| wl_pos_x = std::round(p_to.x / window_state_get_scale_factor(ws)); | ||
| wl_pos_y = std::round(p_to.y / window_state_get_scale_factor(ws)); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should be: if (!ws) {
return;
}
int wl_pos_x = std::round(p_to.x / window_....Warping to 0,0 is not expected behavior if there's no active window. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea great catch! |
||
|
|
||
| if (ss) { | ||
| seat_state_warp_pointer(ss, wl_pos_x, wl_pos_y); | ||
| } | ||
| } | ||
| WaylandThread::PointerConstraint WaylandThread::pointer_get_constraint() const { | ||
| return pointer_constraint; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1157,7 +1157,7 @@ Files extracted from upstream source: | |
| # wayland-protocols | ||
|
|
||
| - Upstream: https://gitlab.freedesktop.org/wayland/wayland-protocols | ||
| - Version: 1.45 (54346071a5f211f2c482889f2c8ee3b5ecda63ab, 2025) | ||
| - Version: 1.45 (0091197f5c1b1f2c131f1410e99f9c95d50646be, 2025) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the reference, old commit (or version) were wrong and correspond to 1.33. |
||
| - License: MIT | ||
|
|
||
| Files extracted from upstream source: | ||
|
|
@@ -1171,6 +1171,8 @@ Files extracted from upstream source: | |
| - `staging/xdg-activation/README` | ||
| - `staging/xdg-activation/xdg-activation-v1.xml` | ||
| - `staging/xdg-system-bell/xdg-system-bell-v1.xml` | ||
| - `staging/pointer-warp/pointer-warp-v1.xml` | ||
| - `staging/pointer-warp/README` | ||
| - `unstable/idle-inhibit/README` | ||
| - `unstable/idle-inhibit/idle-inhibit-unstable-v1.xml` | ||
| - `unstable/pointer-constraints/README` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| pointer-warp protocol | ||
|
|
||
| Maintainers: | ||
| Neal Gompa <[email protected]> (@Conan_Kudo) | ||
| Xaver Hugl <[email protected]> (@Zamundaaa) | ||
| Matthias Klumpp <[email protected]> (@mak) | ||
| Vlad Zahorodnii <[email protected]> (@zzag) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <protocol name="pointer_warp_v1"> | ||
| <copyright> | ||
| Copyright © 2024 Neal Gompa | ||
| Copyright © 2024 Xaver Hugl | ||
| Copyright © 2024 Matthias Klumpp | ||
| Copyright © 2024 Vlad Zahorodnii | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a | ||
| copy of this software and associated documentation files (the "Software"), | ||
| to deal in the Software without restriction, including without limitation | ||
| the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| and/or sell copies of the Software, and to permit persons to whom the | ||
| Software is furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice (including the next | ||
| paragraph) shall be included in all copies or substantial portions of the | ||
| Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| DEALINGS IN THE SOFTWARE. | ||
| </copyright> | ||
|
|
||
| <interface name="wp_pointer_warp_v1" version="1"> | ||
| <description summary="reposition the pointer to a location on a surface"> | ||
| This global interface allows applications to request the pointer to be | ||
| moved to a position relative to a wl_surface. | ||
|
|
||
| Note that if the desired behavior is to constrain the pointer to an area | ||
| or lock it to a position, this protocol does not provide a reliable way | ||
| to do that. The pointer constraint and pointer lock protocols should be | ||
| used for those use cases instead. | ||
|
|
||
| Warning! The protocol described in this file is currently in the testing | ||
| phase. Backward compatible changes may be added together with the | ||
| corresponding interface version bump. Backward incompatible changes can | ||
| only be done by creating a new major version of the extension. | ||
| </description> | ||
|
|
||
| <request name="destroy" type="destructor"> | ||
| <description summary="destroy the warp manager"> | ||
| Destroy the pointer warp manager. | ||
| </description> | ||
| </request> | ||
|
|
||
| <request name="warp_pointer"> | ||
| <description summary="reposition the pointer"> | ||
| Request the compositor to move the pointer to a surface-local position. | ||
| Whether or not the compositor honors the request is implementation defined, | ||
| but it should | ||
| - honor it if the surface has pointer focus, including | ||
| when it has an implicit pointer grab | ||
| - reject it if the enter serial is incorrect | ||
| - reject it if the requested position is outside of the surface | ||
|
|
||
| Note that the enter serial is valid for any surface of the client, | ||
| and does not have to be from the surface the pointer is warped to. | ||
|
|
||
| </description> | ||
| <arg name="surface" type="object" interface="wl_surface" | ||
| summary="surface to position the pointer on"/> | ||
| <arg name="pointer" type="object" interface="wl_pointer" | ||
| summary="the pointer that should be repositioned"/> | ||
| <arg name="x" type="fixed"/> | ||
| <arg name="y" type="fixed"/> | ||
| <arg name="serial" type="uint" summary="serial number of the enter event"/> | ||
| </request> | ||
| </interface> | ||
| </protocol> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to also destroy it
WaylandThread::destroy().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you have to destroy it there too? I'll add this tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea it's kinda annoying. I've considered making it automatic but I feel like it would make everything more complex for little gain.