Wayland: Ensure cursor theme is loaded before trying to set cursor

This commit is contained in:
Kovid Goyal
2020-06-11 07:57:08 +05:30
parent 8a178ebe55
commit 064aa3a150

12
glfw/wl_window.c vendored
View File

@@ -41,6 +41,12 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
static void
load_cursor_theme(_GLFWwindow* window) {
window->wl.cursorTheme = _wlCursorThemeManage(
_glfw.wl.cursorThemeManager, window->wl.cursorTheme, _wlCursorPxFromScale(window->wl.scale));
}
static void static void
setCursorImage(_GLFWwindow* window) setCursorImage(_GLFWwindow* window)
{ {
@@ -57,6 +63,7 @@ setCursorImage(_GLFWwindow* window)
} else } else
{ {
if (cursorWayland->scale != scale) { if (cursorWayland->scale != scale) {
if (!window->wl.cursorTheme) load_cursor_theme(window);
struct wl_cursor *newCursor = _glfwLoadCursor(cursorWayland->shape, window->wl.cursorTheme); struct wl_cursor *newCursor = _glfwLoadCursor(cursorWayland->shape, window->wl.cursorTheme);
if (newCursor != NULL) { if (newCursor != NULL) {
cursorWayland->cursor = newCursor; cursorWayland->cursor = newCursor;
@@ -125,9 +132,7 @@ static bool checkScaleChange(_GLFWwindow* window)
{ {
window->wl.scale = scale; window->wl.scale = scale;
wl_surface_set_buffer_scale(window->wl.surface, scale); wl_surface_set_buffer_scale(window->wl.surface, scale);
window->wl.cursorTheme = _wlCursorThemeManage(_glfw.wl.cursorThemeManager, load_cursor_theme(window);
window->wl.cursorTheme,
_wlCursorPxFromScale(scale));
setCursorImage(window); setCursorImage(window);
return true; return true;
} }
@@ -838,6 +843,7 @@ try_cursor_names(struct wl_cursor_theme* theme, int arg_count, ...) {
struct wl_cursor* _glfwLoadCursor(GLFWCursorShape shape, struct wl_cursor_theme* theme) struct wl_cursor* _glfwLoadCursor(GLFWCursorShape shape, struct wl_cursor_theme* theme)
{ {
static bool warnings[GLFW_INVALID_CURSOR] = {0}; static bool warnings[GLFW_INVALID_CURSOR] = {0};
if (!theme) return NULL;
#define NUMARGS(...) (sizeof((const char*[]){__VA_ARGS__})/sizeof(const char*)) #define NUMARGS(...) (sizeof((const char*[]){__VA_ARGS__})/sizeof(const char*))
#define C(name, ...) case name: { \ #define C(name, ...) case name: { \
ans = try_cursor_names(theme, NUMARGS(__VA_ARGS__), __VA_ARGS__); \ ans = try_cursor_names(theme, NUMARGS(__VA_ARGS__), __VA_ARGS__); \