mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 11:28:15 +00:00
x11: Cleaned up system cursor code to match previous Wayland change.
(cherry picked from commit df00a7dd4c
)
This commit is contained in:
@@ -220,75 +220,53 @@ static SDL_Cursor *X11_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
|||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int GetLegacySystemCursorShape(SDL_SystemCursor id)
|
||||||
|
{
|
||||||
|
switch (id) {
|
||||||
|
/* 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. */
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_assert(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
|
static SDL_Cursor *X11_CreateSystemCursor(SDL_SystemCursor id)
|
||||||
{
|
{
|
||||||
SDL_Cursor *cursor = NULL;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor = SDL_calloc(1, sizeof(*cursor));
|
|
||||||
if (cursor) {
|
|
||||||
Display *dpy = GetDisplay();
|
Display *dpy = GetDisplay();
|
||||||
Cursor x11_cursor = None;
|
Cursor x11_cursor = None;
|
||||||
|
|
||||||
#ifdef SDL_VIDEO_DRIVER_X11_XCURSOR
|
#ifdef SDL_VIDEO_DRIVER_X11_XCURSOR
|
||||||
SDL_assert(xcursorname != NULL);
|
|
||||||
if (SDL_X11_HAVE_XCURSOR) {
|
if (SDL_X11_HAVE_XCURSOR) {
|
||||||
x11_cursor = X11_XcursorLibraryLoadCursor(dpy, xcursorname);
|
x11_cursor = X11_XcursorLibraryLoadCursor(dpy, SDL_GetCSSCursorName(id, NULL));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (x11_cursor == None) {
|
if (x11_cursor == None) {
|
||||||
x11_cursor = X11_XCreateFontCursor(dpy, shape);
|
x11_cursor = X11_XCreateFontCursor(dpy, GetLegacySystemCursorShape(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor->driverdata = (void *)(uintptr_t)x11_cursor;
|
if (x11_cursor != None) {
|
||||||
} else {
|
cursor = SDL_calloc(1, sizeof(*cursor));
|
||||||
|
if (!cursor) {
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
|
} else {
|
||||||
|
cursor->driverdata = (void *)(uintptr_t)x11_cursor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cursor;
|
return cursor;
|
||||||
|
Reference in New Issue
Block a user