mirror of
https://github.com/glfw/glfw.git
synced 2025-10-01 04:10:59 +00:00
Wayland: Implement support for glfwSetCursorPos
This commit is contained in:
parent
8e15281d34
commit
7b9589bf38
72
deps/wayland/pointer-warp-v1.xml
vendored
Normal file
72
deps/wayland/pointer-warp-v1.xml
vendored
Normal file
@ -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>
|
@ -159,6 +159,12 @@ less than the actual scale.
|
||||
|
||||
[fractional-scale-v1]: https://wayland.app/protocols/fractional-scale-v1
|
||||
|
||||
GLFW uses the [pointer-warp-v1][] protocol to implement setting the cursor position.
|
||||
If the running compositor does not support this protocol, `glfwSetCursorPos` while the cursor is in any mode
|
||||
other than `GLFW_CURSOR_DISABLED` will return @ref GLFW_FEATURE_UNAVAILABLE.
|
||||
|
||||
[pointer-warp-v1]: https://wayland.app/protocols/pointer-warp-v1
|
||||
|
||||
|
||||
## GLX extensions {#compat_glx}
|
||||
|
||||
|
@ -100,6 +100,7 @@ if (GLFW_BUILD_WAYLAND)
|
||||
generate_wayland_protocol("viewporter.xml")
|
||||
generate_wayland_protocol("xdg-shell.xml")
|
||||
generate_wayland_protocol("idle-inhibit-unstable-v1.xml")
|
||||
generate_wayland_protocol("pointer-warp-v1.xml")
|
||||
generate_wayland_protocol("pointer-constraints-unstable-v1.xml")
|
||||
generate_wayland_protocol("relative-pointer-unstable-v1.xml")
|
||||
generate_wayland_protocol("fractional-scale-v1.xml")
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "fractional-scale-v1-client-protocol.h"
|
||||
#include "xdg-activation-v1-client-protocol.h"
|
||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||
#include "pointer-warp-v1-client-protocol.h"
|
||||
|
||||
// NOTE: Versions of wayland-scanner prior to 1.17.91 named every global array of
|
||||
// wl_interface pointers 'types', making it impossible to combine several unmodified
|
||||
@ -91,6 +92,10 @@
|
||||
#include "idle-inhibit-unstable-v1-client-protocol-code.h"
|
||||
#undef types
|
||||
|
||||
#define types _glfw_pointer_warp_types
|
||||
#include "pointer-warp-v1-client-protocol-code.h"
|
||||
#undef types
|
||||
|
||||
static void wmBaseHandlePing(void* userData,
|
||||
struct xdg_wm_base* wmBase,
|
||||
uint32_t serial)
|
||||
@ -208,6 +213,13 @@ static void registryHandleGlobal(void* userData,
|
||||
&wp_fractional_scale_manager_v1_interface,
|
||||
1);
|
||||
}
|
||||
else if (strcmp(interface, "wp_pointer_warp_v1") == 0)
|
||||
{
|
||||
_glfw.wl.pointerWarp =
|
||||
wl_registry_bind(registry, name,
|
||||
&wp_pointer_warp_v1_interface,
|
||||
1);
|
||||
}
|
||||
}
|
||||
|
||||
static void registryHandleGlobalRemove(void* userData,
|
||||
|
@ -130,6 +130,7 @@ struct wl_output;
|
||||
#define xdg_activation_token_v1_interface _glfw_xdg_activation_token_v1_interface
|
||||
#define wl_surface_interface _glfw_wl_surface_interface
|
||||
#define wp_fractional_scale_v1_interface _glfw_wp_fractional_scale_v1_interface
|
||||
#define wp_pointer_warp_v1_interface _glfw_pointer_warp_v1_interface
|
||||
|
||||
#define GLFW_WAYLAND_WINDOW_STATE _GLFWwindowWayland wl;
|
||||
#define GLFW_WAYLAND_LIBRARY_WINDOW_STATE _GLFWlibraryWayland wl;
|
||||
@ -440,6 +441,7 @@ typedef struct _GLFWlibraryWayland
|
||||
struct zwp_idle_inhibit_manager_v1* idleInhibitManager;
|
||||
struct xdg_activation_v1* activationManager;
|
||||
struct wp_fractional_scale_manager_v1* fractionalScaleManager;
|
||||
struct wp_pointer_warp_v1* pointerWarp;
|
||||
|
||||
_GLFWofferWayland* offers;
|
||||
unsigned int offerCount;
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "xdg-activation-v1-client-protocol.h"
|
||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||
#include "fractional-scale-v1-client-protocol.h"
|
||||
#include "pointer-warp-v1-client-protocol.h"
|
||||
|
||||
#define GLFW_BORDER_SIZE 4
|
||||
#define GLFW_CAPTION_HEIGHT 24
|
||||
@ -2720,9 +2721,15 @@ void _glfwGetCursorPosWayland(_GLFWwindow* window, double* xpos, double* ypos)
|
||||
}
|
||||
|
||||
void _glfwSetCursorPosWayland(_GLFWwindow* window, double x, double y)
|
||||
{
|
||||
if (!_glfw.wl.pointerWarp)
|
||||
{
|
||||
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
|
||||
"Wayland: The platform does not support setting the cursor position");
|
||||
"Wayland: The compositor does not support setting the cursor position");
|
||||
return;
|
||||
}
|
||||
|
||||
wp_pointer_warp_v1_warp_pointer(_glfw.wl.pointerWarp, window->wl.surface, _glfw.wl.pointer, wl_fixed_from_double(x), wl_fixed_from_double(y), _glfw.wl.pointerEnterSerial);
|
||||
}
|
||||
|
||||
void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode)
|
||||
|
Loading…
Reference in New Issue
Block a user