Simple Directmedia Layer

hint for which system cursor to use as default

Co-Authored-By: Sam Lantinga <slouken@libsdl.org>

authored by

expikr
Sam Lantinga
and committed by
Sam Lantinga
d55e6dfc 3c13bae6

+54 -34
+11
include/SDL3/SDL_hints.h
··· 2402 2402 #define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME "SDL_MOUSE_DOUBLE_CLICK_TIME" 2403 2403 2404 2404 /** 2405 + * A variable setting which system cursor to use as the default cursor. 2406 + * This should be an integer corresponding to the SDL_SystemCursor enum. 2407 + * The default value is zero (SDL_SYSTEM_CURSOR_DEFAULT). 2408 + * 2409 + * This hint needs to be set before SDL_Init(). 2410 + * 2411 + * \since This hint is available since SDL 3.1.3. 2412 + */ 2413 + #define SDL_HINT_MOUSE_DEFAULT_SYSTEM_CURSOR "SDL_MOUSE_DEFAULT_SYSTEM_CURSOR" 2414 + 2415 + /** 2405 2416 * A variable controlling whether warping a hidden mouse cursor will activate 2406 2417 * relative mouse mode. 2407 2418 *
+13
src/events/SDL_mouse.c
··· 440 440 } 441 441 } 442 442 443 + SDL_SystemCursor SDL_GetDefaultSystemCursor(void) 444 + { 445 + SDL_SystemCursor id = SDL_SYSTEM_CURSOR_DEFAULT; 446 + const char *value = SDL_GetHint(SDL_HINT_MOUSE_DEFAULT_SYSTEM_CURSOR); 447 + if (value) { 448 + int index = SDL_atoi(value); 449 + if (0 <= index && index < (int)SDL_SYSTEM_CURSOR_COUNT) { 450 + id = (SDL_SystemCursor)index; 451 + } 452 + } 453 + return id; 454 + } 455 + 443 456 SDL_Mouse *SDL_GetMouse(void) 444 457 { 445 458 return &SDL_mouse;
+3
src/events/SDL_mouse_c.h
··· 158 158 // Set the default mouse cursor 159 159 extern void SDL_SetDefaultCursor(SDL_Cursor *cursor); 160 160 161 + // Get the preferred default system cursor 162 + extern SDL_SystemCursor SDL_GetDefaultSystemCursor(void); 163 + 161 164 // Set the mouse focus window 162 165 extern void SDL_SetMouseFocus(SDL_Window *window); 163 166
+2 -1
src/video/android/SDL_androidmouse.c
··· 75 75 76 76 static SDL_Cursor *Android_CreateDefaultCursor(void) 77 77 { 78 - return Android_WrapCursor(0, SDL_SYSTEM_CURSOR_DEFAULT); 78 + SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 79 + return Android_WrapCursor(0, id); 79 80 } 80 81 81 82 static SDL_Cursor *Android_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
+6 -19
src/video/cocoa/SDL_cocoamouse.m
··· 63 63 } 64 64 @end 65 65 66 - static SDL_Cursor *Cocoa_CreateDefaultCursor(void) 67 - { 68 - @autoreleasepool { 69 - NSCursor *nscursor; 70 - SDL_Cursor *cursor = NULL; 71 - 72 - nscursor = [NSCursor arrowCursor]; 73 - 74 - if (nscursor) { 75 - cursor = SDL_calloc(1, sizeof(*cursor)); 76 - if (cursor) { 77 - cursor->internal = (void *)CFBridgingRetain(nscursor); 78 - } 79 - } 80 - 81 - return cursor; 82 - } 83 - } 84 - 85 66 static SDL_Cursor *Cocoa_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) 86 67 { 87 68 @autoreleasepool { ··· 227 208 228 209 return cursor; 229 210 } 211 + } 212 + 213 + static SDL_Cursor *Cocoa_CreateDefaultCursor(void) 214 + { 215 + SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 216 + return Cocoa_CreateSystemCursor(id); 230 217 } 231 218 232 219 static void Cocoa_FreeCursor(SDL_Cursor *cursor)
+3 -1
src/video/emscripten/SDL_emscriptenmouse.c
··· 62 62 63 63 static SDL_Cursor *Emscripten_CreateDefaultCursor(void) 64 64 { 65 - return Emscripten_CreateCursorFromString("default", false); 65 + SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 66 + const char *cursor_name = SDL_GetCSSCursorName(id, NULL); 67 + return Emscripten_CreateCursorFromString(cursor_name, false); 66 68 } 67 69 68 70 EM_JS_DEPS(sdlmouse, "$stringToUTF8,$UTF8ToString");
+2 -1
src/video/haiku/SDL_bvideo.cc
··· 180 180 181 181 static SDL_Cursor * HAIKU_CreateDefaultCursor() 182 182 { 183 - return HAIKU_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT); 183 + SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 184 + return HAIKU_CreateSystemCursor(id); 184 185 } 185 186 186 187 static void HAIKU_FreeCursor(SDL_Cursor * cursor)
+2 -1
src/video/wayland/SDL_waylandmouse.c
··· 592 592 593 593 static SDL_Cursor *Wayland_CreateDefaultCursor(void) 594 594 { 595 - return Wayland_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT); 595 + SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 596 + return Wayland_CreateSystemCursor(id); 596 597 } 597 598 598 599 static void Wayland_FreeCursorData(SDL_CursorData *d)
+6 -5
src/video/windows/SDL_windowsmouse.c
··· 84 84 return cursor; 85 85 } 86 86 87 - static SDL_Cursor *WIN_CreateDefaultCursor(void) 88 - { 89 - return WIN_CreateCursorAndData(LoadCursor(NULL, IDC_ARROW)); 90 - } 91 - 92 87 static bool IsMonochromeSurface(SDL_Surface *surface) 93 88 { 94 89 int x, y; ··· 340 335 break; 341 336 } 342 337 return WIN_CreateCursorAndData(LoadCursor(NULL, name)); 338 + } 339 + 340 + static SDL_Cursor *WIN_CreateDefaultCursor(void) 341 + { 342 + SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 343 + return WIN_CreateSystemCursor(id); 343 344 } 344 345 345 346 static void WIN_FreeCursor(SDL_Cursor *cursor)
+6 -6
src/video/x11/SDL_x11mouse.c
··· 89 89 return cursor; 90 90 } 91 91 92 - static SDL_Cursor *X11_CreateDefaultCursor(void) 93 - { 94 - // None is used to indicate the default cursor 95 - return X11_CreateCursorAndData(None); 96 - } 97 - 98 92 #ifdef SDL_VIDEO_DRIVER_X11_XCURSOR 99 93 static Cursor X11_CreateXCursorCursor(SDL_Surface *surface, int hot_x, int hot_y) 100 94 { ··· 277 271 } 278 272 279 273 return cursor; 274 + } 275 + 276 + static SDL_Cursor *X11_CreateDefaultCursor(void) 277 + { 278 + SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 279 + return X11_CreateSystemCursor(id); 280 280 } 281 281 282 282 static void X11_FreeCursor(SDL_Cursor *cursor)