redo native keyboard handling

instead of like, constantly checking stuff each frame
Now we check whenever we change the menu entry or open/close the chat or console instead and set sdl textinput mode directly and accordingly no more weird hacking around
this is similar to how srb2classic handles it, just a bit simplified (i dont wanna touch anything menu related if it can be avoided lmao)
this hopefully should resolve any weird remaining issues (lets hope i didnt miss some wonky edge case ugghhh)
TODO: update sdl2 lib on windows to fix issues on sdl side with certain layouts
This commit is contained in:
Alug committed 2025-09-28 16:15:16 +02:00
1 parent 939354f483
commit 423ca0eca0
6 files changed
+97 -65

No files matched your search

+10
View File
@@ -729,6 +729,8 @@ void CON_ToggleOff(void)
con_forcepic = 0;
con_clipviewtop = -1; // remove console clipping of view
I_SetTextInput(false);
Unlock_state();
}
@@ -768,9 +770,13 @@ void CON_Ticker(void)
{
con_destlines = 0;
CON_ClearHUD();
I_SetTextInput(false);
}
else
{
CON_ChangeHeight();
I_SetTextInput(true);
}
}
// clip the view, so that the part under the console is not drawn
@@ -787,9 +793,13 @@ void CON_Ticker(void)
// check if console ready for prompt
if (con_destlines >= minheight)
{
consoleready = true;
}
else
{
consoleready = false;
}
// make overlay messages disappear after a while
for (i = 0; i < con_hudlines; i++)
+5
View File
@@ -1305,6 +1305,7 @@ void HU_clearChatChars(void)
{
M_TextInputClear(&w_chat);
chat_on = false;
I_SetTextInput(false);
}
#ifndef NONET
@@ -1357,6 +1358,7 @@ boolean HU_Responder(event_t *ev)
teamtalk = false;
chat_scrollmedown = true;
typelines = 1;
I_SetTextInput(true);
return true;
}
if ((ev->data1 == gamecontrol[0][gc_teamkey][0] || ev->data1 == gamecontrol[0][gc_teamkey][1])
@@ -1368,6 +1370,7 @@ boolean HU_Responder(event_t *ev)
teamtalk = G_GametypeHasTeams(); // Don't teamtalk if we don't have teams.
chat_scrollmedown = true;
typelines = 1;
I_SetTextInput(true);
return true;
}
}
@@ -1395,6 +1398,7 @@ boolean HU_Responder(event_t *ev)
{
chat_on = false;
chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :)
I_SetTextInput(false);
HU_SendChatMessage();
}
else if (c == KEY_ESCAPE
@@ -1403,6 +1407,7 @@ boolean HU_Responder(event_t *ev)
&& c >= KEY_MOUSE1)) // If it's not a keyboard key, then the chat button is used as a toggle.
{
chat_on = false;
I_SetTextInput(false);
}
else if ((c == KEY_UPARROW || c == KEY_MOUSEWHEELUP) && chat_scroll > 0 && !OLDCHAT) // CHAT SCROLLING YAYS!
{
+2 -3
View File
@@ -24,7 +24,8 @@ extern "C" {
#pragma interface
#endif
void I_SetTextInput(void);
boolean I_UseNativeKeyboard(void);
void I_SetTextInput(boolean enable);
typedef enum
{
@@ -138,8 +139,6 @@ void I_EndRead(void);
UINT32 I_GetRefreshRate(void);
boolean I_UseNativeKeyboard(void);
boolean I_CheckNativeRes(void);
void I_SetBorderlessWindow(void);
+26 -8
View File
@@ -157,8 +157,6 @@ boolean browselocalskins = false;
boolean menuactive = false;
boolean fromlevelselect = false;
boolean menu_text_input = false;
char menu_text_input_buf[MAXSTRINGLENGTH];
static textinput_t menuinput;
@@ -684,9 +682,28 @@ static void M_ResetCvars(void)
}
// This is not a particular elegant solution, but it seems to make do for our purposes
static boolean M_CheckTextInput(void)
static void M_SetTextInput(void)
{
return (menuactive && currentMenu && (itemOn < currentMenu->numitems) && (((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) || (currentMenu->menuitems[itemOn].status == IT_MSGHANDLER && currentMenu->menuitems[itemOn].alphaKey != MM_EVENTHANDLER) || ((currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_KEYHANDLER)));
// dont reset our native input state when console is open
if (CON_Ready())
return;
I_SetTextInput(false);
if (!menuactive || !currentMenu)
{
return;
}
// check if the current entry requieres some kind of keyboard input from us
// except for MM_EVENTHANDLER since thats to be used for the control setup
const UINT16 status = currentMenu->menuitems[itemOn].status;
if ((itemOn < currentMenu->numitems)
&& (((status & IT_CVARTYPE) == IT_CV_STRING) || ((status & IT_TYPE) == IT_KEYHANDLER)
|| (status == IT_MSGHANDLER && currentMenu->menuitems[itemOn].alphaKey != MM_EVENTHANDLER)))
{
I_SetTextInput(true);
}
}
// If current menu item is IT_CV_STRING, setup menuinput
@@ -717,6 +734,7 @@ static void M_NextOpt(void)
} while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE);
M_CheckStringItem();
M_SetTextInput();
}
static void M_PrevOpt(void)
@@ -732,6 +750,7 @@ static void M_PrevOpt(void)
} while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE);
M_CheckStringItem();
M_SetTextInput();
}
// lock out further input in a tic when important buttons are pressed
@@ -1653,6 +1672,8 @@ void M_EndModeAttackRun(void)
//
void M_ClearMenus(boolean callexitmenufunc)
{
M_SetTextInput();
if (!menuactive)
return;
@@ -1702,6 +1723,7 @@ void M_SetupNextMenu(menu_t *menudef)
}
M_CheckStringItem();
M_SetTextInput();
}
//
@@ -1731,10 +1753,6 @@ void M_Ticker(void)
interpTimerHackAllow = true;
menu_text_input = M_CheckTextInput();
I_SetTextInput();
//added : 30-01-98 : test mode for five seconds
if (vidm_testingmode > 0)
{
-2
View File
@@ -116,8 +116,6 @@ void M_QuitResponse(INT32 ch);
// Determines whether to show a level in the list
boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt);
extern boolean menu_text_input;
// flags for items in the menu
// menu handle (what we do when key is pressed
#define IT_TYPE 14 // (2+4+8)
+54 -52
View File
@@ -111,11 +111,6 @@ static void KeyboardLayout_OnChange(void)
HU_Shiftform();
}
boolean I_UseNativeKeyboard(void)
{
return (cv_keyboardlayout.value == 2) && (chat_on || CON_Ready() || (menu_text_input && menuactive));
}
static CV_PossibleValue_t keyboardlayout_cons_t[] = {{1,"Default US"}, {2, "Native"}, {3, "AZERTY"}, {0, NULL}};
consvar_t cv_keyboardlayout = {"keyboardlayout", "Default US", CV_SAVE|CV_CALL, keyboardlayout_cons_t, KeyboardLayout_OnChange, 0, NULL, NULL, 0, 0, NULL};
@@ -205,23 +200,6 @@ static void Impl_SetWindowIcon(void);
boolean downsample = false;
#endif
void I_SetTextInput(void)
{
static boolean input_active = false;
boolean use_native = I_UseNativeKeyboard();
if (use_native && !input_active)
{
SDL_StartTextInput();
input_active = true;
}
else if (!use_native && input_active)
{
SDL_StopTextInput();
input_active = false;
}
}
static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code)
{
if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z)
@@ -315,36 +293,6 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code)
return 0;
}
// Get the equivalent ASCII (Unicode?) character for a keypress.
static INT32 GetTypedChar(SDL_Keysym keysym)
{
SDL_Event next_event;
SDL_Keycode keycode = keysym.sym;
SDL_Scancode scancode = keysym.scancode;
if (I_UseNativeKeyboard()) // only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig)
{
// Special cases, where we always return a fixed value.
switch (keycode)
{
case SDLK_BACKSPACE: return KEY_BACKSPACE;
case SDLK_RETURN: return KEY_ENTER;
default:
break;
}
if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT)
{
if (next_event.text.text[1] == '\0') // limit to ASCII
{
return next_event.text.text[0];
}
}
}
return Impl_SDL_Scancode_To_Keycode(scancode); // fallback to scancodes
}
static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym)
{
SDL_Keycode keycode = keysym.sym;
@@ -423,6 +371,60 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym)
return Impl_SDL_Scancode_To_Keycode(scancode);
}
static boolean native_input_active = false;
// used to supress the games shift/alt handling
boolean I_UseNativeKeyboard(void)
{
return (cv_keyboardlayout.value == 2 && native_input_active);
}
void I_SetTextInput(boolean enable)
{
if (enable && !native_input_active)
{
SDL_StartTextInput();
native_input_active = true;
}
else if (!enable && native_input_active)
{
SDL_StopTextInput();
native_input_active = false;
}
}
// Get the equivalent ASCII (Unicode?) character for a keypress.
static INT32 GetTypedChar(SDL_Keysym keysym)
{
SDL_Event next_event;
SDL_Keycode keycode = keysym.sym;
SDL_Scancode scancode = keysym.scancode;
// only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig)
if (native_input_active)
{
// Special cases, where we always return a fixed value.
switch (keycode)
{
case SDLK_BACKSPACE: return KEY_BACKSPACE;
case SDLK_RETURN: return KEY_ENTER;
default:
break;
}
if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT)
{
if (next_event.text.text[1] == '\0') // limit to ASCII
{
return next_event.text.text[0];
}
}
}
// otherwise fallback to scancodes
return Impl_SDL_Scancode_To_Keycode(scancode);
}
static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which)
{
// -32768 to 32767