From 164eea67bf11bc30da1257c8cb759cede55c7d5f Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Thu, 28 Dec 2023 12:34:45 +0100 Subject: [PATCH] Don't show on-screen keyboard in searchable menus Some menus (Options, Keys, Levels, Mods) are searchable, but text entry is a bonus feature and we don't want to pop up an on-screen keyboard on the Steam Deck every time we enter one of them. --- Quake/in_sdl.c | 13 +++++++++---- Quake/input.h | 2 ++ Quake/keys.c | 17 +++++++++++------ Quake/keys.h | 8 +++++++- Quake/menu.c | 32 ++++++++++++++++---------------- Quake/menu.h | 2 +- 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index ac70faa93..643e3abed 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -35,7 +35,7 @@ extern cvar_t ui_mouse; extern cvar_t language; static qboolean windowhasfocus = true; //just in case sdl fails to tell us... -static qboolean textmode; +static textmode_t textmode = TEXTMODE_OFF; static cvar_t in_debugkeys = {"in_debugkeys", "0", CVAR_NONE}; @@ -405,7 +405,7 @@ void IN_Init (void) { textmode = Key_TextEntry(); - if (textmode) + if (textmode == TEXTMODE_ON) SDL_StartTextInput(); else SDL_StopTextInput(); @@ -896,11 +896,11 @@ void IN_ClearStates (void) void IN_UpdateInputMode (void) { - qboolean want_textmode = Key_TextEntry(); + textmode_t want_textmode = Key_TextEntry(); if (textmode != want_textmode) { textmode = want_textmode; - if (textmode) + if (textmode == TEXTMODE_ON) { SDL_StartTextInput(); if (in_debugkeys.value) @@ -915,6 +915,11 @@ void IN_UpdateInputMode (void) } } +textmode_t IN_GetTextMode (void) +{ + return textmode; +} + static inline int IN_SDL2_ScancodeToQuakeKey(SDL_Scancode scancode) { switch (scancode) diff --git a/Quake/input.h b/Quake/input.h index e05b7177f..38a1fb4a9 100644 --- a/Quake/input.h +++ b/Quake/input.h @@ -44,6 +44,8 @@ void IN_SendKeyEvents (void); void IN_UpdateInputMode (void); // do stuff if input mode (text/non-text) changes matter to the keyboard driver +enum textmode_t IN_GetTextMode (void); + void IN_Move (usercmd_t *cmd); // add additional movement on top of the keyboard move cmd diff --git a/Quake/keys.c b/Quake/keys.c index 106c26c30..c18c47dff 100644 --- a/Quake/keys.c +++ b/Quake/keys.c @@ -1115,6 +1115,11 @@ void Key_EventWithKeycode (int key, qboolean down, int keycode) return; } +// generate char events if we want text input without popping up an on-screen keyboard +// when a physical one isn't present, e.g. when using a searchable menu on the Steam Deck + if (down && IN_GetTextMode () == TEXTMODE_NOPOPUP) + Char_Event (keycode); + // handle escape specialy, so the user can never unbind it if (key == K_ESCAPE) { @@ -1270,30 +1275,30 @@ void Char_Event (int key) Key_TextEntry =================== */ -qboolean Key_TextEntry (void) +textmode_t Key_TextEntry (void) { if (key_inputgrab.active) { // This path is used for simple single-letter inputs (y/n prompts) that also // accept controller input, so we don't want an onscreen keyboard for this case. - return false; + return TEXTMODE_NOPOPUP; } switch (key_dest) { case key_message: - return true; + return TEXTMODE_ON; case key_menu: return M_TextEntry(); case key_game: // Don't return true even during con_forcedup, because that happens while starting a // game and we don't to trigger text input (and the onscreen keyboard on some devices) // during this. - return false; + return TEXTMODE_OFF; case key_console: - return true; + return TEXTMODE_ON; default: - return false; + return TEXTMODE_OFF; } } diff --git a/Quake/keys.h b/Quake/keys.h index ceeeffea6..4ef723adc 100644 --- a/Quake/keys.h +++ b/Quake/keys.h @@ -163,6 +163,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAXCMDLINE 256 typedef enum {key_game, key_console, key_message, key_menu} keydest_t; +typedef enum textmode_t +{ + TEXTMODE_OFF, // no char events + TEXTMODE_ON, // char events, show on-screen keyboard + TEXTMODE_NOPOPUP, // char events, don't show on-screen keyboard +} textmode_t; extern keydest_t key_dest; extern char *keybindings[MAX_KEYS]; @@ -189,7 +195,7 @@ void Key_GetGrabbedInput (int *lastkey, int *lastchar); void Key_Event (int key, qboolean down); void Key_EventWithKeycode (int key, qboolean down, int keycode); void Char_Event (int key); -qboolean Key_TextEntry (void); +textmode_t Key_TextEntry (void); void Key_SetBinding (int keynum, const char *binding); int Key_GetKeysForCommand (const char *command, int *keys, int maxkeys); diff --git a/Quake/menu.c b/Quake/menu.c index 7eeb47156..c6d806532 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -1912,9 +1912,9 @@ void M_Maps_Char (int key) M_List_Char (&mapsmenu.list, key); } -qboolean M_Maps_TextEntry (void) +textmode_t M_Maps_TextEntry (void) { - return !mapsmenu.scrollbar_grab; + return mapsmenu.scrollbar_grab ? TEXTMODE_OFF : TEXTMODE_NOPOPUP; } void M_Maps_Key (int key) @@ -2462,9 +2462,9 @@ void M_Setup_Char (int k) } -qboolean M_Setup_TextEntry (void) +textmode_t M_Setup_TextEntry (void) { - return (setup_cursor == 0 || setup_cursor == 1); + return (setup_cursor == 0 || setup_cursor == 1) ? TEXTMODE_ON : TEXTMODE_OFF; } @@ -4331,9 +4331,9 @@ void M_Options_Key (int k) } } -qboolean M_Options_TextEntry (void) +textmode_t M_Options_TextEntry (void) { - return !slider_grab; + return slider_grab ? TEXTMODE_OFF : TEXTMODE_NOPOPUP; } void M_Options_Char (int key) @@ -4633,9 +4633,9 @@ void M_Keys_Mousemove (int cx, int cy) M_List_Mousemove (&keysmenu.list, cy - keysmenu.y - KEYLIST_OFS); } -qboolean M_Keys_TextEntry (void) +textmode_t M_Keys_TextEntry (void) { - return !bind_grab; + return bind_grab ? TEXTMODE_OFF : TEXTMODE_NOPOPUP; } void M_Keys_Char (int key) @@ -4835,9 +4835,9 @@ void M_Quit_Char (int key) } -qboolean M_Quit_TextEntry (void) +textmode_t M_Quit_TextEntry (void) { - return true; + return TEXTMODE_NOPOPUP; } @@ -5087,9 +5087,9 @@ void M_LanConfig_Char (int key) } -qboolean M_LanConfig_TextEntry (void) +textmode_t M_LanConfig_TextEntry (void) { - return (lanConfig_cursor == 0 || lanConfig_cursor == 2); + return (lanConfig_cursor == 0 || lanConfig_cursor == 2) ? TEXTMODE_ON : TEXTMODE_OFF; } @@ -6050,9 +6050,9 @@ void M_Mods_Char (int key) M_List_Char (&modsmenu.list, key); } -qboolean M_Mods_TextEntry (void) +textmode_t M_Mods_TextEntry (void) { - return !modsmenu.scrollbar_grab; + return modsmenu.scrollbar_grab ? TEXTMODE_OFF : TEXTMODE_NOPOPUP; } void M_Mods_Key (int key) @@ -6801,7 +6801,7 @@ void M_Charinput (int key) } -qboolean M_TextEntry (void) +textmode_t M_TextEntry (void) { switch (m_state) { @@ -6822,7 +6822,7 @@ qboolean M_TextEntry (void) case m_keys: return M_Keys_TextEntry (); default: - return false; + return TEXTMODE_OFF; } } diff --git a/Quake/menu.h b/Quake/menu.h index 58a66bf13..795a3f912 100644 --- a/Quake/menu.h +++ b/Quake/menu.h @@ -61,7 +61,7 @@ void M_Init (void); void M_Keydown (int key); void M_Charinput (int key); void M_Mousemove (int x, int y); -qboolean M_TextEntry (void); +enum textmode_t M_TextEntry (void); qboolean M_KeyBinding (void); void M_ToggleMenu_f (void);