From f4e2ec8fa93b0f7f8f8fe326aacafb9c2d0d8a72 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Tue, 24 Mar 2026 23:44:30 -0700 Subject: [PATCH] h --- include/Mw/LowLevel/Wayland.h | 4 ++++ pl/rules.pl | 1 + src/backend/wayland.c | 25 +++++++++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index 95e84eb..bc8ce1f 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -285,6 +285,7 @@ MwInline int wayland_load_funcs() { #include "Wayland/xdg-decoration-client-protocol.h" #include "Wayland/cursor-shape-client-protocol.h" #include "Wayland/primary-selection-client-protocol.h" +#include "Wayland/pointer-constraints-client-protocol.h" #include "Wayland/xdg-toplevel-icon-client-protocol.h" #endif @@ -418,6 +419,9 @@ struct _MwLLWayland { struct wp_viewport* vp; + struct zwp_pointer_constraints_v1* pointer_constraints; + struct zwp_locked_pointer_v1* locked_pointer; + /* clipboard related stuff. * Note that unlike most interfaces, we don't keep zwp_primary_selection stuff in a wayland_protocol_t because we use wl_data_device as a fallback and want to have it share memory space.*/ diff --git a/pl/rules.pl b/pl/rules.pl index 81a1ece..5433a17 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -42,6 +42,7 @@ if (grep(/^wayland$/, @backends)) { scan_wayland_protocol("staging", "cursor-shape", "-v1"); scan_wayland_protocol("unstable", "xdg-decoration", "-unstable-v1"); scan_wayland_protocol("unstable", "primary-selection", "-unstable-v1"); + scan_wayland_protocol("unstable", "pointer-constraints", "-unstable-v1"); $gl_libs = "-lGL -lGLU"; } diff --git a/src/backend/wayland.c b/src/backend/wayland.c index 5e4e767..4d7f72a 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -5,11 +5,6 @@ #include "../../external/stb_ds.h" -/* TODO: - * - MwLLMakePopupImpl - * - MwLLShowImpl - */ - /* TODO: find out what FreeBSD and such wants us to include */ #ifdef __FreeBSD__ /* XXX: Untested (nishi) */ @@ -450,6 +445,17 @@ static void zwp_primary_selection_device_manager_v1_interface_destroy(struct _Mw (void)data; } +/* zwp_primary_selection_device_manager_v1 setup function */ +static wayland_protocol_t* zwp_pointer_constraints_v1_setup(MwU32 name, struct _MwLLWayland* wayland) { + wayland->pointer_constraints = wl_registry_bind(wayland->registry, name, &zwp_pointer_constraints_v1_interface, 1); + return NULL; +} + +static void zwp_pointer_constraints_v1_interface_destroy(struct _MwLLWayland* wayland, wayland_protocol_t* data) { + (void)wayland; + (void)data; +} + static struct wl_surface* curSurface; /* `wl_pointer.enter` callback */ @@ -1329,6 +1335,7 @@ static void setup_callbacks(struct _MwLLWayland* wayland) { WL_INTERFACE(wl_output); WL_INTERFACE(wl_data_device_manager); WL_INTERFACE(zwp_primary_selection_device_manager_v1); + WL_INTERFACE(zwp_pointer_constraints_v1); if(wayland->type == MWLL_WAYLAND_TOPLEVEL) { WL_INTERFACE(xdg_wm_base); WL_INTERFACE(wp_viewporter); @@ -2275,9 +2282,11 @@ static void MwLLFocusImpl(MwLL handle) { } static void MwLLGrabPointerImpl(MwLL handle, int toggle) { - (void)handle; - (void)toggle; - printf("[WARNING] MwLLGrabPointer not supported on Wayland\n"); + if(handle->wayland.pointer_constraints) { + handle->wayland.locked_pointer = zwp_pointer_constraints_v1_lock_pointer(handle->wayland.pointer_constraints, handle->wayland.framebuffer.surface, handle->wayland.pointer, handle->wayland.region, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); + } else { + printf("[WARNING] MwLLGrabPointer not supported in Wayland session, zwp_pointer_constraints_v1 required.\n"); + } } static void MwLLSetClipboardImpl(MwLL handle, const char* text) {