From 8caeaaacddce29604e991acb5f2a7b8c758914f8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 20 Mar 2025 16:00:04 -0700 Subject: [PATCH] A Steam Controller might be generating keyboard input We can't use keyboard input as a signal about whether a keyboard is attached. There might be keyboard input from any number of generated inputs or non-keyboard devices. --- src/events/SDL_keyboard.c | 17 ----------------- src/events/SDL_keyboard_c.h | 6 ------ src/joystick/SDL_joystick.c | 5 ----- src/video/SDL_video.c | 2 +- 4 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 69fcc08091..066c6e6aaa 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -70,7 +70,6 @@ typedef struct SDL_Keyboard static SDL_Keyboard SDL_keyboard; static int SDL_keyboard_count; static SDL_KeyboardInstance *SDL_keyboards; -static bool SDL_keyboard_active; static void SDLCALL SDL_KeycodeOptionsChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { @@ -215,20 +214,6 @@ const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id) return SDL_GetPersistentString(SDL_keyboards[keyboard_index].name); } -void SDL_SetKeyboardActive(bool active) -{ - SDL_keyboard_active = active; -} - -bool SDL_HasActiveKeyboard(void) -{ - if (!SDL_HasKeyboard()) { - // No keyboards to be active - return false; - } - return SDL_keyboard_active; -} - void SDL_ResetKeyboard(void) { SDL_Keyboard *keyboard = &SDL_keyboard; @@ -571,8 +556,6 @@ static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keyb } if (source == KEYBOARD_HARDWARE) { - // Primary input appears to be a keyboard - SDL_SetKeyboardActive(true); keyboard->hardware_timestamp = SDL_GetTicks(); } else if (source == KEYBOARD_AUTORELEASE) { keyboard->autorelease_pending = true; diff --git a/src/events/SDL_keyboard_c.h b/src/events/SDL_keyboard_c.h index 45145cf211..ddfb5c5747 100644 --- a/src/events/SDL_keyboard_c.h +++ b/src/events/SDL_keyboard_c.h @@ -43,12 +43,6 @@ extern void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name, bool se // A keyboard has been removed from the system extern void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID, bool send_event); -// Set whether keyboard input is active -extern void SDL_SetKeyboardActive(bool active); - -// Get whether keyboard input is active -extern bool SDL_HasActiveKeyboard(void); - // Set the mapping of scancode to key codes extern void SDL_SetKeymap(SDL_Keymap *keymap, bool send_event); diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index bcc806a47f..e88dde63f8 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -2368,11 +2368,6 @@ void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butt return; } - if (!joystick->is_virtual) { - // Primary input appears to be a joystick - SDL_SetKeyboardActive(false); - } - /* We ignore events if we don't have keyboard focus, except for button * release. */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 3d45b3b0ac..1540e92b83 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -5416,7 +5416,7 @@ bool SDL_GetTextInputMultiline(SDL_PropertiesID props) static bool AutoShowingScreenKeyboard(void) { const char *hint = SDL_GetHint(SDL_HINT_ENABLE_SCREEN_KEYBOARD); - if (((!hint || SDL_strcasecmp(hint, "auto") == 0) && !SDL_HasActiveKeyboard()) || + if (((!hint || SDL_strcasecmp(hint, "auto") == 0) && !SDL_HasKeyboard()) || SDL_GetStringBoolean(hint, false)) { return true; } else {