Removed keymaps from the API
This is unnecessary complication for applications. We can always add it again later if we find that it's really useful.
This commit is contained in:
@@ -172,48 +172,6 @@ static void print_modifiers(char **text, size_t *maxlen, SDL_Keymod mod)
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintKeymap(void)
|
||||
{
|
||||
SDL_Keymod mods[] = {
|
||||
SDL_KMOD_NONE,
|
||||
SDL_KMOD_SHIFT,
|
||||
SDL_KMOD_CAPS,
|
||||
(SDL_KMOD_SHIFT | SDL_KMOD_CAPS),
|
||||
SDL_KMOD_ALT,
|
||||
(SDL_KMOD_ALT | SDL_KMOD_SHIFT),
|
||||
(SDL_KMOD_ALT | SDL_KMOD_CAPS),
|
||||
(SDL_KMOD_ALT | SDL_KMOD_SHIFT | SDL_KMOD_CAPS),
|
||||
SDL_KMOD_MODE,
|
||||
(SDL_KMOD_MODE | SDL_KMOD_SHIFT),
|
||||
(SDL_KMOD_MODE | SDL_KMOD_CAPS),
|
||||
(SDL_KMOD_MODE | SDL_KMOD_SHIFT | SDL_KMOD_CAPS)
|
||||
};
|
||||
int i, m;
|
||||
SDL_Keymap *keymap = SDL_GetCurrentKeymap();
|
||||
|
||||
SDL_Log("Differences from the default keymap:\n");
|
||||
for (m = 0; m < SDL_arraysize(mods); ++m) {
|
||||
for (i = 0; i < SDL_NUM_SCANCODES; ++i) {
|
||||
SDL_Keycode key = SDL_GetKeymapKeycode(keymap, (SDL_Scancode)i, mods[m]);
|
||||
SDL_Keycode default_key = SDL_GetKeymapKeycode(NULL, (SDL_Scancode)i, mods[m]);
|
||||
if (key != default_key) {
|
||||
char message[512];
|
||||
char *spot;
|
||||
size_t left;
|
||||
|
||||
spot = message;
|
||||
left = sizeof(message);
|
||||
|
||||
print_string(&spot, &left, "Scancode %s (%d)", SDL_GetScancodeName((SDL_Scancode)i), i);
|
||||
print_modifiers(&spot, &left, mods[m]);
|
||||
print_string(&spot, &left, ": %s 0x%x (default: %s 0x%x)", SDL_GetKeyName(key, SDL_FALSE), key, SDL_GetKeyName(default_key, SDL_FALSE), default_key);
|
||||
SDL_Log("%s", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_ReleaseKeymap(keymap);
|
||||
}
|
||||
|
||||
static void PrintModifierState(void)
|
||||
{
|
||||
char message[512];
|
||||
@@ -434,7 +392,6 @@ static void loop(void)
|
||||
break;
|
||||
case SDL_EVENT_KEYMAP_CHANGED:
|
||||
SDL_Log("Keymap changed!\n");
|
||||
PrintKeymap();
|
||||
break;
|
||||
case SDL_EVENT_QUIT:
|
||||
done = 1;
|
||||
@@ -548,7 +505,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Print initial state */
|
||||
SDL_PumpEvents();
|
||||
PrintKeymap();
|
||||
PrintModifierState();
|
||||
|
||||
/* Watch keystrokes */
|
||||
|
||||
@@ -128,12 +128,12 @@ static int keyboard_getKeyFromScancode(void *arg)
|
||||
SDL_Keycode result;
|
||||
|
||||
/* Case where input is valid */
|
||||
result = SDL_GetKeyFromScancode(SDL_SCANCODE_A, SDL_KMOD_NONE);
|
||||
result = SDL_GetKeyFromScancode(SDL_SCANCODE_A, SDL_KMOD_NONE, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
|
||||
SDLTest_AssertCheck(result == SDLK_A, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_A, result);
|
||||
|
||||
/* Case where input is zero */
|
||||
result = SDL_GetKeyFromScancode(SDL_SCANCODE_UNKNOWN, SDL_KMOD_NONE);
|
||||
result = SDL_GetKeyFromScancode(SDL_SCANCODE_UNKNOWN, SDL_KMOD_NONE, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %d, got: %" SDL_PRIu32, SDLK_UNKNOWN, result);
|
||||
|
||||
@@ -142,13 +142,13 @@ static int keyboard_getKeyFromScancode(void *arg)
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* Case where input is invalid (too small) */
|
||||
result = SDL_GetKeyFromScancode((SDL_Scancode)-999, SDL_KMOD_NONE);
|
||||
result = SDL_GetKeyFromScancode((SDL_Scancode)-999, SDL_KMOD_NONE, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %d, got: %" SDL_PRIu32, SDLK_UNKNOWN, result);
|
||||
checkInvalidScancodeError();
|
||||
|
||||
/* Case where input is invalid (too big) */
|
||||
result = SDL_GetKeyFromScancode((SDL_Scancode)999, SDL_KMOD_NONE);
|
||||
result = SDL_GetKeyFromScancode((SDL_Scancode)999, SDL_KMOD_NONE, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
|
||||
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %d, got: %" SDL_PRIu32, SDLK_UNKNOWN, result);
|
||||
checkInvalidScancodeError();
|
||||
@@ -497,32 +497,6 @@ static int keyboard_setTextInputAreaNegative(void *arg)
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check call to SDL_getKeymapScancode
|
||||
*
|
||||
* \sa SDL_getKeymapScancode
|
||||
* \sa SDL_Keycode
|
||||
*/
|
||||
static int keyboard_getKeymapScancode(void *arg)
|
||||
{
|
||||
SDL_Scancode scancode;
|
||||
SDL_Keymod modstate;
|
||||
|
||||
/* Regular key */
|
||||
scancode = SDL_GetKeymapScancode(NULL, SDLK_4, &modstate);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeymapScancode(SDLK_4)");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetDefaultScancodeFromKey, expected: %d, got: %d", SDL_SCANCODE_4, scancode);
|
||||
SDLTest_AssertCheck(modstate == SDL_KMOD_NONE, "Validate modstate from SDL_GetDefaultScancodeFromKey, expected: %d, got: %d", SDL_KMOD_NONE, modstate);
|
||||
|
||||
/* Virtual key */
|
||||
scancode = SDL_GetKeymapScancode(NULL, SDLK_PLUS, &modstate);
|
||||
SDLTest_AssertPass("Call to SDL_GetKeymapScancode(SDLK_PLUS)");
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_EQUALS, "Validate return value from SDL_GetDefaultScancodeFromKey, expected: %d, got: %d", SDL_SCANCODE_EQUALS, scancode);
|
||||
SDLTest_AssertCheck(modstate == SDL_KMOD_SHIFT, "Validate modstate from SDL_GetDefaultScancodeFromKey, expected: %d, got: %d", SDL_KMOD_SHIFT, modstate);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check call to SDL_GetScancodeFromName
|
||||
*
|
||||
@@ -641,67 +615,74 @@ static int keyboard_getScancodeFromNameNegative(void *arg)
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Keyboard test cases */
|
||||
static const SDLTest_TestCaseReference keyboardTest1 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetKeyboardState = {
|
||||
(SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest2 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetKeyboardFocus = {
|
||||
(SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest3 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetKeyFromName = {
|
||||
(SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest4 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetKeyFromScancode = {
|
||||
(SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest5 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetKeyName = {
|
||||
(SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest6 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetSetModState = {
|
||||
(SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest7 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestStartStopTextInput = {
|
||||
(SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest8 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestSetTextInputArea = {
|
||||
(SDLTest_TestCaseFp)keyboard_setTextInputArea, "keyboard_setTextInputArea", "Check call to SDL_SetTextInputArea", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest9 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestSetTextInputAreaNegative = {
|
||||
(SDLTest_TestCaseFp)keyboard_setTextInputAreaNegative, "keyboard_setTextInputAreaNegative", "Check call to SDL_SetTextInputArea with invalid data", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest10 = {
|
||||
(SDLTest_TestCaseFp)keyboard_getKeymapScancode, "keyboard_getKeymapScancode", "Check call to SDL_getKeymapScancode", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest11 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetScancodeFromName = {
|
||||
(SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest12 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetScancodeFromNameNegative = {
|
||||
(SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest13 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetKeyNameNegative = {
|
||||
(SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest14 = {
|
||||
static const SDLTest_TestCaseReference keyboardTestGetScancodeNameNegative = {
|
||||
(SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Keyboard test cases */
|
||||
static const SDLTest_TestCaseReference *keyboardTests[] = {
|
||||
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6,
|
||||
&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12,
|
||||
&keyboardTest13, &keyboardTest14, NULL
|
||||
&keyboardTestGetKeyboardState,
|
||||
&keyboardTestGetKeyboardFocus,
|
||||
&keyboardTestGetKeyFromName,
|
||||
&keyboardTestGetKeyFromScancode,
|
||||
&keyboardTestGetKeyName,
|
||||
&keyboardTestGetSetModState,
|
||||
&keyboardTestStartStopTextInput,
|
||||
&keyboardTestSetTextInputArea,
|
||||
&keyboardTestSetTextInputAreaNegative,
|
||||
&keyboardTestGetScancodeFromName,
|
||||
&keyboardTestGetScancodeFromNameNegative,
|
||||
&keyboardTestGetKeyNameNegative,
|
||||
&keyboardTestGetScancodeNameNegative,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Keyboard test suite (global) */
|
||||
|
||||
Reference in New Issue
Block a user