-
Notifications
You must be signed in to change notification settings - Fork 117
[Wayland] Add support for pointer-warp-v1 protocol #795
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9b51e95
[Wayland] Add support for pointer-warp-v1 protocol
Sunderland93 52044fa
Merge branch 'master' into pointer_warp
Sunderland93 3ea1fed
Merge branch 'master' into pointer_warp
Sunderland93 4b974c0
pointer-wrap: use coords.x and coords.y for the bounds check
Sunderland93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * Wayland Support | ||
| * | ||
| * Copyright (C) 2025 Red Hat Inc. | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * Author: Carlos Garnacho <carlosg@gnome.org> | ||
| */ | ||
|
|
||
| #include "config.h" | ||
|
|
||
| #include "meta-wayland-pointer-warp.h" | ||
|
|
||
| #include "meta-wayland-private.h" | ||
| #include "meta-wayland-seat.h" | ||
| #include "meta-wayland-surface.h" | ||
|
|
||
| #include "pointer-warp-v1-server-protocol.h" | ||
|
|
||
| struct _MetaWaylandPointerWarp | ||
| { | ||
| MetaWaylandSeat *seat; | ||
| struct wl_list resource_list; | ||
| }; | ||
|
|
||
| static void | ||
| pointer_warp_destroy (struct wl_client *client, | ||
| struct wl_resource *resource) | ||
| { | ||
| wl_resource_destroy (resource); | ||
| } | ||
|
|
||
| static void | ||
| pointer_warp_perform (struct wl_client *client, | ||
| struct wl_resource *resource, | ||
| struct wl_resource *surface_resource, | ||
| struct wl_resource *pointer_resource, | ||
| wl_fixed_t x, | ||
| wl_fixed_t y, | ||
| uint32_t serial) | ||
| { | ||
| ClutterSeat *seat; | ||
| MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource); | ||
| MetaWaylandPointer *pointer = wl_resource_get_user_data (pointer_resource); | ||
| MetaSurfaceActor *surface_actor = meta_wayland_surface_get_actor (surface); | ||
| graphene_point3d_t coords = | ||
| GRAPHENE_POINT3D_INIT ((float) wl_fixed_to_double (x), | ||
| (float) wl_fixed_to_double (y), | ||
| 0.0); | ||
|
|
||
| /* Not focused and implicitly grabbed */ | ||
| if (!meta_wayland_pointer_get_grab_info (pointer, surface, serial, TRUE, | ||
| NULL, NULL, NULL)) | ||
| return; | ||
|
|
||
| /* Outside of actor */ | ||
| if (!surface_actor || | ||
| x < 0 || x > clutter_actor_get_width (CLUTTER_ACTOR (surface_actor)) || | ||
| y < 0 || y > clutter_actor_get_height (CLUTTER_ACTOR (surface_actor))) | ||
| return; | ||
|
|
||
| clutter_actor_apply_transform_to_point (CLUTTER_ACTOR (surface_actor), | ||
| &coords, &coords); | ||
|
|
||
| seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); | ||
|
|
||
| clutter_seat_warp_pointer (seat, (int) coords.x, (int) coords.y); | ||
| } | ||
|
|
||
| static struct wp_pointer_warp_v1_interface pointer_warp_interface = { | ||
| pointer_warp_destroy, | ||
| pointer_warp_perform, | ||
| }; | ||
|
|
||
| static void | ||
| unbind_resource (struct wl_resource *resource) | ||
| { | ||
| wl_list_remove (wl_resource_get_link (resource)); | ||
| } | ||
|
|
||
| static void | ||
| bind_pointer_warp (struct wl_client *client, | ||
| void *data, | ||
| uint32_t version, | ||
| uint32_t id) | ||
| { | ||
| MetaWaylandPointerWarp *pointer_warp = data; | ||
| struct wl_resource *resource; | ||
|
|
||
| resource = wl_resource_create (client, &wp_pointer_warp_v1_interface, | ||
| MIN (version, META_WP_POINTER_WARP_VERSION), | ||
| id); | ||
| wl_resource_set_implementation (resource, &pointer_warp_interface, | ||
| pointer_warp, unbind_resource); | ||
| wl_resource_set_user_data (resource, pointer_warp); | ||
| wl_list_insert (&pointer_warp->resource_list, | ||
| wl_resource_get_link (resource)); | ||
| } | ||
|
|
||
| MetaWaylandPointerWarp * | ||
| meta_wayland_pointer_warp_new (MetaWaylandSeat *seat) | ||
| { | ||
| MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default (); | ||
| MetaWaylandPointerWarp *pointer_warp; | ||
|
|
||
| pointer_warp = g_new0 (MetaWaylandPointerWarp, 1); | ||
| pointer_warp->seat = seat; | ||
| wl_list_init (&pointer_warp->resource_list); | ||
|
|
||
| wl_global_create (compositor->wayland_display, | ||
| &wp_pointer_warp_v1_interface, | ||
| META_WP_POINTER_WARP_VERSION, | ||
| pointer_warp, bind_pointer_warp); | ||
|
|
||
| return pointer_warp; | ||
| } | ||
|
|
||
| void | ||
| meta_wayland_pointer_warp_destroy (MetaWaylandPointerWarp *pointer_warp) | ||
| { | ||
| wl_list_remove (&pointer_warp->resource_list); | ||
| g_free (pointer_warp); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Wayland Support | ||
| * | ||
| * Copyright (C) 2025 Red Hat Inc. | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * Author: Carlos Garnacho <carlosg@gnome.org> | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <glib.h> | ||
| #include <wayland-server.h> | ||
|
|
||
| #include "wayland/meta-wayland-types.h" | ||
|
|
||
| typedef struct _MetaWaylandPointerWarp MetaWaylandPointerWarp; | ||
|
|
||
| MetaWaylandPointerWarp * meta_wayland_pointer_warp_new (MetaWaylandSeat *seat); | ||
|
|
||
| void meta_wayland_pointer_warp_destroy (MetaWaylandPointerWarp *pointer_warp); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should use
coords.x,coords.yhere instead ofx,y?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.
Using
xandyis correct because the bounds check must happen in the surface-local coordinate space, before any transformation is applied.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 mean, you can't can't compare wl_fixed_t this way, you have to extract the value first (with
wl_fixed_to_double()) - you could use the values you initializedcoordsto since this is before the transform below.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.
Ok, done