SDL: wayland: Move calls to WAYLAND_wl_cursor_theme_get_cursor out of the switch

From 7dbd6669c36a5e7ba85aa384a0dbc46acf0dce25 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Fri, 16 Feb 2024 11:41:01 +0000
Subject: [PATCH] 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>
---
 src/video/wayland/SDL_waylandmouse.c | 67 ++++++++++++++--------------
 1 file changed, 33 insertions(+), 34 deletions(-)

diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index 33c577785366..841d3da58b1c 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -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 *cursor;
+    const char *css_name = "default";
+    const char *fallback_name = NULL;
 
     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/ */
     switch (cdata->system_cursor) {
     case SDL_SYSTEM_CURSOR_ARROW:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "default");
+        css_name = "default";
         break;
     case SDL_SYSTEM_CURSOR_IBEAM:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "text");
+        css_name = "text";
         break;
     case SDL_SYSTEM_CURSOR_WAIT:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "wait");
+        css_name = "wait";
         break;
     case SDL_SYSTEM_CURSOR_CROSSHAIR:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "crosshair");
+        css_name = "crosshair";
         break;
     case SDL_SYSTEM_CURSOR_WAITARROW:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "progress");
+        css_name = "progress";
         break;
     case SDL_SYSTEM_CURSOR_SIZENWSE:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nwse-resize");
-        if (!cursor) {
-            /* only a single arrow */
-            cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nw-resize");
-        }
+        css_name = "nwse-resize";
+        /* only a single arrow */
+        fallback_name = "nw-resize";
         break;
     case SDL_SYSTEM_CURSOR_SIZENESW:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nesw-resize");
-        if (!cursor) {
-            /* only a single arrow */
-            cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ne-resize");
-        }
+        css_name = "nesw-resize";
+        /* only a single arrow */
+        fallback_name = "ne-resize";
         break;
     case SDL_SYSTEM_CURSOR_SIZEWE:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ew-resize");
-        if (!cursor) {
-            cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "col-resize");
-        }
+        css_name = "ew-resize";
+        fallback_name = "col-resize";
         break;
     case SDL_SYSTEM_CURSOR_SIZENS:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ns-resize");
-        if (!cursor) {
-            cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "row-resize");
-        }
+        css_name = "ns-resize";
+        fallback_name = "row-resize";
         break;
     case SDL_SYSTEM_CURSOR_SIZEALL:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "all-scroll");
+        css_name = "all-scroll";
         break;
     case SDL_SYSTEM_CURSOR_NO:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "not-allowed");
+        css_name = "not-allowed";
         break;
     case SDL_SYSTEM_CURSOR_HAND:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "pointer");
+        css_name = "pointer";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "nw-resize");
+        css_name = "nw-resize";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_TOP:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "n-resize");
+        css_name = "n-resize";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "ne-resize");
+        css_name = "ne-resize";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_RIGHT:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "e-resize");
+        css_name = "e-resize";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "se-resize");
+        css_name = "se-resize";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "s-resize");
+        css_name = "s-resize";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "sw-resize");
+        css_name = "sw-resize";
         break;
     case SDL_SYSTEM_CURSOR_WINDOW_LEFT:
-        cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "w-resize");
+        css_name = "w-resize";
         break;
     default:
         SDL_assert(0);
         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 */
     if (!cursor) {
         cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "default");