mirror of https://github.com/libsdl-org/SDL
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:
parent
1966472f73
commit
a13c993e40
|
@ -185,103 +185,22 @@ extern SDL_DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
|
|||
extern SDL_DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
|
||||
|
||||
/**
|
||||
* A keymap is a mapping from scancode and modifier state to keycode.
|
||||
* Get the key code corresponding to the given scancode according to the
|
||||
* current keyboard layout.
|
||||
*
|
||||
* \sa SDL_GetCurrentKeymap
|
||||
* \sa SDL_GetKeymapKeycode
|
||||
* \sa SDL_GetKeymapScancode
|
||||
* \sa SDL_ReleaseKeymap
|
||||
*/
|
||||
typedef struct SDL_Keymap SDL_Keymap;
|
||||
|
||||
/**
|
||||
* Get a reference to the current keyboard layout.
|
||||
* If you want to get the keycode as it would be delivered in key events, including options specified in SDL_HINT_KEYCODE_OPTIONS, then you should pass `key_event` as SDL_TRUE. Otherwise this function simply translates the scancode based on the given modifier state.
|
||||
*
|
||||
* You should release the reference to the keymap with SDL_ReleaseKeymap()
|
||||
* when you're done with it.
|
||||
*
|
||||
* \returns the current keymap, or NULL if the default US-QWERTY keymap is
|
||||
* being used.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_GetKeymapKeycode
|
||||
* \sa SDL_GetKeymapScancode
|
||||
* \sa SDL_ReleaseKeymap
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_Keymap * SDLCALL SDL_GetCurrentKeymap(void);
|
||||
|
||||
/**
|
||||
* Get the key code corresponding to the given scancode and modifier state
|
||||
* using the provided keymap.
|
||||
*
|
||||
* Note that this is not the same as the input that would be generated by
|
||||
* pressing this key. There are many factors involved, such as dead key
|
||||
* composition, input method editors, etc. If you're looking for a way to get
|
||||
* text input, you should handle SDL_EVENT_TEXT_INPUT.
|
||||
*
|
||||
* \param keymap the SDL_Keymap to query, or NULL for the default keymap.
|
||||
* \param scancode the SDL_Scancode to translate.
|
||||
* \param scancode the desired SDL_Scancode to query.
|
||||
* \param modstate the modifier state to use when translating the scancode to
|
||||
* a keycode.
|
||||
* \param key_event SDL_TRUE if the keycode will be used in key events.
|
||||
* \returns the SDL_Keycode that corresponds to the given SDL_Scancode.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_GetCurrentKeymap
|
||||
* \sa SDL_GetKeymapScancode
|
||||
* \sa SDL_GetKeyName
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeymapKeycode(SDL_Keymap *keymap, SDL_Scancode scancode, SDL_Keymod modstate);
|
||||
|
||||
/**
|
||||
* Get the scancode and modifier state corresponding to the given key code
|
||||
* using the provided keymap.
|
||||
*
|
||||
* Note that there may be multiple scancode+modifier states that can generate
|
||||
* this keycode, this will just return the first one found.
|
||||
*
|
||||
* \param keymap the SDL_Keymap to query, or NULL for the default keymap.
|
||||
* \param keycode the SDL_Keycode to translate.
|
||||
* \param modstate a pointer to the modifier state that would be used when the
|
||||
* scancode generates this key, may be NULL.
|
||||
* \returns the SDL_Scancode that corresponds to the given SDL_Keycode.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_GetCurrentKeymap
|
||||
* \sa SDL_GetKeymapKeycode
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetKeymapScancode(SDL_Keymap *keymap, SDL_Keycode keycode, SDL_Keymod *modstate);
|
||||
|
||||
/**
|
||||
* Release a reference to the current keyboard layout.
|
||||
*
|
||||
* \param keymap the SDL_Keymap to release, may be NULL.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_GetCurrentKeymap
|
||||
*/
|
||||
extern SDL_DECLSPEC void SDLCALL SDL_ReleaseKeymap(SDL_Keymap *keymap);
|
||||
|
||||
/**
|
||||
* Get the key code that would be sent with the given scancode in a key event.
|
||||
*
|
||||
* This uses the information from the current keymap along with the options
|
||||
* specified in SDL_HINT_KEYCODE_OPTIONS to get the keycode that would be
|
||||
* delivered to the application in a key event. This is typically the
|
||||
* unmodified version of the key based on the current keyboard layout. For
|
||||
* example, the keycode for SDL_SCANCODE_A + SDL_KMOD_SHIFT using the US
|
||||
* QWERTY layout would be 'a'.
|
||||
*
|
||||
* \param scancode the SDL_Scancode to translate.
|
||||
* \param modstate the modifier state to use when translating the scancode to
|
||||
* a keycode.
|
||||
* \returns the SDL_Keycode that corresponds to the given SDL_Scancode.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate);
|
||||
extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate, SDL_bool key_event);
|
||||
|
||||
/**
|
||||
* Set a human-readable name for a scancode.
|
||||
|
|
|
@ -199,7 +199,6 @@ SDL3_0.0.0 {
|
|||
SDL_GetCurrentCameraDriver;
|
||||
SDL_GetCurrentDisplayMode;
|
||||
SDL_GetCurrentDisplayOrientation;
|
||||
SDL_GetCurrentKeymap;
|
||||
SDL_GetCurrentRenderOutputSize;
|
||||
SDL_GetCurrentThreadID;
|
||||
SDL_GetCurrentTime;
|
||||
|
@ -328,8 +327,6 @@ SDL3_0.0.0 {
|
|||
SDL_GetKeyboardNameForID;
|
||||
SDL_GetKeyboardState;
|
||||
SDL_GetKeyboards;
|
||||
SDL_GetKeymapKeycode;
|
||||
SDL_GetKeymapScancode;
|
||||
SDL_GetLogOutputFunction;
|
||||
SDL_GetLogPriority;
|
||||
SDL_GetMasksForPixelFormat;
|
||||
|
@ -644,7 +641,6 @@ SDL3_0.0.0 {
|
|||
SDL_RegisterApp;
|
||||
SDL_RegisterEvents;
|
||||
SDL_ReleaseCameraFrame;
|
||||
SDL_ReleaseKeymap;
|
||||
SDL_ReloadGamepadMappings;
|
||||
SDL_RemovePath;
|
||||
SDL_RemoveStoragePath;
|
||||
|
|
|
@ -224,7 +224,6 @@
|
|||
#define SDL_GetCurrentCameraDriver SDL_GetCurrentCameraDriver_REAL
|
||||
#define SDL_GetCurrentDisplayMode SDL_GetCurrentDisplayMode_REAL
|
||||
#define SDL_GetCurrentDisplayOrientation SDL_GetCurrentDisplayOrientation_REAL
|
||||
#define SDL_GetCurrentKeymap SDL_GetCurrentKeymap_REAL
|
||||
#define SDL_GetCurrentRenderOutputSize SDL_GetCurrentRenderOutputSize_REAL
|
||||
#define SDL_GetCurrentThreadID SDL_GetCurrentThreadID_REAL
|
||||
#define SDL_GetCurrentTime SDL_GetCurrentTime_REAL
|
||||
|
@ -353,8 +352,6 @@
|
|||
#define SDL_GetKeyboardNameForID SDL_GetKeyboardNameForID_REAL
|
||||
#define SDL_GetKeyboardState SDL_GetKeyboardState_REAL
|
||||
#define SDL_GetKeyboards SDL_GetKeyboards_REAL
|
||||
#define SDL_GetKeymapKeycode SDL_GetKeymapKeycode_REAL
|
||||
#define SDL_GetKeymapScancode SDL_GetKeymapScancode_REAL
|
||||
#define SDL_GetLogOutputFunction SDL_GetLogOutputFunction_REAL
|
||||
#define SDL_GetLogPriority SDL_GetLogPriority_REAL
|
||||
#define SDL_GetMasksForPixelFormat SDL_GetMasksForPixelFormat_REAL
|
||||
|
@ -669,7 +666,6 @@
|
|||
#define SDL_RegisterApp SDL_RegisterApp_REAL
|
||||
#define SDL_RegisterEvents SDL_RegisterEvents_REAL
|
||||
#define SDL_ReleaseCameraFrame SDL_ReleaseCameraFrame_REAL
|
||||
#define SDL_ReleaseKeymap SDL_ReleaseKeymap_REAL
|
||||
#define SDL_ReloadGamepadMappings SDL_ReloadGamepadMappings_REAL
|
||||
#define SDL_RemovePath SDL_RemovePath_REAL
|
||||
#define SDL_RemoveStoragePath SDL_RemoveStoragePath_REAL
|
||||
|
|
|
@ -244,7 +244,6 @@ SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return)
|
|||
SDL_DYNAPI_PROC(const char*,SDL_GetCurrentCameraDriver,(void),(),return)
|
||||
SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetCurrentDisplayMode,(SDL_DisplayID a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetCurrentDisplayOrientation,(SDL_DisplayID a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_Keymap*,SDL_GetCurrentKeymap,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetCurrentRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetCurrentThreadID,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetCurrentTime,(SDL_Time *a),(a),return)
|
||||
|
@ -367,14 +366,12 @@ 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_GetKeyFromScancode,(SDL_Scancode a, SDL_Keymod b),(a,b),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(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)
|
||||
SDL_DYNAPI_PROC(SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeymapKeycode,(SDL_Keymap *a, SDL_Scancode b, SDL_Keymod c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_Scancode,SDL_GetKeymapScancode,(SDL_Keymap *a, SDL_Keycode b, SDL_Keymod *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_GetLogOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),)
|
||||
SDL_DYNAPI_PROC(SDL_LogPriority,SDL_GetLogPriority,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetMasksForPixelFormat,(SDL_PixelFormat a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
|
||||
|
@ -680,7 +677,6 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU8,(SDL_IOStream *a, Uint8 *b),(a,b),return)
|
|||
SDL_DYNAPI_PROC(int,SDL_RegisterApp,(const char *a, Uint32 b, void *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_RegisterEvents,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_ReleaseCameraFrame,(SDL_Camera *a, SDL_Surface *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_ReleaseKeymap,(SDL_Keymap *a),(a),)
|
||||
SDL_DYNAPI_PROC(int,SDL_ReloadGamepadMappings,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_RemovePath,(const char *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_RemoveStoragePath,(SDL_Storage *a, const char *b),(a,b),return)
|
||||
|
|
|
@ -229,6 +229,8 @@ SDL_Keymap *SDL_GetCurrentKeymap(void)
|
|||
{
|
||||
SDL_Keyboard *keyboard = &SDL_keyboard;
|
||||
|
||||
SDL_AcquireKeymap(keyboard->keymap);
|
||||
|
||||
return keyboard->keymap;
|
||||
}
|
||||
|
||||
|
@ -431,33 +433,37 @@ static SDL_Keycode SDL_ConvertNumpadKeycode(SDL_Keycode keycode, SDL_bool numloc
|
|||
}
|
||||
}
|
||||
|
||||
SDL_Keycode SDL_GetKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate)
|
||||
SDL_Keycode SDL_GetKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate, SDL_bool key_event)
|
||||
{
|
||||
SDL_Keyboard *keyboard = &SDL_keyboard;
|
||||
SDL_bool numlock = (modstate & SDL_KMOD_NUM) != 0;
|
||||
SDL_Keycode keycode;
|
||||
|
||||
// We won't be applying any modifiers by default
|
||||
modstate = SDL_KMOD_NONE;
|
||||
if (key_event) {
|
||||
SDL_bool numlock = (modstate & SDL_KMOD_NUM) != 0;
|
||||
|
||||
if ((keyboard->keycode_options & KEYCODE_OPTION_LATIN_LETTERS) &&
|
||||
keyboard->non_latin_letters) {
|
||||
keycode = SDL_GetKeymapKeycode(NULL, scancode, modstate);
|
||||
} else {
|
||||
if ((keyboard->keycode_options & KEYCODE_OPTION_FRENCH_NUMBERS) &&
|
||||
keyboard->french_numbers &&
|
||||
(scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0)) {
|
||||
// Add the shift state to generate a numeric keycode
|
||||
modstate |= SDL_KMOD_SHIFT;
|
||||
// We won't be applying any modifiers by default
|
||||
modstate = SDL_KMOD_NONE;
|
||||
|
||||
if ((keyboard->keycode_options & KEYCODE_OPTION_LATIN_LETTERS) &&
|
||||
keyboard->non_latin_letters) {
|
||||
keycode = SDL_GetKeymapKeycode(NULL, scancode, modstate);
|
||||
} else {
|
||||
if ((keyboard->keycode_options & KEYCODE_OPTION_FRENCH_NUMBERS) &&
|
||||
keyboard->french_numbers &&
|
||||
(scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0)) {
|
||||
// Add the shift state to generate a numeric keycode
|
||||
modstate |= SDL_KMOD_SHIFT;
|
||||
}
|
||||
|
||||
keycode = SDL_GetKeymapKeycode(keyboard->keymap, scancode, modstate);
|
||||
}
|
||||
|
||||
if (keyboard->keycode_options & KEYCODE_OPTION_HIDE_NUMPAD) {
|
||||
keycode = SDL_ConvertNumpadKeycode(keycode, numlock);
|
||||
}
|
||||
} else {
|
||||
keycode = SDL_GetKeymapKeycode(keyboard->keymap, scancode, modstate);
|
||||
}
|
||||
|
||||
if (keyboard->keycode_options & KEYCODE_OPTION_HIDE_NUMPAD) {
|
||||
keycode = SDL_ConvertNumpadKeycode(keycode, numlock);
|
||||
}
|
||||
|
||||
return keycode;
|
||||
}
|
||||
|
||||
|
@ -509,7 +515,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo
|
|||
/* Update internal keyboard state */
|
||||
keyboard->keystate[scancode] = state;
|
||||
|
||||
keycode = SDL_GetKeyFromScancode(scancode, keyboard->modstate);
|
||||
keycode = SDL_GetKeyFromScancode(scancode, keyboard->modstate, SDL_TRUE);
|
||||
|
||||
} else if (rawcode == 0) {
|
||||
/* Nothing to do! */
|
||||
|
|
|
@ -1114,6 +1114,5 @@ SDL_Keycode SDL_GetKeyFromName(const char *name, SDL_bool uppercase)
|
|||
return key;
|
||||
}
|
||||
|
||||
/* Get the scancode for this name, and the associated keycode */
|
||||
return SDL_GetKeyFromScancode(SDL_GetScancodeFromName(name), SDL_KMOD_NONE);
|
||||
return SDL_GetKeyFromScancode(SDL_GetScancodeFromName(name), SDL_KMOD_NONE, SDL_FALSE);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,9 @@
|
|||
#ifndef SDL_keymap_c_h_
|
||||
#define SDL_keymap_c_h_
|
||||
|
||||
#include "../SDL_hashtable.h"
|
||||
typedef struct SDL_Keymap SDL_Keymap;
|
||||
|
||||
SDL_Keymap *SDL_GetCurrentKeymap(void);
|
||||
SDL_Keymap *SDL_CreateKeymap(void);
|
||||
void SDL_AcquireKeymap(SDL_Keymap *keymap);
|
||||
void SDL_SetKeymapEntry(SDL_Keymap *keymap, SDL_Scancode scancode, SDL_Keymod modstate, SDL_Keycode keycode);
|
||||
|
|
|
@ -1457,7 +1457,7 @@ static void Wayland_ReconcileModifiers(struct SDL_WaylandInput *input)
|
|||
|
||||
static void Wayland_HandleModifierKeys(struct SDL_WaylandInput *input, SDL_Scancode scancode, SDL_bool pressed)
|
||||
{
|
||||
const SDL_Keycode keycode = SDL_GetKeyFromScancode(scancode, SDL_KMOD_NONE);
|
||||
const SDL_Keycode keycode = SDL_GetKeyFromScancode(scancode, SDL_KMOD_NONE, SDL_FALSE);
|
||||
SDL_Keymod mod;
|
||||
|
||||
switch (keycode) {
|
||||
|
@ -1536,7 +1536,7 @@ static void keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
|
|||
|
||||
wl_array_for_each (key, keys) {
|
||||
const SDL_Scancode scancode = Wayland_get_scancode_from_key(input, *key + 8);
|
||||
const SDL_Keycode keycode = SDL_GetKeyFromScancode(scancode, SDL_KMOD_NONE);
|
||||
const SDL_Keycode keycode = SDL_GetKeyFromScancode(scancode, SDL_KMOD_NONE, SDL_FALSE);
|
||||
|
||||
switch (keycode) {
|
||||
case SDLK_LSHIFT:
|
||||
|
|
|
@ -313,7 +313,7 @@ void X11_ReconcileKeyboardState(SDL_VideoDevice *_this)
|
|||
|
||||
if (x11KeyPressed && !sdlKeyPressed) {
|
||||
/* Only update modifier state for keys that are pressed in another application */
|
||||
switch (SDL_GetKeyFromScancode(scancode, SDL_KMOD_NONE)) {
|
||||
switch (SDL_GetKeyFromScancode(scancode, SDL_KMOD_NONE, SDL_FALSE)) {
|
||||
case SDLK_LCTRL:
|
||||
case SDLK_RCTRL:
|
||||
case SDLK_LSHIFT:
|
||||
|
|
|
@ -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) */
|
||||
|
|
Loading…
Reference in New Issue