Tests: Refactor key modifier checking.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 72b73e3..690a076 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -1293,7 +1293,11 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
break;
}
break;
- case SDL_KEYDOWN:
+ case SDL_KEYDOWN: {
+ SDL_bool withControl = !!(event->key.keysym.mod & KMOD_CTRL);
+ SDL_bool withShift = !!(event->key.keysym.mod & KMOD_SHIFT);
+ SDL_bool withAlt = !!(event->key.keysym.mod & KMOD_ALT);
+
switch (event->key.keysym.sym) {
/* Add hotkeys here */
case SDLK_PRINTSCREEN: {
@@ -1308,7 +1312,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_EQUALS:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-+ double the size of the window */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1319,7 +1323,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_MINUS:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-- half the size of the window */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1330,12 +1334,12 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_c:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-C copy awesome text! */
SDL_SetClipboardText("SDL rocks!\nYou know it!");
printf("Copied text to clipboard\n");
}
- if (event->key.keysym.mod & KMOD_ALT) {
+ if (withAlt) {
/* Alt-C toggle a render clip rectangle */
for (i = 0; i < state->num_windows; ++i) {
int w, h;
@@ -1357,7 +1361,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_v:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-V paste awesome text! */
char *text = SDL_GetClipboardText();
if (*text) {
@@ -1369,7 +1373,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_g:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-G toggle grab */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1378,7 +1382,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_m:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-M maximize */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1392,13 +1396,13 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_r:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-R toggle mouse relative mode */
SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE);
}
break;
case SDLK_z:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-Z minimize */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1407,7 +1411,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_RETURN:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-Enter toggle fullscreen */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1418,7 +1422,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
}
}
- } else if (event->key.keysym.mod & KMOD_ALT) {
+ } else if (withAlt) {
/* Alt-Enter toggle fullscreen desktop */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1432,7 +1436,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_b:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
/* Ctrl-B toggle window border */
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
if (window) {
@@ -1443,18 +1447,18 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
}
break;
case SDLK_0:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
}
break;
case SDLK_1:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
FullscreenTo(0, event->key.windowID);
}
break;
case SDLK_2:
- if (event->key.keysym.mod & KMOD_CTRL) {
+ if (withControl) {
FullscreenTo(1, event->key.windowID);
}
break;
@@ -1474,6 +1478,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
break;
}
break;
+ }
case SDL_QUIT:
*done = 1;
break;