input: Rework the text/non-text input mode handling.

Before, "gamekey" was the special case, now "textmode" is. We are now more precise about when we activate "textmode", e.g. we only do this when the console, messagemode, or a textfield in the menu are active. The trigger for doing this was this line on the "SDL_StartTextInput" page of the SDL2 wiki: "On some platforms using this function activates the screen keyboard.". Although we currenly support no such platform, it's good te be prepared, and what we do now is more correct anyway.


git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1066 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Sander van Dijk 2014-09-23 19:10:02 +00:00
parent e21e7a375b
commit cebef615e5
7 changed files with 61 additions and 37 deletions

View file

@ -690,6 +690,7 @@ void _Host_Frame (float time)
// get new key events // get new key events
Key_UpdateForDest (); Key_UpdateForDest ();
IN_UpdateInputMode ();
Sys_SendKeyEvents (); Sys_SendKeyEvents ();
// allow mice or other external controllers to add commands // allow mice or other external controllers to add commands

View file

@ -32,7 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "SDL.h" #include "SDL.h"
#endif #endif
static qboolean prev_gamekey, gamekey; static qboolean textmode;
#ifdef __APPLE__ #ifdef __APPLE__
/* Mouse acceleration needs to be disabled on OS X */ /* Mouse acceleration needs to be disabled on OS X */
@ -261,10 +261,10 @@ void IN_Deactivate (qboolean free_cursor)
void IN_Init (void) void IN_Init (void)
{ {
prev_gamekey = Key_GameKey(); textmode = Key_InputtingText();
#if !defined(USE_SDL2) #if !defined(USE_SDL2)
SDL_EnableUNICODE (!prev_gamekey); SDL_EnableUNICODE (textmode);
if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1) if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n"); Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n");
#endif #endif
@ -353,20 +353,19 @@ void IN_ClearStates (void)
{ {
} }
void IN_UpdateForKeydest (void) void IN_UpdateInputMode (void)
{ {
gamekey = Key_GameKey(); qboolean want_textmode = Key_InputtingText();
if (gamekey != prev_gamekey) if (textmode != want_textmode)
{ {
prev_gamekey = gamekey; textmode = want_textmode;
Key_ClearStates();
#if !defined(USE_SDL2) #if !defined(USE_SDL2)
SDL_EnableUNICODE(!gamekey); SDL_EnableUNICODE(textmode);
#else #else
if (gamekey) if (textmode)
SDL_StopTextInput();
else
SDL_StartTextInput(); SDL_StartTextInput();
else
SDL_StopTextInput();
#endif #endif
} }
} }
@ -629,9 +628,8 @@ void IN_SendKeyEvents (void)
/* fallthrough */ /* fallthrough */
case SDL_KEYUP: case SDL_KEYUP:
#if defined(USE_SDL2) #if defined(USE_SDL2)
// SDL2: in gamekey mode, we interpret the keyboard as the US // SDL2: we interpret the keyboard as the US layout, so keybindings
// layout, so keybindings are based on key position, not the label // are based on key position, not the label on the key cap.
// on the key cap.
sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode); sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode);
if (event.type == SDL_KEYDOWN) if (event.type == SDL_KEYDOWN)

View file

@ -38,8 +38,8 @@ void IN_MouseMove(int dx, int dy);
void IN_SendKeyEvents (void); void IN_SendKeyEvents (void);
// used as a callback for Sys_SendKeyEvents() by some drivers // used as a callback for Sys_SendKeyEvents() by some drivers
void IN_UpdateForKeydest (void); void IN_UpdateInputMode (void);
// do stuff if key_dest changes matter to the keyboard driver // do stuff if input mode (text/non-text) changes matter to the keyboard driver
void IN_Move (usercmd_t *cmd); void IN_Move (usercmd_t *cmd);
// add additional movement on top of the keyboard move cmd // add additional movement on top of the keyboard move cmd

View file

