From ae771d4710c55e24a6d33eeffed7b6c730f563ba Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 5 Jul 2023 01:09:28 -0700 Subject: [PATCH] Added test shortcuts Alt-C and Alt-V to test the primary selection functionality --- src/test/SDL_test_common.c | 55 +++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index aad6646c6..d53f0fef2 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -2188,7 +2188,12 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done } break; case SDLK_c: - if (withControl) { + if (withAlt) { + /* Alt-C copy awesome text to the primary selection! */ + SDL_SetPrimarySelectionText("SDL rocks!\nYou know it!"); + SDL_Log("Copied text to primary selection\n"); + + } else if (withControl) { if (withShift) { /* Ctrl-Shift-C copy screenshot! */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); @@ -2206,37 +2211,19 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done } break; } - if (withAlt) { - /* Alt-C toggle a render clip rectangle */ - for (i = 0; i < state->num_windows; ++i) { - int w, h; - if (state->renderers[i]) { - SDL_Rect clip; - SDL_GetWindowSize(state->windows[i], &w, &h); - SDL_GetRenderClipRect(state->renderers[i], &clip); - if (SDL_RectEmpty(&clip)) { - clip.x = w / 4; - clip.y = h / 4; - clip.w = w / 2; - clip.h = h / 2; - SDL_SetRenderClipRect(state->renderers[i], &clip); - } else { - SDL_SetRenderClipRect(state->renderers[i], NULL); - } - } - } - } - if (withShift) { - SDL_Window *current_win = SDL_GetKeyboardFocus(); - if (current_win) { - const SDL_bool shouldCapture = !(SDL_GetWindowFlags(current_win) & SDL_WINDOW_MOUSE_CAPTURE); - const int rc = SDL_CaptureMouse(shouldCapture); - SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed"); - } - } break; case SDLK_v: - if (withControl) { + if (withAlt) { + /* Alt-V paste awesome text from the primary selection! */ + char *text = SDL_GetPrimarySelectionText(); + if (*text) { + SDL_Log("Primary selection: %s\n", text); + } else { + SDL_Log("Primary selection is empty\n"); + } + SDL_free(text); + + } else if (withControl) { if (withShift) { /* Ctrl-Shift-V paste screenshot! */ SDLTest_PasteScreenShot(); @@ -2292,6 +2279,14 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done } } } + if (withShift) { + SDL_Window *current_win = SDL_GetKeyboardFocus(); + if (current_win) { + const SDL_bool shouldCapture = !(SDL_GetWindowFlags(current_win) & SDL_WINDOW_MOUSE_CAPTURE); + const int rc = SDL_CaptureMouse(shouldCapture); + SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed"); + } + } break; case SDLK_r: if (withControl) {