Skip to content

Commit

Permalink
Slightly reworked text input handling
Browse files Browse the repository at this point in the history
Previously, menus accepting text input for filtering (maps, mods, options, controls) relied on emulated char events, which don't handle the shift modifier.

The new code takes advantage of the fact that text input is enabled by default on desktop platforms and avoids calling SDL_StartTextInput/SDL_StopTextInput, so that actual input events get generated.

On Steam Deck we still call those functions, but only when necessary. For TEXTMODE_NOPOPUP we avoid popping up the on-screen keyboard and accept slightly less functional menu filtering.
  • Loading branch information
andrei-drexler committed Aug 17, 2024
1 parent 16533c2 commit aa650f8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
59 changes: 40 additions & 19 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,46 @@ static void Joy_Flick_f (cvar_t *cvar)
IN_ResetFlickState ();
}

/*
================
IN_UpdateSDLTextInput
Calls SDL_StartTextInput/StopTextInput as needed
based on textmode and the device type
================
*/
static void IN_UpdateSDLTextInput (void)
{
if (SDL_HasScreenKeyboardSupport ())
{
// Devices with an on-screen keyboard (e.g. Steam Deck) don't receive text input events by default.
// In order to have a functional console we need to call SDL_StartTextInput when text mode is explicitly requested.
// When text mode is optional, but we'd rather not have an on-screen keyboard pop up (e.g. maps & options menus),
// we need call SDL_StopTextInput.
if (textmode == TEXTMODE_ON)
SDL_StartTextInput ();
else
SDL_StopTextInput ();
}
else
{
// Desktop devices (without on-screen keyboards) receive text inputs by default.
// We only call SDL_StartTextInput if for some reason text input got deactivated
// (which shouldn't happen if SDL_StopTextInput is not called).
if (textmode == TEXTMODE_ON && !SDL_IsTextInputActive ())
SDL_StartTextInput ();
}
}

/*
================
IN_Init
================
*/
void IN_Init (void)
{
textmode = Key_TextEntry();

if (textmode == TEXTMODE_ON)
SDL_StartTextInput();
else
SDL_StopTextInput();
IN_UpdateSDLTextInput ();

if (safemode || COM_CheckParm("-nomouse"))
{
Expand Down Expand Up @@ -1228,24 +1260,13 @@ void IN_UpdateInputMode (void)
if (textmode != want_textmode)
{
textmode = want_textmode;
if (textmode == TEXTMODE_ON)
{
SDL_StartTextInput();
if (in_debugkeys.value)
Con_Printf("SDL_StartTextInput time: %g\n", Sys_DoubleTime());
}
else
{
SDL_StopTextInput();
if (in_debugkeys.value)
Con_Printf("SDL_StopTextInput time: %g\n", Sys_DoubleTime());
}
IN_UpdateSDLTextInput ();
}
}

textmode_t IN_GetTextMode (void)
qboolean IN_EmulatedCharEvents (void)
{
return textmode;
return textmode == TEXTMODE_NOPOPUP && !SDL_IsTextInputActive ();
}

keydevice_t IN_GetLastActiveDeviceType (void)
Expand Down
2 changes: 1 addition & 1 deletion Quake/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ 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);
qboolean IN_EmulatedCharEvents (void);

enum keydevice_t IN_GetLastActiveDeviceType (void);

Expand Down
5 changes: 3 additions & 2 deletions Quake/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,9 @@ void Key_EventWithKeycode (int key, qboolean down, int keycode)
}

// 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)
// when a physical one isn't present, e.g. when using a searchable menu on the Steam Deck.
// Note: shift modifier is currently not supported for emulated char events.
if (down && !keydown[K_SHIFT] && IN_EmulatedCharEvents ())
Char_Event (keycode);

// handle escape specialy, so the user can never unbind it
Expand Down

0 comments on commit aa650f8

Please sign in to comment.