@ -1063,6 +1063,17 @@ void Char_Event (int key)
} }
} }
/*
===================
Key_InputtingText
===================
*/
qboolean Key_InputtingText(void)
{
return (key_dest == key_console || (key_dest == key_game && con_forcedup) ||
key_dest == key_message || (key_dest == key_menu && M_InputtingText()));
}
/* /*
=================== ===================
Key_ClearStates Key_ClearStates
@ -1114,18 +1125,6 @@ void Key_UpdateForDest (void)
forced = false; forced = false;
break; break;
} }
IN_UpdateForKeydest ();
}
/*
===================
Key_GameKey
===================
*/
qboolean Key_GameKey(void)
{
return ((key_dest == key_game && !con_forcedup) || m_keys_bind_grab);
} }
/* /*

View file

@ -164,11 +164,11 @@ extern qboolean chat_team;
void Key_Init (void); void Key_Init (void);
void Key_ClearStates (void); void Key_ClearStates (void);
void Key_UpdateForDest (void); void Key_UpdateForDest (void);
qboolean Key_GameKey (void);
qboolean Key_ConsoleBindable (int key); qboolean Key_ConsoleBindable (int key);
void Key_Event (int key, qboolean down); void Key_Event (int key, qboolean down);
void Char_Event (int key); void Char_Event (int key);
qboolean Key_InputtingText (void);
void Key_SetBinding (int keynum, const char *binding); void Key_SetBinding (int keynum, const char *binding);
const char *Key_KeynumToString (int keynum); const char *Key_KeynumToString (int keynum);

View file

@ -845,6 +845,12 @@ void M_Setup_Char (int k)
} }
} }
qboolean M_Setup_InputtingText (void)
{
return (setup_cursor == 0 || setup_cursor == 1);
}
//============================================================================= //=============================================================================
/* NET MENU */ /* NET MENU */
@ -1299,7 +1305,7 @@ const char *bindnames[][2] =
#define NUMCOMMANDS (sizeof(bindnames)/sizeof(bindnames[0])) #define NUMCOMMANDS (sizeof(bindnames)/sizeof(bindnames[0]))
static int keys_cursor; static int keys_cursor;
qboolean m_keys_bind_grab; static qboolean bind_grab;
void M_Menu_Keys_f (void) void M_Menu_Keys_f (void)
{ {
@ -1366,7 +1372,7 @@ void M_Keys_Draw (void)
p = Draw_CachePic ("gfx/ttl_cstm.lmp"); p = Draw_CachePic ("gfx/ttl_cstm.lmp");
M_DrawPic ( (320-p->width)/2, 4, p); M_DrawPic ( (320-p->width)/2, 4, p);
if (m_keys_bind_grab) if (bind_grab)
M_Print (12, 32, "Press a key or button for this action"); M_Print (12, 32, "Press a key or button for this action");
else else
M_Print (18, 32, "Enter to change, backspace to clear"); M_Print (18, 32, "Enter to change, backspace to clear");
@ -1397,7 +1403,7 @@ void M_Keys_Draw (void)
} }
} }
if (m_keys_bind_grab) if (bind_grab)
M_DrawCharacter (130, 48 + keys_cursor*8, '='); M_DrawCharacter (130, 48 + keys_cursor*8, '=');
else else
M_DrawCharacter (130, 48 + keys_cursor*8, 12+((int)(realtime*4)&1)); M_DrawCharacter (130, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
@ -1409,7 +1415,7 @@ void M_Keys_Key (int k)
char cmd[80]; char cmd[80];
int keys[2]; int keys[2];
if (m_keys_bind_grab) if (bind_grab)
{ // defining a key { // defining a key
S_LocalSound ("misc/menu1.wav"); S_LocalSound ("misc/menu1.wav");
if ((k != K_ESCAPE) && (k != '`')) if ((k != K_ESCAPE) && (k != '`'))
@ -1418,7 +1424,7 @@ void M_Keys_Key (int k)
Cbuf_InsertText (cmd); Cbuf_InsertText (cmd);
} }
m_keys_bind_grab = false; bind_grab = false;
IN_Deactivate(modestate == MS_WINDOWED); // deactivate because we're returning to the menu IN_Deactivate(modestate == MS_WINDOWED); // deactivate because we're returning to the menu
return; return;
} }
@ -1451,7 +1457,7 @@ void M_Keys_Key (int k)
S_LocalSound ("misc/menu2.wav"); S_LocalSound ("misc/menu2.wav");
if (keys[1] != -1) if (keys[1] != -1)
M_UnbindCommand (bindnames[keys_cursor][0]); M_UnbindCommand (bindnames[keys_cursor][0]);
m_keys_bind_grab = true; bind_grab = true;
IN_Activate(); // activate to allow mouse key binding IN_Activate(); // activate to allow mouse key binding
break; break;
@ -1828,6 +1834,12 @@ void M_LanConfig_Char (int key)
} }
} }
qboolean M_LanConfig_InputtingText (void)
{
return (lanConfig_cursor == 0 || lanConfig_cursor == 2);
}
//============================================================================= //=============================================================================
/* GAME OPTIONS MENU */ /* GAME OPTIONS MENU */
@ -2648,6 +2660,20 @@ void M_Charinput (int key)
} }
qboolean M_InputtingText (void)
{
switch (m_state)
{
case m_setup:
return M_Setup_InputtingText();
case m_lanconfig:
return M_LanConfig_InputtingText();
default:
return false;
}
}
void M_ConfigureNetSubsystem(void) void M_ConfigureNetSubsystem(void)
{ {
// enable/disable net systems to match desired config // enable/disable net systems to match desired config

View file

@ -47,7 +47,6 @@ extern enum m_state_e m_state;
extern enum m_state_e m_return_state; extern enum m_state_e m_return_state;
extern qboolean m_entersound; extern qboolean m_entersound;
extern qboolean m_keys_bind_grab;
// //
// menus // menus
@ -55,6 +54,7 @@ extern qboolean m_keys_bind_grab;
void M_Init (void); void M_Init (void);
void M_Keydown (int key); void M_Keydown (int key);
void M_Charinput (int key); void M_Charinput (int key);
qboolean M_InputtingText (void);
void M_ToggleMenu_f (void); void M_ToggleMenu_f (void);
void M_Menu_Main_f (void); void M_Menu_Main_f (void);