mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-28 20:09:38 +08:00
Use predefined names for constant keyboard and mouse IDs
Fixes https://github.com/libsdl-org/SDL/issues/15563
This commit is contained in:
@@ -201,14 +201,22 @@ SDL_KeyboardID *SDL_GetKeyboards(int *count)
|
|||||||
const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id)
|
const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id)
|
||||||
{
|
{
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
if (!SDL_FindInHashTable(SDL_keyboard_names, (const void *)(uintptr_t)instance_id, (const void **)&name)) {
|
|
||||||
SDL_SetError("Keyboard %" SDL_PRIu32 " not found", instance_id);
|
switch (instance_id) {
|
||||||
return NULL;
|
case SDL_GLOBAL_KEYBOARD_ID:
|
||||||
}
|
name = "Keyboard";
|
||||||
if (!name) {
|
break;
|
||||||
// SDL_strdup() failed during insert
|
default:
|
||||||
SDL_OutOfMemory();
|
if (!SDL_FindInHashTable(SDL_keyboard_names, (const void *)(uintptr_t)instance_id, (const void **)&name)) {
|
||||||
return NULL;
|
SDL_SetError("Keyboard %" SDL_PRIu32 " not found", instance_id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!name) {
|
||||||
|
// SDL_strdup() failed during insert
|
||||||
|
SDL_OutOfMemory();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-8
@@ -422,14 +422,28 @@ SDL_MouseID *SDL_GetMice(int *count)
|
|||||||
const char *SDL_GetMouseNameForID(SDL_MouseID instance_id)
|
const char *SDL_GetMouseNameForID(SDL_MouseID instance_id)
|
||||||
{
|
{
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
if (!SDL_FindInHashTable(SDL_mouse_names, (const void *)(uintptr_t)instance_id, (const void **)&name)) {
|
|
||||||
SDL_SetError("Mouse %" SDL_PRIu32 " not found", instance_id);
|
switch (instance_id) {
|
||||||
return NULL;
|
case SDL_GLOBAL_MOUSE_ID:
|
||||||
}
|
name = "Mouse";
|
||||||
if (!name) {
|
break;
|
||||||
// SDL_strdup() failed during insert
|
case SDL_TOUCH_MOUSEID:
|
||||||
SDL_OutOfMemory();
|
name = "Touch";
|
||||||
return NULL;
|
break;
|
||||||
|
case SDL_PEN_MOUSEID:
|
||||||
|
name = "Pen";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!SDL_FindInHashTable(SDL_mouse_names, (const void *)(uintptr_t)instance_id, (const void **)&name)) {
|
||||||
|
SDL_SetError("Mouse %" SDL_PRIu32 " not found", instance_id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!name) {
|
||||||
|
// SDL_strdup() failed during insert
|
||||||
|
SDL_OutOfMemory();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user