Skip to content

Commit

Permalink
Don't show on-screen keyboard in searchable menus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrei-drexler committed Dec 28, 2023
1 parent e1f682d commit 164eea6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 28 deletions.
13 changes: 9 additions & 4 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -405,7 +405,7 @@ void IN_Init (void)
{
textmode = Key_TextEntry();

if (textmode)
if (textmode == TEXTMODE_ON)
SDL_StartTextInput();
else
SDL_StopTextInput();
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Quake/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 11 additions & 6 deletions Quake/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}

Expand Down
8 changes: 7 additions & 1 deletion Quake/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
Expand Down
32 changes: 16 additions & 16 deletions Quake/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -6801,7 +6801,7 @@ void M_Charinput (int key)
}


qboolean M_TextEntry (void)
textmode_t M_TextEntry (void)
{
switch (m_state)
{
Expand All @@ -6822,7 +6822,7 @@ qboolean M_TextEntry (void)
case m_keys:
return M_Keys_TextEntry ();
default:
return false;
return TEXTMODE_OFF;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Quake/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 164eea6

Please sign in to comment.