From 05fb91c7b4cd3fb3b2c17987b89d5741c7e7c6fd Mon Sep 17 00:00:00 2001 From: Dragon-Baroque <74261498+Dragon-Baroque@users.noreply.github.com> Date: Tue, 21 May 2024 22:19:16 +0200 Subject: [PATCH] TESTWM : Option and Keyboard action to ShowCursor and HideCursor In include/SDL3/SDL_test_common.h Add flag hide_cursor In src/test/SDL_test_common.c Handle option --hide-cursor to SDL_HideCursor Handle Ctrl-h toggle to SDL_HideCursor and SDL_ShowCursor --- include/SDL3/SDL_test_common.h | 1 + src/test/SDL_test_common.c | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/SDL3/SDL_test_common.h b/include/SDL3/SDL_test_common.h index 3c502238b1..fd5f71d45d 100644 --- a/include/SDL3/SDL_test_common.h +++ b/include/SDL3/SDL_test_common.h @@ -127,6 +127,7 @@ typedef struct /* Mouse info */ SDL_Rect confine; + SDL_bool hide_cursor; } SDLTest_CommonState; diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 9974ad6a98..357796bdf2 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -590,6 +590,10 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index) state->window_flags |= SDL_WINDOW_UTILITY; return 1; } + if (SDL_strcasecmp(argv[index], "--hide-cursor") == 0) { + state->hide_cursor = SDL_TRUE; + return 1; + } } if (state->flags & SDL_INIT_AUDIO) { @@ -1400,6 +1404,9 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) SDL_ShowWindow(state->windows[i]); } + if (state->hide_cursor) { + SDL_HideCursor(); + } } if (state->flags & SDL_INIT_AUDIO) { @@ -2181,6 +2188,16 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event } } break; + case SDLK_h: + if (withControl) { + /* Ctrl-H changes cursor visibility. */ + if (SDL_CursorVisible()) { + SDL_HideCursor(); + } else { + SDL_ShowCursor(); + } + } + break; case SDLK_c: if (withAlt) { /* Alt-C copy awesome text to the primary selection! */ @@ -2318,7 +2335,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event if (window) { SDL_WindowFlags flags = SDL_GetWindowFlags(window); if (!(flags & SDL_WINDOW_FULLSCREEN) || - !SDL_GetWindowFullscreenMode(window)) { + !SDL_GetWindowFullscreenMode(window)) { SDL_SetWindowFullscreenMode(window, &state->fullscreen_mode); SDL_SetWindowFullscreen(window, SDL_TRUE); } else { @@ -2331,7 +2348,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event if (window) { SDL_WindowFlags flags = SDL_GetWindowFlags(window); if (!(flags & SDL_WINDOW_FULLSCREEN) || - SDL_GetWindowFullscreenMode(window)) { + SDL_GetWindowFullscreenMode(window)) { SDL_SetWindowFullscreenMode(window, NULL); SDL_SetWindowFullscreen(window, SDL_TRUE); } else {