x11: Use XcursorLibraryLoadCursor to load system cursors when available.

Apparently this is necessary on the latest Gnome to get properly themed
cursors, vs ancient X11 standard cursors, as Gnome has dropped the old
theme names that XCreateFontCursor eventually expected to find.

Fixes #8939.
This commit is contained in:
Ryan C. Gordon
2024-02-16 02:06:32 -05:00
parent d451fcd7a7
commit cb9565354c
2 changed files with 36 additions and 4 deletions

View File

@@ -214,8 +214,9 @@ static SDL_Cursor *X11_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id) static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
{ {
SDL_Cursor *cursor; SDL_Cursor *cursor = NULL;
unsigned int shape; unsigned int shape = 0;
const char *xcursorname = NULL;
switch (id) { switch (id) {
default: default:
@@ -225,71 +226,101 @@ static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
/* http://tronche.com/gui/x/xlib/appendix/b/ */ /* http://tronche.com/gui/x/xlib/appendix/b/ */
case SDL_SYSTEM_CURSOR_ARROW: case SDL_SYSTEM_CURSOR_ARROW:
shape = XC_left_ptr; shape = XC_left_ptr;
xcursorname = "default";
break; break;
case SDL_SYSTEM_CURSOR_IBEAM: case SDL_SYSTEM_CURSOR_IBEAM:
shape = XC_xterm; shape = XC_xterm;
xcursorname = "text";
break; break;
case SDL_SYSTEM_CURSOR_WAIT: case SDL_SYSTEM_CURSOR_WAIT:
shape = XC_watch; shape = XC_watch;
xcursorname = "wait";
break; break;
case SDL_SYSTEM_CURSOR_CROSSHAIR: case SDL_SYSTEM_CURSOR_CROSSHAIR:
shape = XC_tcross; shape = XC_tcross;
xcursorname = "crosshair";
break; break;
case SDL_SYSTEM_CURSOR_WAITARROW: case SDL_SYSTEM_CURSOR_WAITARROW:
shape = XC_watch; shape = XC_watch;
xcursorname = "progress";
break; break;
case SDL_SYSTEM_CURSOR_SIZENWSE: case SDL_SYSTEM_CURSOR_SIZENWSE:
shape = XC_top_left_corner; shape = XC_top_left_corner;
xcursorname = "nwse-resize";
break; break;
case SDL_SYSTEM_CURSOR_SIZENESW: case SDL_SYSTEM_CURSOR_SIZENESW:
shape = XC_top_right_corner; shape = XC_top_right_corner;
xcursorname = "nesw-resize";
break; break;
case SDL_SYSTEM_CURSOR_SIZEWE: case SDL_SYSTEM_CURSOR_SIZEWE:
shape = XC_sb_h_double_arrow; shape = XC_sb_h_double_arrow;
xcursorname = "ew-resize";
break; break;
case SDL_SYSTEM_CURSOR_SIZENS: case SDL_SYSTEM_CURSOR_SIZENS:
shape = XC_sb_v_double_arrow; shape = XC_sb_v_double_arrow;
xcursorname = "ns-resize";
break; break;
case SDL_SYSTEM_CURSOR_SIZEALL: case SDL_SYSTEM_CURSOR_SIZEALL:
shape = XC_fleur; shape = XC_fleur;
xcursorname = "move";
break; break;
case SDL_SYSTEM_CURSOR_NO: case SDL_SYSTEM_CURSOR_NO:
shape = XC_pirate; shape = XC_pirate;
xcursorname = "not-allowed";
break; break;
case SDL_SYSTEM_CURSOR_HAND: case SDL_SYSTEM_CURSOR_HAND:
shape = XC_hand2; shape = XC_hand2;
xcursorname = "pointer";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT: case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT:
shape = XC_top_left_corner; shape = XC_top_left_corner;
xcursorname = "nw-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_TOP: case SDL_SYSTEM_CURSOR_WINDOW_TOP:
shape = XC_top_side; shape = XC_top_side;
xcursorname = "n-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT: case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT:
shape = XC_top_right_corner; shape = XC_top_right_corner;
xcursorname = "ne-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_RIGHT: case SDL_SYSTEM_CURSOR_WINDOW_RIGHT:
shape = XC_right_side; shape = XC_right_side;
xcursorname = "e-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT: case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT:
shape = XC_bottom_right_corner; shape = XC_bottom_right_corner;
xcursorname = "se-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM: case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM:
shape = XC_bottom_side; shape = XC_bottom_side;
xcursorname = "s-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT: case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT:
shape = XC_bottom_left_corner; shape = XC_bottom_left_corner;
xcursorname = "sw-resize";
break; break;
case SDL_SYSTEM_CURSOR_WINDOW_LEFT: case SDL_SYSTEM_CURSOR_WINDOW_LEFT:
shape = XC_left_side; shape = XC_left_side;
xcursorname = "w-resize";
break; break;
} }
cursor = SDL_calloc(1, sizeof(*cursor)); cursor = SDL_calloc(1, sizeof(*cursor));
if (cursor) { if (cursor) {
Cursor x11_cursor; Display *dpy = GetDisplay();
Cursor x11_cursor = None;
x11_cursor = X11_XCreateFontCursor(GetDisplay(), shape); #ifdef SDL_VIDEO_DRIVER_X11_XCURSOR
SDL_assert(xcursorname != NULL);
if (SDL_X11_HAVE_XCURSOR) {
x11_cursor = X11_XcursorLibraryLoadCursor(dpy, xcursorname);
}
#endif
if (x11_cursor == None) {
x11_cursor = X11_XCreateFontCursor(dpy, shape);
}
cursor->driverdata = (void *)(uintptr_t)x11_cursor; cursor->driverdata = (void *)(uintptr_t)x11_cursor;
} }

View File

@@ -262,6 +262,7 @@ SDL_X11_MODULE(XCURSOR)
SDL_X11_SYM(XcursorImage*,XcursorImageCreate,(int a,int b),(a,b),return) SDL_X11_SYM(XcursorImage*,XcursorImageCreate,(int a,int b),(a,b),return)
SDL_X11_SYM(void,XcursorImageDestroy,(XcursorImage *a),(a),) SDL_X11_SYM(void,XcursorImageDestroy,(XcursorImage *a),(a),)
SDL_X11_SYM(Cursor,XcursorImageLoadCursor,(Display *a,const XcursorImage *b),(a,b),return) SDL_X11_SYM(Cursor,XcursorImageLoadCursor,(Display *a,const XcursorImage *b),(a,b),return)
SDL_X11_SYM(Cursor,XcursorLibraryLoadCursor,(Display *a, const char *b),(a,b),return)
#endif #endif
/* Xdbe support */ /* Xdbe support */