From b6130e3901ed5c6d423f168705929e555608d870 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 30 Oct 2023 16:48:36 +0000 Subject: [PATCH] core: implement more safety around cursor themes fixes #38 --- src/events/Events.cpp | 3 +++ src/hyprpicker.cpp | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/events/Events.cpp b/src/events/Events.cpp index b6d3006..32a9277 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -96,6 +96,9 @@ void Events::handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint3 if (ls->pSurface == surface) { g_pHyprpicker->m_pLastSurface = ls.get(); + 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); diff --git a/src/hyprpicker.cpp b/src/hyprpicker.cpp index a06b960..67bcea9 100644 --- a/src/hyprpicker.cpp +++ b/src/hyprpicker.cpp @@ -80,7 +80,14 @@ void CHyprpicker::recheckACK() { XCURSOR_SIZE = std::stoi(getenv("XCURSOR_SIZE")); } - ls->pCursorImg = wl_cursor_theme_get_cursor(wl_cursor_theme_load(getenv("XCURSOR_THEME"), XCURSOR_SIZE * ls->m_pMonitor->scale, m_pWLSHM), "crosshair")->images[0]; + const auto THEME = wl_cursor_theme_load(getenv("XCURSOR_THEME"), XCURSOR_SIZE * ls->m_pMonitor->scale, m_pWLSHM); + auto cursor = wl_cursor_theme_get_cursor(THEME, "crosshair"); + + if (!cursor) + cursor = wl_cursor_theme_get_cursor(THEME, "left_ptr"); + + if (cursor) + ls->pCursorImg = cursor->images[0]; } } } @@ -242,7 +249,7 @@ void CHyprpicker::convertBuffer(SPoolBuffer* pBuffer) { for (int y = 0; y < pBuffer->pixelSize.y; ++y) { for (int x = 0; x < pBuffer->pixelSize.x; ++x) { - uint32_t * px = (uint32_t*) (data + y * (int)pBuffer->pixelSize.x * 4 + x * 4); + uint32_t* px = (uint32_t*)(data + y * (int)pBuffer->pixelSize.x * 4 + x * 4); // conv to 8 bit uint8_t R = (uint8_t)std::round((255.0 * (((*px) & 0b00000000000000000000001111111111) >> 0) / 1023.0)); @@ -252,7 +259,7 @@ void CHyprpicker::convertBuffer(SPoolBuffer* pBuffer) { // write 8-bit values *px = ((FLIP ? B : R) << 0) + (G << 8) + ((FLIP ? R : B) << 16) + (A << 24); - } + } } } break; default: {