From 56b374b5699bf1ba77744c7019fa658dcd1fe3b3 Mon Sep 17 00:00:00 2001 From: spacepineapple24 Date: Mon, 24 Mar 2025 18:28:04 +0000 Subject: [PATCH] Implement wp_cursor_shape_v1 --- bar/meson.build | 9 ++++++++- bar/wayland.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- meson.build | 4 ++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/bar/meson.build b/bar/meson.build index 6ca5ec9..9163c79 100644 --- a/bar/meson.build +++ b/bar/meson.build @@ -15,11 +15,18 @@ if backend_wayland wl_proto_headers = [] wl_proto_src = [] - foreach prot : [ + wl_proto_xml = [ '../external/wlr-layer-shell-unstable-v1.xml', wayland_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml', wayland_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml'] + if wayland_protocols.version().version_compare('>=1.32') + wl_proto_xml += [ + wayland_protocols_datadir + '/staging/cursor-shape/cursor-shape-v1.xml', + wayland_protocols_datadir + '/unstable/tablet/tablet-unstable-v2.xml'] + endif + + foreach prot : wl_proto_xml wl_proto_headers += custom_target( prot.underscorify() + '-client-header', output: '@BASENAME@.h', diff --git a/bar/wayland.c b/bar/wayland.c index 86ab252..4b31e01 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -21,6 +21,10 @@ #include #include +#ifdef HAVE_CURSOR_SHAPE +#include +#endif + #define LOG_MODULE "bar:wayland" #define LOG_ENABLE_DBG 0 #include "../log.h" @@ -107,6 +111,10 @@ struct wayland_backend { struct zxdg_output_manager_v1 *xdg_output_manager; +#ifdef HAVE_CURSOR_SHAPE + struct wp_cursor_shape_manager_v1 *cursor_shape_manager; +#endif + /* TODO: set directly in bar instead */ int width, height; @@ -145,6 +153,23 @@ seat_destroy(struct seat *seat) wl_seat_release(seat->seat); } +static bool attempt_cursor_shape(struct wayland_backend *wayl, struct wl_pointer *wl_pointer, + uint32_t serial) { +#ifdef HAVE_CURSOR_SHAPE + if (wayl->cursor_shape_manager) { + struct wp_cursor_shape_device_v1 *device = + wp_cursor_shape_manager_v1_get_pointer( + wayl->cursor_shape_manager, wl_pointer); + wp_cursor_shape_device_v1_set_shape(device, serial, + WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT); + wp_cursor_shape_device_v1_destroy(device); + return true; + } +#endif + + return false; +} + void * bar_backend_wayland_new(void) { @@ -235,8 +260,11 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, str seat->pointer.y = wl_fixed_to_int(surface_y) * backend->scale; backend->active_seat = seat; - reload_cursor_theme(seat, backend->monitor->scale); - update_cursor_surface(backend, seat); + + if (!attempt_cursor_shape(backend, wl_pointer, serial)) { + reload_cursor_theme(seat, backend->monitor->scale); + update_cursor_surface(backend, seat); + } } static void @@ -678,6 +706,16 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name, const cha backend->xdg_output_manager = wl_registry_bind(registry, name, &zxdg_output_manager_v1_interface, required); } +#ifdef HAVE_CURSOR_SHAPE + else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) { + const uint32_t required = 1; + if (!verify_iface_version(interface, version, required)) + return; + + backend->cursor_shape_manager = wl_registry_bind( + backend->registry, name, &wp_cursor_shape_manager_v1_interface, required); + } +#endif } static void @@ -1146,6 +1184,11 @@ cleanup(struct bar *_bar) if (backend->xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(backend->xdg_output_manager); +#ifdef HAVE_CURSOR_SHAPE + if (backend->cursor_shape_manager != NULL) + wp_cursor_shape_manager_v1_destroy(backend->cursor_shape_manager); +#endif + tll_foreach(backend->seats, it) seat_destroy(&it->item); tll_free(backend->seats); diff --git a/meson.build b/meson.build index 67d3096..97654c8 100644 --- a/meson.build +++ b/meson.build @@ -71,7 +71,11 @@ backend_x11 = xcb_aux.found() and xcb_cursor.found() and xcb_event.found() and \ # Wayland dependencies wayland_client = dependency('wayland-client', required: get_option('backend-wayland')) wayland_cursor = dependency('wayland-cursor', required: get_option('backend-wayland')) +wayland_protocols = dependency('wayland-protocols', required: get_option('backend-wayland')) backend_wayland = wayland_client.found() and wayland_cursor.found() +if backend_wayland and wayland_protocols.version().version_compare('>=1.32') + add_project_arguments('-DHAVE_CURSOR_SHAPE=1', language: 'c') +endif # "My" dependencies, fallback to subproject tllist = dependency('tllist', version: '>=1.0.1', fallback: 'tllist')