From a1998d106daf1ed1c30ff7a2dfb2a9c7c34d4040 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Aug 2024 20:58:41 -0700
Subject: [PATCH] Putting the simple back into Simple DirectMedia Layer
---
include/SDL3/SDL_keyboard.h | 11 ++---------
src/dynapi/SDL_dynapi_procs.h | 4 ++--
src/events/SDL_keymap.c | 6 ++++--
src/test/SDL_test_common.c | 2 +-
test/checkkeys.c | 2 +-
test/testautomation_keyboard.c | 34 +++++++++++++++-------------------
test/testime.c | 2 +-
7 files changed, 26 insertions(+), 35 deletions(-)
diff --git a/include/SDL3/SDL_keyboard.h b/include/SDL3/SDL_keyboard.h
index fa074d27d434c..d4f9b22cd9d95 100644
--- a/include/SDL3/SDL_keyboard.h
+++ b/include/SDL3/SDL_keyboard.h
@@ -286,9 +286,6 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *nam
* If the key doesn't have a name, this function returns an empty string ("").
*
* \param key the desired SDL_Keycode to query.
- * \param uppercase SDL_TRUE if the name should be the letter printed on the
- * key on the keyboard, which is usually uppercase, or
- * SDL_FALSE to return the name of the key unchanged.
* \returns a UTF-8 encoded string of the key name.
*
* \since This function is available since SDL 3.0.0.
@@ -297,16 +294,12 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *nam
* \sa SDL_GetKeyFromScancode
* \sa SDL_GetScancodeFromKey
*/
-extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase);
+extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key);
/**
* Get a key code from a human-readable name.
*
* \param name the human-readable key name.
- * \param uppercase SDL_TRUE if the name is the letter printed on the key on
- * the keyboard, which is usually uppercase, and this
- * function should return the unshifted version of the key,
- * or SDL_FALSE to return the key unchanged.
* \returns key code, or `SDLK_UNKNOWN` if the name wasn't recognized; call
* SDL_GetError() for more information.
*
@@ -316,7 +309,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key, SDL_boo
* \sa SDL_GetKeyName
* \sa SDL_GetScancodeFromName
*/
-extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name, SDL_bool uppercase);
+extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
/**
* Start accepting Unicode text input events in a window.
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 6cbded81cdf38..44d96651ae19b 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -365,9 +365,9 @@ SDL_DYNAPI_PROC(SDL_JoystickType,SDL_GetJoystickTypeForID,(SDL_JoystickID a),(a)
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendor,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendorForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetJoysticks,(int *a),(a),return)
-SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromName,(const char *a, SDL_bool b),(a, b),return)
+SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromName,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromScancode,(SDL_Scancode a, SDL_Keymod b, SDL_bool c),(a,b,c),return)
-SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a, SDL_bool b),(a,b),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyboardNameForID,(SDL_KeyboardID a),(a),return)
SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return)
diff --git a/src/events/SDL_keymap.c b/src/events/SDL_keymap.c
index de5a63312bc58..d69f3f156a599 100644
--- a/src/events/SDL_keymap.c
+++ b/src/events/SDL_keymap.c
@@ -981,8 +981,9 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
return SDL_SCANCODE_UNKNOWN;
}
-const char *SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase)
+const char *SDL_GetKeyName(SDL_Keycode key)
{
+ const SDL_bool uppercase = SDL_TRUE;
char name[8];
char *end;
@@ -1027,8 +1028,9 @@ const char *SDL_GetKeyName(SDL_Keycode key, SDL_bool uppercase)
}
}
-SDL_Keycode SDL_GetKeyFromName(const char *name, SDL_bool uppercase)
+SDL_Keycode SDL_GetKeyFromName(const char *name)
{
+ const SDL_bool uppercase = SDL_TRUE;
SDL_Keycode key;
/* Check input */
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 9d8c398990304..5f84b36495854 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -1717,7 +1717,7 @@ void SDLTest_PrintEvent(const SDL_Event *event)
event->key.windowID,
event->key.scancode,
SDL_GetScancodeName(event->key.scancode),
- event->key.key, SDL_GetKeyName(event->key.key, SDL_TRUE),
+ event->key.key, SDL_GetKeyName(event->key.key),
modstr);
break;
}
diff --git a/test/checkkeys.c b/test/checkkeys.c
index b10e7aaf721b8..33cb73b1ed100 100644
--- a/test/checkkeys.c
+++ b/test/checkkeys.c
@@ -202,7 +202,7 @@ static void PrintKey(SDL_KeyboardEvent *event)
event->raw,
event->scancode,
event->scancode == SDL_SCANCODE_UNKNOWN ? "UNKNOWN" : SDL_GetScancodeName(event->scancode),
- event->key, SDL_GetKeyName(event->key, SDL_TRUE));
+ event->key, SDL_GetKeyName(event->key));
} else {
print_string(&spot, &left,
"Unknown Key (raw 0x%.2x, scancode %d = %s) %s ",
diff --git a/test/testautomation_keyboard.c b/test/testautomation_keyboard.c
index 6a895f0b0f334..f5786e53b7e4b 100644
--- a/test/testautomation_keyboard.c
+++ b/test/testautomation_keyboard.c
@@ -59,41 +59,37 @@ static int keyboard_getKeyFromName(void *arg)
SDL_Keycode result;
/* Case where Key is known, 1 character input */
- result = SDL_GetKeyFromName("A", SDL_TRUE);
+ result = SDL_GetKeyFromName("A");
SDLTest_AssertPass("Call to SDL_GetKeyFromName('A', SDL_TRUE)");
SDLTest_AssertCheck(result == SDLK_A, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_A, result);
- result = SDL_GetKeyFromName("A", SDL_FALSE);
- SDLTest_AssertPass("Call to SDL_GetKeyFromName('A', SDL_FALSE)");
- SDLTest_AssertCheck(result == 'A', "Verify result from call, expected: %d, got: %" SDL_PRIu32, 'A', result);
-
/* Case where Key is known, 2 character input */
- result = SDL_GetKeyFromName("F1", SDL_TRUE);
+ result = SDL_GetKeyFromName("F1");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_F1, result);
/* Case where Key is known, 3 character input */
- result = SDL_GetKeyFromName("End", SDL_TRUE);
+ result = SDL_GetKeyFromName("End");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_END, result);
/* Case where Key is known, 4 character input */
- result = SDL_GetKeyFromName("Find", SDL_TRUE);
+ result = SDL_GetKeyFromName("Find");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_FIND, result);
/* Case where Key is known, multiple character input */
- result = SDL_GetKeyFromName("MediaStop", SDL_TRUE);
+ result = SDL_GetKeyFromName("MediaStop");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
SDLTest_AssertCheck(result == SDLK_MEDIA_STOP, "Verify result from call, expected: %d, got: %" SDL_PRIu32, SDLK_MEDIA_STOP, result);
/* Case where Key is unknown */
- result = SDL_GetKeyFromName("NotThere", SDL_TRUE);
+ result = SDL_GetKeyFromName("NotThere");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %d, got: %" SDL_PRIu32, SDLK_UNKNOWN, result);
/* Case where input is NULL/invalid */
- result = SDL_GetKeyFromName(NULL, SDL_TRUE);
+ result = SDL_GetKeyFromName(NULL);
SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %d, got: %" SDL_PRIu32, SDLK_UNKNOWN, result);
@@ -168,42 +164,42 @@ static int keyboard_getKeyName(void *arg)
/* Case where key has a 1 character name */
expected = "3";
- result = SDL_GetKeyName(SDLK_3, SDL_TRUE);
+ result = SDL_GetKeyName(SDLK_3);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 2 character name */
expected = "F1";
- result = SDL_GetKeyName(SDLK_F1, SDL_TRUE);
+ result = SDL_GetKeyName(SDLK_F1);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 3 character name */
expected = "Cut";
- result = SDL_GetKeyName(SDLK_CUT, SDL_TRUE);
+ result = SDL_GetKeyName(SDLK_CUT);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a 4 character name */
expected = "Down";
- result = SDL_GetKeyName(SDLK_DOWN, SDL_TRUE);
+ result = SDL_GetKeyName(SDLK_DOWN);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name */
expected = "MediaPlay";
- result = SDL_GetKeyName(SDLK_MEDIA_PLAY, SDL_TRUE);
+ result = SDL_GetKeyName(SDLK_MEDIA_PLAY);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
/* Case where key has a N character name with space */
expected = "Keypad MemStore";
- result = SDL_GetKeyName(SDLK_KP_MEMSTORE, SDL_TRUE);
+ result = SDL_GetKeyName(SDLK_KP_MEMSTORE);
SDLTest_AssertPass("Call to SDL_GetKeyName()");
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
@@ -250,7 +246,7 @@ static int keyboard_getKeyNameNegative(void *arg)
/* Unknown keycode */
keycode = SDLK_UNKNOWN;
- result = SDL_GetKeyName(keycode, SDL_TRUE);
+ result = SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%" SDL_PRIu32 "/unknown)", keycode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
@@ -261,7 +257,7 @@ static int keyboard_getKeyNameNegative(void *arg)
/* Negative keycode */
keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
- result = SDL_GetKeyName(keycode, SDL_TRUE);
+ result = SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%" SDL_PRIu32 "/negative)", keycode);
SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
diff --git a/test/testime.c b/test/testime.c
index 6be70a60ff63a..f6cc4f0368d18 100644
--- a/test/testime.c
+++ b/test/testime.c
@@ -1209,7 +1209,7 @@ int main(int argc, char *argv[])
event.key.scancode,
SDL_GetScancodeName(event.key.scancode),
SDL_static_cast(Uint32, event.key.key),
- SDL_GetKeyName(event.key.key, SDL_TRUE));
+ SDL_GetKeyName(event.key.key));
break;
}
case SDL_EVENT_TEXT_INPUT: {