[client] wayland: implement warping through pointer-warp-v1 protocol

This commit is contained in:
Quantum
2026-08-08 14:57:45 -04:00
committed by Geoffrey McRae
parent e2be90e264
commit 25328ec5ba
4 changed files with 40 additions and 17 deletions

View File

@@ -684,13 +684,17 @@ void waylandWarpPointer(int x, int y, bool exiting)
return; return;
} }
if (!wlWm.pointerWarpper)
{
LG_LOCK(wlWm.surfaceLock); LG_LOCK(wlWm.surfaceLock);
if (wlWm.lockedPointer) if (wlWm.lockedPointer)
{ {
LG_UNLOCK(wlWm.surfaceLock); LG_UNLOCK(wlWm.surfaceLock);
MTRACE("warp drop=lock-race target=%d,%d exit=%d", x, y, exiting); MTRACE("warp drop=lock-race target=%d,%d exit=%d", x, y, exiting);
return; return;
} }
}
int width, height; int width, height;
wlWm.desktop->getSize(&width, &height); wlWm.desktop->getSize(&width, &height);
@@ -700,21 +704,32 @@ void waylandWarpPointer(int x, int y, bool exiting)
if (y < 0) y = 0; if (y < 0) y = 0;
else if (y >= height) y = height - 1; else if (y >= height) y = height - 1;
uint32_t tempId = 0;
uint64_t warpSeq;
if (wlWm.pointerWarpper)
{
wp_pointer_warp_v1_warp_pointer(wlWm.pointerWarpper, wlWm.surface,
wlWm.pointer, wl_fixed_from_int(x), wl_fixed_from_int(y),
wlWm.pointerEnterSerial);
warpSeq = app_mouseSeq();
} else {
struct wl_region * region = wl_compositor_create_region(wlWm.compositor); struct wl_region * region = wl_compositor_create_region(wlWm.compositor);
wl_region_add(region, x, y, 1, 1); wl_region_add(region, x, y, 1, 1);
struct zwp_confined_pointer_v1 * confine = zwp_pointer_constraints_v1_confine_pointer( struct zwp_confined_pointer_v1 * confine = zwp_pointer_constraints_v1_confine_pointer(
wlWm.pointerConstraints, wlWm.surface, wlWm.pointer, region, wlWm.pointerConstraints, wlWm.surface, wlWm.pointer, region,
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
uint32_t tempId = proxyId(confine); tempId = proxyId(confine);
wl_surface_commit(wlWm.surface); wl_surface_commit(wlWm.surface);
zwp_confined_pointer_v1_destroy(confine); zwp_confined_pointer_v1_destroy(confine);
wl_surface_commit(wlWm.surface); wl_surface_commit(wlWm.surface);
wl_region_destroy(region); wl_region_destroy(region);
uint64_t warpSeq = app_mouseSeq(); warpSeq = app_mouseSeq();
LG_UNLOCK(wlWm.surfaceLock); LG_UNLOCK(wlWm.surfaceLock);
}
MLOG(warpSeq, "warp req=%d,%d target=%d,%d exit=%d temp=%u", MLOG(warpSeq, "warp req=%d,%d target=%d,%d exit=%d temp=%u",
reqX, reqY, x, y, exiting, tempId); reqX, reqY, x, y, exiting, tempId);

View File

@@ -72,6 +72,9 @@ wayland_generate(
wayland_generate( wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml" "${WAYLAND_PROTOCOLS_BASE}/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml"
"${CMAKE_BINARY_DIR}/wayland/wayland-xdg-toplevel-icon-v1-client-protocol") "${CMAKE_BINARY_DIR}/wayland/wayland-xdg-toplevel-icon-v1-client-protocol")
wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/staging/pointer-warp/pointer-warp-v1.xml"
"${CMAKE_BINARY_DIR}/wayland/wayland-pointer-warp-v1-client-protocol")
target_link_libraries(wayland_protocol target_link_libraries(wayland_protocol
PkgConfig::WAYLAND PkgConfig::WAYLAND

View File

@@ -80,6 +80,9 @@ static void registryGlobalHandler(void * data, struct wl_registry * registry,
else if (!strcmp(interface, xdg_toplevel_icon_manager_v1_interface.name)) else if (!strcmp(interface, xdg_toplevel_icon_manager_v1_interface.name))
wlWm.iconManager = wl_registry_bind(wlWm.registry, name, wlWm.iconManager = wl_registry_bind(wlWm.registry, name,
&xdg_toplevel_icon_manager_v1_interface, 1); &xdg_toplevel_icon_manager_v1_interface, 1);
else if (!strcmp(interface, wp_pointer_warp_v1_interface.name))
wlWm.pointerWarpper = wl_registry_bind(wlWm.registry, name,
&wp_pointer_warp_v1_interface, 1);
else if (wlWm.desktop->registryGlobalHandler( else if (wlWm.desktop->registryGlobalHandler(
data, registry, name, interface, version)) data, registry, name, interface, version))
return; return;

View File

@@ -53,6 +53,7 @@
#include "wayland-content-type-v1-client-protocol.h" #include "wayland-content-type-v1-client-protocol.h"
#include "wayland-color-management-v1-client-protocol.h" #include "wayland-color-management-v1-client-protocol.h"
#include "wayland-xdg-toplevel-icon-v1-client-protocol.h" #include "wayland-xdg-toplevel-icon-v1-client-protocol.h"
#include "wayland-pointer-warp-v1-client-protocol.h"
#include "scale.h" #include "scale.h"
#include "motion.h" #include "motion.h"
@@ -196,6 +197,7 @@ struct WaylandDSState
struct zwp_pointer_constraints_v1 * pointerConstraints; struct zwp_pointer_constraints_v1 * pointerConstraints;
struct zwp_relative_pointer_v1 * relativePointer; struct zwp_relative_pointer_v1 * relativePointer;
struct zwp_locked_pointer_v1 * lockedPointer; struct zwp_locked_pointer_v1 * lockedPointer;
struct wp_pointer_warp_v1 * pointerWarpper;
bool captureRequested; bool captureRequested;
bool showPointer; bool showPointer;
uint32_t pointerEnterSerial; uint32_t pointerEnterSerial;