core: switch to server-side cursors

ref #51
This commit is contained in:
Vaxry 2024-03-23 20:50:44 +00:00
parent 0e416939a1
commit 9f05fbdabe
4 changed files with 23 additions and 14 deletions

View file

@ -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}\"")

View file

@ -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);
}
}
}

View file

@ -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;

View file

@ -11,7 +11,7 @@
#include <cmath>
#include <math.h>
#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 <wayland-client.h>
#include <wayland-cursor.h>
}