wayland: Move calls to WAYLAND_wl_cursor_theme_get_cursor out of the switch

This will make it easier to potentially share the switch statement
between X11 and Wayland.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2024-02-16 11:41:01 +00:00 committed by Ryan C. Gordon
parent 40a6c1c0a7
commit 7dbd6669c3

View File

@ -262,6 +262,8 @@ static SDL_bool wayland_get_system_cursor(SDL_VideoData *vdata, Wayland_CursorDa
{ {
struct wl_cursor_theme *theme = NULL; struct wl_cursor_theme *theme = NULL;
struct wl_cursor *cursor; struct wl_cursor *cursor;
const char *css_name = "default";
const char *fallback_name = NULL;
int size = dbus_cursor_size; int size = dbus_cursor_size;
@ -321,84 +323,81 @@ static SDL_bool wayland_get_system_cursor(SDL_VideoData *vdata, Wayland_CursorDa
/* https://www.freedesktop.org/wiki/Specifications/cursor-spec/ */ /* https://www.freedesktop.org/wiki/Specifications/cursor-spec/ */
switch (cdata->system_cursor) { switch (cdata->system_cursor) {
case SDL_SYSTEM_CURSOR_ARROW: case SDL_SYSTEM_CURSOR_ARROW:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "default"); css_name = "default";
break; break;
case SDL_SYSTEM_CURSOR_IBEAM: case SDL_SYSTEM_CURSOR_IBEAM:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "text"); css_name = "text";
break; break;
case SDL_SYSTEM_CURSOR_WAIT: case SDL_SYSTEM_CURSOR_WAIT:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "wait"); css_name = "wait";
break; break;
case SDL_SYSTEM_CURSOR_CROSSHAIR: case SDL_SYSTEM_CURSOR_CROSSHAIR:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "crosshair"); css_name = "crosshair";
break; break;
case SDL_SYSTEM_CURSOR_WAITARROW: case SDL_SYSTEM_CURSOR_WAITARROW:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "progress"); css_name = "progress";
break; break;
case SDL_SYSTEM_CURSOR_SIZENWSE: case SDL_SYSTEM_CURSOR_SIZENWSE:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nwse-resize"); css_name = "nwse-resize";
if (!cursor) { /* only a single arrow */
/* only a single arrow */ fallback_name = "nw-resize";
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nw-resize");
}
break; break;
case SDL_SYSTEM_CURSOR_SIZENESW: case SDL_SYSTEM_CURSOR_SIZENESW:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nesw-resize"); css_name = "nesw-resize";
if (!cursor) { /* only a single arrow */
/* only a single arrow */ fallback_name = "ne-resize";
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ne-resize");
}
break; break;
case SDL_SYSTEM_CURSOR_SIZEWE: case SDL_SYSTEM_CURSOR_SIZEWE:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ew-resize"); css_name = "ew-resize";
if (!cursor) { fallback_name = "col-resize";
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "col-resize");
}
break; break;
case SDL_SYSTEM_CURSOR_SIZENS: case SDL_SYSTEM_CURSOR_SIZENS:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ns-resize"); css_name = "ns-resize";
if (!cursor) { fallback_name = "row-resize";
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "row-resize");
}
break; break;
case SDL_SYSTEM_CURSOR_SIZEALL: case SDL_SYSTEM_CURSOR_SIZEALL:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "all-scroll"); css_name = "all-scroll";
break; break;
case SDL_SYSTEM_CURSOR_NO: case SDL_SYSTEM_CURSOR_NO:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "not-allowed"); css_name = "not-allowed";
break; break;
case SDL_SYSTEM_CURSOR_HAND: case SDL_SYSTEM_CURSOR_HAND:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "pointer"); css_name = "pointer";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT: case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nw-resize"); css_name = "nw-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_TOP: case SDL_SYSTEM_CURSOR_WINDOW_TOP:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "n-resize"); css_name = "n-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT: case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ne-resize"); css_name = "ne-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_RIGHT: case SDL_SYSTEM_CURSOR_WINDOW_RIGHT:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "e-resize"); css_name = "e-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT: case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "se-resize"); css_name = "se-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM: case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "s-resize"); css_name = "s-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT: case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "sw-resize"); css_name = "sw-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_LEFT: case SDL_SYSTEM_CURSOR_WINDOW_LEFT:
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "w-resize"); css_name = "w-resize";
break; break;
default: default:
SDL_assert(0); SDL_assert(0);
return SDL_FALSE; return SDL_FALSE;
} }
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, css_name);
if (!cursor && fallback_name) {
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, fallback_name);
}
/* Fallback to the default cursor if the chosen one wasn't found */ /* Fallback to the default cursor if the chosen one wasn't found */
if (!cursor) { if (!cursor) {
cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "default"); cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "default");