SDL: x11: Cleaned up system cursor code to match previous Wayland change. (c67f1)

From c67f10e43f8996823f131dfab6d005a9ff9a27b9 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 16 Feb 2024 08:37:23 -0500
Subject: [PATCH] x11: Cleaned up system cursor code to match previous Wayland
 change.

(cherry picked from commit df00a7dd4c3deb03839e799187a3c75fc4e8854b)
---
 src/video/x11/SDL_x11mouse.c | 98 ++++++++++++++----------------------
 1 file changed, 38 insertions(+), 60 deletions(-)

diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c
index 22878c8f3190..beb694178d34 100644
--- a/src/video/x11/SDL_x11mouse.c
+++ b/src/video/x11/SDL_x11mouse.c
@@ -220,75 +220,53 @@ static SDL_Cursor *X11_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
     return cursor;
 }
 
-static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
+static unsigned int GetLegacySystemCursorShape(SDL_SystemCursor id)
 {
-    SDL_Cursor *cursor = NULL;
-    unsigned int shape = 0;
-    const char *xcursorname = SDL_GetCSSCursorName(id, NULL);
-
     switch (id) {
-    default:
-        SDL_assert(0);
-        return NULL;
-    /* X Font Cursors reference: */
-    /*   http://tronche.com/gui/x/xlib/appendix/b/ */
-    case SDL_SYSTEM_CURSOR_ARROW:
-        shape = XC_left_ptr;
-        break;
-    case SDL_SYSTEM_CURSOR_IBEAM:
-        shape = XC_xterm;
-        break;
-    case SDL_SYSTEM_CURSOR_WAIT:
-        shape = XC_watch;
-        break;
-    case SDL_SYSTEM_CURSOR_CROSSHAIR:
-        shape = XC_tcross;
-        break;
-    case SDL_SYSTEM_CURSOR_WAITARROW:
-        shape = XC_watch;
-        break;
-    case SDL_SYSTEM_CURSOR_SIZENWSE:
-        shape = XC_top_left_corner;
-        break;
-    case SDL_SYSTEM_CURSOR_SIZENESW:
-        shape = XC_top_right_corner;
-        break;
-    case SDL_SYSTEM_CURSOR_SIZEWE:
-        shape = XC_sb_h_double_arrow;
-        break;
-    case SDL_SYSTEM_CURSOR_SIZENS:
-        shape = XC_sb_v_double_arrow;
-        break;
-    case SDL_SYSTEM_CURSOR_SIZEALL:
-        shape = XC_fleur;
-        break;
-    case SDL_SYSTEM_CURSOR_NO:
-        shape = XC_pirate;
-        break;
-    case SDL_SYSTEM_CURSOR_HAND:
-        shape = XC_hand2;
-        break;
+        /* X Font Cursors reference: */
+        /*   http://tronche.com/gui/x/xlib/appendix/b/ */
+        case SDL_SYSTEM_CURSOR_ARROW: return XC_left_ptr;
+        case SDL_SYSTEM_CURSOR_IBEAM: return XC_xterm;
+        case SDL_SYSTEM_CURSOR_WAIT: return XC_watch;
+        case SDL_SYSTEM_CURSOR_CROSSHAIR: return XC_tcross;
+        case SDL_SYSTEM_CURSOR_WAITARROW: return XC_watch;
+        case SDL_SYSTEM_CURSOR_SIZENWSE: return XC_top_left_corner;
+        case SDL_SYSTEM_CURSOR_SIZENESW: return XC_top_right_corner;
+        case SDL_SYSTEM_CURSOR_SIZEWE: return XC_sb_h_double_arrow;
+        case SDL_SYSTEM_CURSOR_SIZENS: return XC_sb_v_double_arrow;
+        case SDL_SYSTEM_CURSOR_SIZEALL: return XC_fleur;
+        case SDL_SYSTEM_CURSOR_NO: return XC_pirate;
+        case SDL_SYSTEM_CURSOR_HAND: return XC_hand2;
+        case SDL_NUM_SYSTEM_CURSORS: break;  /* so the compiler might notice if an enum value is missing here. */
     }
 
-    cursor = SDL_calloc(1, sizeof(*cursor));
-    if (cursor) {
-        Display *dpy = GetDisplay();
-        Cursor x11_cursor = None;
+    SDL_assert(0);
+    return 0;
+}
+
+static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
+{
+    SDL_Cursor *cursor = NULL;
+    Display *dpy = GetDisplay();
+    Cursor x11_cursor = None;
 
 #ifdef SDL_VIDEO_DRIVER_X11_XCURSOR
-        SDL_assert(xcursorname != NULL);
-        if (SDL_X11_HAVE_XCURSOR) {
-            x11_cursor = X11_XcursorLibraryLoadCursor(dpy, xcursorname);
-        }
+    if (SDL_X11_HAVE_XCURSOR) {
+        x11_cursor = X11_XcursorLibraryLoadCursor(dpy, SDL_GetCSSCursorName(id, NULL));
+    }
 #endif
 
-        if (x11_cursor == None) {
-            x11_cursor = X11_XCreateFontCursor(dpy, shape);
-        }
+    if (x11_cursor == None) {
+        x11_cursor = X11_XCreateFontCursor(dpy, GetLegacySystemCursorShape(id));
+    }
 
-        cursor->driverdata = (void *)(uintptr_t)x11_cursor;
-    } else {
-        SDL_OutOfMemory();
+    if (x11_cursor != None) {
+        cursor = SDL_calloc(1, sizeof(*cursor));
+        if (!cursor) {
+            SDL_OutOfMemory();
+        } else {
+            cursor->driverdata = (void *)(uintptr_t)x11_cursor;
+        }
     }
 
     return cursor;