From 9f05fbdabedca3da1ae0f43cd2c5bc9f39f0e3b4 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 23 Mar 2024 20:50:44 +0000 Subject: [PATCH] core: switch to server-side cursors ref #51 --- CMakeLists.txt | 2 ++ src/events/Events.cpp | 15 ++++++++++----- src/hyprpicker.hpp | 17 +++++++++-------- src/includes.hpp | 3 ++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 063fe46..5010108 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,8 @@ add_executable(hyprpicker ${SRCFILES}) protocol("protocols/wlr-layer-shell-unstable-v1.xml" "wlr-layer-shell-unstable-v1" true) protocol("protocols/wlr-screencopy-unstable-v1.xml" "wlr-screencopy-unstable-v1" true) protocol("stable/xdg-shell/xdg-shell.xml" "xdg-shell" false) +protocol("staging/cursor-shape/cursor-shape-v1.xml" "wp-cursor-shape-v1" false) +protocol("unstable/tablet/tablet-unstable-v2.xml" "tablet-unstable-v2" false) target_compile_definitions(hyprpicker PRIVATE "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") target_compile_definitions(hyprpicker PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"") diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 32a9277..e9fb6e1 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -69,6 +69,8 @@ void Events::handleGlobal(void* data, struct wl_registry* registry, uint32_t nam g_pHyprpicker->createSeat((wl_seat*)wl_registry_bind(registry, name, &wl_seat_interface, 1)); } else if (strcmp(interface, zwlr_screencopy_manager_v1_interface.name) == 0) { g_pHyprpicker->m_pSCMgr = (zwlr_screencopy_manager_v1*)wl_registry_bind(registry, name, &zwlr_screencopy_manager_v1_interface, 1); + } else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) { + g_pHyprpicker->m_pCursorShape = (wp_cursor_shape_manager_v1*)wl_registry_bind(registry, name, &wp_cursor_shape_manager_v1_interface, 1); } } @@ -78,7 +80,9 @@ void Events::handleGlobalRemove(void* data, struct wl_registry* registry, uint32 void Events::handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities) { if (capabilities & WL_SEAT_CAPABILITY_POINTER) { - wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, wl_seat); + const auto POINTER = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(POINTER, &pointerListener, wl_seat); + g_pHyprpicker->m_pCursorShapeDevice = wp_cursor_shape_manager_v1_get_pointer(g_pHyprpicker->m_pCursorShape, POINTER); } else { Debug::log(CRIT, "Hyprpicker cannot work without a pointer!"); g_pHyprpicker->finish(1); @@ -99,10 +103,11 @@ void Events::handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint3 if (!ls->pCursorImg) break; - wl_surface_set_buffer_scale(ls->pCursorSurface, ls->m_pMonitor->scale); - wl_surface_attach(ls->pCursorSurface, wl_cursor_image_get_buffer(ls->pCursorImg), 0, 0); - wl_pointer_set_cursor(wl_pointer, serial, ls->pCursorSurface, ls->pCursorImg->hotspot_x / ls->m_pMonitor->scale, ls->pCursorImg->hotspot_y / ls->m_pMonitor->scale); - wl_surface_commit(ls->pCursorSurface); + // wl_surface_set_buffer_scale(ls->pCursorSurface, ls->m_pMonitor->scale); + // wl_surface_attach(ls->pCursorSurface, wl_cursor_image_get_buffer(ls->pCursorImg), 0, 0); + // wl_pointer_set_cursor(wl_pointer, serial, ls->pCursorSurface, ls->pCursorImg->hotspot_x / ls->m_pMonitor->scale, ls->pCursorImg->hotspot_y / ls->m_pMonitor->scale); + // wl_surface_commit(ls->pCursorSurface); + wp_cursor_shape_device_v1_set_shape(g_pHyprpicker->m_pCursorShapeDevice, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR); } } } diff --git a/src/hyprpicker.hpp b/src/hyprpicker.hpp index 60a8851..5a29d83 100644 --- a/src/hyprpicker.hpp +++ b/src/hyprpicker.hpp @@ -4,8 +4,7 @@ #include "helpers/LayerSurface.hpp" #include "helpers/PoolBuffer.hpp" -enum eOutputMode -{ +enum eOutputMode { OUTPUT_CMYK = 0, OUTPUT_HEX, OUTPUT_RGB, @@ -19,12 +18,14 @@ class CHyprpicker { std::mutex m_mtTickMutex; - wl_compositor* m_pCompositor; - wl_display* m_pWLDisplay; - wl_registry* m_pWLRegistry; - wl_shm* m_pWLSHM; - zwlr_layer_shell_v1* m_pLayerShell; - zwlr_screencopy_manager_v1* m_pSCMgr; + wl_compositor* m_pCompositor = nullptr; + wl_display* m_pWLDisplay = nullptr; + wl_registry* m_pWLRegistry = nullptr; + wl_shm* m_pWLSHM = nullptr; + zwlr_layer_shell_v1* m_pLayerShell = nullptr; + zwlr_screencopy_manager_v1* m_pSCMgr = nullptr; + wp_cursor_shape_manager_v1* m_pCursorShape = nullptr; + wp_cursor_shape_device_v1* m_pCursorShapeDevice = nullptr; xkb_context* m_pXKBContext = nullptr; xkb_keymap* m_pXKBKeymap = nullptr; diff --git a/src/includes.hpp b/src/includes.hpp index 9890344..fa06edb 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -11,7 +11,7 @@ #include #include -#define class _class +#define class _class #define namespace _namespace #define static @@ -19,6 +19,7 @@ extern "C" { #include "wlr-layer-shell-unstable-v1-protocol.h" #include "wlr-screencopy-unstable-v1-protocol.h" #include "xdg-shell-protocol.h" +#include "wp-cursor-shape-protocol.h" #include #include }