core: implement more safety around cursor themes

fixes #38
This commit is contained in:
Vaxry 2023-10-30 16:48:36 +00:00
parent 8a7799ae20
commit b6130e3901
2 changed files with 13 additions and 3 deletions

View file

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

View file

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