From 67e0f34e2760a80d74ab5d8ec8d2acae692d307f Mon Sep 17 00:00:00 2001 From: Lennart Klebl <15572276+alcubierre-drive@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:18:23 +0200 Subject: [PATCH] core: fix segfault when cursor_shape is not supported (#76) Co-authored-by: alcubierre-drive --- src/events/Events.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 7cf8851..c261b20 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -82,7 +82,9 @@ void Events::handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilit if (capabilities & WL_SEAT_CAPABILITY_POINTER) { 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); + g_pHyprpicker->m_pCursorShapeDevice = (g_pHyprpicker->m_pCursorShape) ? + wp_cursor_shape_manager_v1_get_pointer(g_pHyprpicker->m_pCursorShape, POINTER) : + nullptr; } else { Debug::log(CRIT, "Hyprpicker cannot work without a pointer!"); g_pHyprpicker->finish(1); @@ -103,11 +105,14 @@ 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); - wp_cursor_shape_device_v1_set_shape(g_pHyprpicker->m_pCursorShapeDevice, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR); + if (g_pHyprpicker->m_pCursorShapeDevice) { + wp_cursor_shape_device_v1_set_shape(g_pHyprpicker->m_pCursorShapeDevice, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR); + } else { + 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); + } } } }