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+ssh://svn.code.sf.net/p/quakespasm/code/trunk@1066 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
svdijk 2014-09-23 19:10:02 +00:00
parent 1a0de172a2
commit f4600f12fa
7 changed files with 61 additions and 37 deletions

View file

@ -690,6 +690,7 @@ void _Host_Frame (float time)
// get new key events
Key_UpdateForDest ();
IN_UpdateInputMode ();
Sys_SendKeyEvents ();
// 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"
#endif
static qboolean prev_gamekey, gamekey;
static qboolean textmode;
#ifdef __APPLE__
/* Mouse acceleration needs to be disabled on OS X */
@ -261,10 +261,10 @@ void IN_Deactivate (qboolean free_cursor)
void IN_Init (void)
{
prev_gamekey = Key_GameKey();
textmode = Key_InputtingText();
#if !defined(USE_SDL2)
SDL_EnableUNICODE (!prev_gamekey);
SDL_EnableUNICODE (textmode);
if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n");
#endif
@ -353,20 +353,19 @@ void IN_ClearStates (void)
{
}
void IN_UpdateForKeydest (void)
void IN_UpdateInputMode (void)
{
gamekey = Key_GameKey();
if (gamekey != prev_gamekey)
qboolean want_textmode = Key_InputtingText();
if (textmode != want_textmode)
{
prev_gamekey = gamekey;
Key_ClearStates();
textmode = want_textmode;
#if !defined(USE_SDL2)
SDL_EnableUNICODE(!gamekey);
SDL_EnableUNICODE(textmode);
#else
if (gamekey)
SDL_StopTextInput();
else
if (textmode)
SDL_StartTextInput();
else
SDL_StopTextInput();
#endif
}
}
@ -629,9 +628,8 @@ void IN_SendKeyEvents (void)
/* fallthrough */
case SDL_KEYUP:
#if defined(USE_SDL2)
// SDL2: in gamekey mode, we interpret the keyboard as the US
// layout, so keybindings are based on key position, not the label
// on the key cap.
// SDL2: we interpret the keyboard as the US layout, so keybindings
// are based on key position, not the label on the key cap.
sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode);
if (event.type == SDL_KEYDOWN)

View file

@ -38,8 +38,8 @@ void IN_MouseMove(int dx, int dy);
void IN_SendKeyEvents (void);
// used as a callback for Sys_SendKeyEvents() by some drivers
void IN_UpdateForKeydest (void);
// do stuff if key_dest changes matter to the keyboard driver
void IN_UpdateInputMode (void);
// do stuff if input mode (text/non-text) changes matter to the keyboard driver
void IN_Move (usercmd_t *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
@ -1114,18 +1125,6 @@ void Key_UpdateForDest (void)
forced = false;
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_ClearStates (void);
void Key_UpdateForDest (void);
qboolean Key_GameKey (void);
qboolean Key_ConsoleBindable (int key);
void Key_Event (int key, qboolean down);
void Char_Event (int key);
qboolean Key_InputtingText (void);
void Key_SetBinding (int keynum, const char *binding);
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 */
@ -1299,7 +1305,7 @@ const char *bindnames[][2] =
#define NUMCOMMANDS (sizeof(bindnames)/sizeof(bindnames[0]))
static int keys_cursor;
qboolean m_keys_bind_grab;
static qboolean bind_grab;
void M_Menu_Keys_f (void)
{
@ -1366,7 +1372,7 @@ void M_Keys_Draw (void)
p = Draw_CachePic ("gfx/ttl_cstm.lmp");
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");
else
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, '=');
else
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];
int keys[2];
if (m_keys_bind_grab)
if (bind_grab)
{ // defining a key
S_LocalSound ("misc/menu1.wav");
if ((k != K_ESCAPE) && (k != '`'))
@ -1418,7 +1424,7 @@ void M_Keys_Key (int k)
Cbuf_InsertText (cmd);
}
m_keys_bind_grab = false;
bind_grab = false;
IN_Deactivate(modestate == MS_WINDOWED); // deactivate because we're returning to the menu
return;
}
@ -1451,7 +1457,7 @@ void M_Keys_Key (int k)
S_LocalSound ("misc/menu2.wav");
if (keys[1] != -1)
M_UnbindCommand (bindnames[keys_cursor][0]);
m_keys_bind_grab = true;
bind_grab = true;
IN_Activate(); // activate to allow mouse key binding
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 */
@ -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)
{
// 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 qboolean m_entersound;
extern qboolean m_keys_bind_grab;
//
// menus
@ -55,6 +54,7 @@ extern qboolean m_keys_bind_grab;
void M_Init (void);
void M_Keydown (int key);
void M_Charinput (int key);
qboolean M_InputtingText (void);
void M_ToggleMenu_f (void);
void M_Menu_Main_f (void);