Skip to content

Commit

Permalink
Toggle capslock when opening/closing console if bound to +alwaysrun
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Aug 4, 2024
1 parent 3805a9b commit 3149bab
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* The `STTMINUS` lump used in the status bar and widescreen HUD when the `negativehealth` CVAR is `on` and the player is dead, will now be positioned correctly in instances where its vertical offset is missing.
* A bug is fixed whereby a string CVAR couldn't be changed in the console to the same string but with a different case.
* Blood splats now move with everything else on *BOOM*-compatible scrolling floors.
* If the `+alwaysrun` action is bound to the <kbd>CAPSLOCK</kbd> key, and the `alwaysrun` CVAR is `on`, the <kbd>CAPSLOCK</kbd> key will now be toggled off when the console is opened, and then toggled back on when it closes.

![](https://github.com/bradharding/www.doomretro.com/raw/master/wiki/bigdivider.png)

Expand Down
39 changes: 32 additions & 7 deletions src/c_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,19 @@ void C_ShowConsole(bool reset)
mousebuttons[i] = false;

if (gamestate == GS_LEVEL)
{
if (keyboardalwaysrun == KEY_CAPSLOCK && alwaysrun && GetCapsLockState())
#if defined(_WIN32)
{
ToggleCapsLockState();
nokeyevent = true;
}
#elif defined(X11)
SetCapsLockState(false);
#endif

I_RestoreMousePointerPosition();
}

S_StopSounds();
S_LowerMusicVolume();
Expand All @@ -864,6 +876,16 @@ void C_HideConsole(void)
if (!consoleactive)
return;

if (keyboardalwaysrun == KEY_CAPSLOCK && alwaysrun && !GetCapsLockState() && gamestate == GS_LEVEL)
#if defined(_WIN32)
{
ToggleCapsLockState();
nokeyevent = true;
}
#elif defined(X11)
SetCapsLockState(true);
#endif

SDL_StopTextInput();

consoledirection = -1;
Expand All @@ -880,6 +902,16 @@ void C_HideConsoleFast(void)
if (!consoleactive)
return;

if (keyboardalwaysrun == KEY_CAPSLOCK && alwaysrun && !GetCapsLockState() && gamestate == GS_LEVEL)
#if defined(_WIN32)
{
ToggleCapsLockState();
nokeyevent = true;
}
#elif defined(X11)
SetCapsLockState(true);
#endif

SDL_StopTextInput();

consoledirection = -1;
Expand Down Expand Up @@ -2519,13 +2551,6 @@ bool C_Responder(event_t *ev)
C_HideConsole();
break;

case KEY_CAPSLOCK:
// toggle "always run"
if (keyboardalwaysrun == KEY_CAPSLOCK)
G_ToggleAlwaysRun(ev_keydown);

break;

case 'a':
// select all text
if (modstate & KMOD_CTRL)
Expand Down
2 changes: 1 addition & 1 deletion src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void G_ToggleAlwaysRun(evtype_t type)
const int oldcaretpos = caretpos;
const int oldselectstart = selectstart;
const int oldselectend = selectend;

C_Output("yayayaya!");
#if defined(_WIN32)
alwaysrun = (keyboardalwaysrun == KEY_CAPSLOCK && type == ev_keydown ?
(GetKeyState(VK_CAPITAL) & 0x0001) : !alwaysrun);
Expand Down
11 changes: 9 additions & 2 deletions src/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ bool windowfocused = true;

int keydown = 0;
int keydown2 = 0;
bool nokeyevent = false;

static bool keys[NUMKEYS];

Expand Down Expand Up @@ -239,13 +240,13 @@ bool keystate(const int key)
}

#if defined(_WIN32)
static void ToggleCapsLockState(void)
void ToggleCapsLockState(void)
{
keybd_event(VK_CAPITAL, 0x45, 0, (uintptr_t)0);
keybd_event(VK_CAPITAL, 0x45, KEYEVENTF_KEYUP, (uintptr_t)0);
}
#elif defined(X11)
static void SetCapsLockState(bool enabled)
void SetCapsLockState(bool enabled)
{
Display *display = XOpenDisplay(0);

Expand Down Expand Up @@ -305,6 +306,12 @@ static void I_GetEvent(void)
{
const SDL_Scancode scancode = Event->key.keysym.scancode;

if (nokeyevent)
{
nokeyevent = false;
break;
}

if (scancode >= SDL_SCANCODE_KP_1 && scancode <= SDL_SCANCODE_KP_0
&& !SDL_IsTextInputActive())
ev.data1 = translatekey[keypad[scancode - SDL_SCANCODE_KP_1]];
Expand Down
8 changes: 8 additions & 0 deletions src/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ void I_InitKeyboard(void);
void I_ShutdownKeyboard(void);
bool GetCapsLockState(void);

#if defined(_WIN32)
void ToggleCapsLockState(void);
#elif defined(X11)
void SetCapsLockState(bool enabled);
#endif

// Called by D_DoomLoop,
// called before processing each tic in a frame.
// Quick synchronous operations are performed here.
Expand Down Expand Up @@ -138,6 +144,8 @@ extern bool waspaused;
extern int keydown;
extern int keydown2;

extern bool nokeyevent;

extern int gammaindex;
extern const float gammalevels[GAMMALEVELS];
extern float brightness;
Expand Down

0 comments on commit 3149bab

Please sign in to comment.