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];
}
}
}