From daff54fe1c8f0bc0b64bf5f18f7ec23c269fc680 Mon Sep 17 00:00:00 2001 From: Marcus Minhorst Date: Mon, 11 Aug 2025 12:34:42 -0400 Subject: [PATCH] Added alt+enter fullscreen keybind --- src/common/engine/d_event.cpp | 25 ++++++++++++++++++----- src/common/platform/posix/sdl/i_input.cpp | 4 ++++ src/common/platform/win32/i_input.cpp | 5 ----- src/common/platform/win32/i_keyboard.cpp | 4 +++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/common/engine/d_event.cpp b/src/common/engine/d_event.cpp index ce11d3b1e..3aa2d3f8f 100644 --- a/src/common/engine/d_event.cpp +++ b/src/common/engine/d_event.cpp @@ -34,15 +34,19 @@ */ #include "c_bind.h" -#include "d_eventbase.h" #include "c_console.h" +#include "c_cvars.h" +#include "d_eventbase.h" #include "d_gui.h" -#include "menu.h" -#include "utf8.h" -#include "m_joy.h" -#include "vm.h" #include "gamestate.h" #include "i_interface.h" +#include "keydef.h" +#include "m_joy.h" +#include "menu.h" +#include "utf8.h" +#include "vm.h" + +extern bool ToggleFullscreen; int eventhead; int eventtail; @@ -73,6 +77,7 @@ void D_ProcessEvents (void) while (eventtail != eventhead) { event_t *ev = &events[eventtail]; + eventtail = (eventtail + 1) & (MAXEVENTS - 1); if (ev->type == EV_KeyUp && keywasdown[ev->data1]) @@ -86,6 +91,16 @@ void D_ProcessEvents (void) if (ev->type == EV_DeviceChange) UpdateJoystickMenu(I_UpdateDeviceList()); +#if defined(__linux__) || defined(_WIN32) + // I cannot test on macos, so it is disabled for now + if ((ev->type == EV_KeyDown && ev->data1 == KEY_ENTER && (ev->data3 & GKM_ALT)) + || (ev->type == EV_GUI_Event && ev->subtype == EV_GUI_KeyDown && ev->data1 == GK_RETURN && (ev->data3 & GKM_ALT))) + { + ToggleFullscreen = !ToggleFullscreen; + continue; + } +#endif + // allow the game to intercept Escape before dispatching it. if (ev->type != EV_KeyDown || ev->data1 != KEY_ESCAPE || !sysCallbacks.WantEscape || !sysCallbacks.WantEscape()) { diff --git a/src/common/platform/posix/sdl/i_input.cpp b/src/common/platform/posix/sdl/i_input.cpp index da7ac59c2..ef1c11e9d 100644 --- a/src/common/platform/posix/sdl/i_input.cpp +++ b/src/common/platform/posix/sdl/i_input.cpp @@ -449,6 +449,10 @@ void MessagePump (const SDL_Event &sev) { event.data2 = sev.key.keysym.sym; } + SDL_Keymod kmod = SDL_GetModState(); + event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) | + ((kmod & KMOD_CTRL) ? GKM_CTRL : 0) | + ((kmod & KMOD_ALT) ? GKM_ALT : 0); D_PostEvent (&event); } } diff --git a/src/common/platform/win32/i_input.cpp b/src/common/platform/win32/i_input.cpp index 121d06c2d..2a4ea0ddd 100644 --- a/src/common/platform/win32/i_input.cpp +++ b/src/common/platform/win32/i_input.cpp @@ -441,11 +441,6 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_SYSKEYDOWN: - // Pressing Alt+Enter can toggle between fullscreen and windowed. - if (wParam == VK_RETURN && k_allowfullscreentoggle && !(lParam & 0x40000000)) - { - ToggleFullscreen = !ToggleFullscreen; - } // Pressing Alt+F4 quits the program. if (wParam == VK_F4 && !(lParam & 0x40000000)) { diff --git a/src/common/platform/win32/i_keyboard.cpp b/src/common/platform/win32/i_keyboard.cpp index 33cf6da5b..4e0a9d451 100644 --- a/src/common/platform/win32/i_keyboard.cpp +++ b/src/common/platform/win32/i_keyboard.cpp @@ -277,7 +277,9 @@ void FKeyboard::PostKeyEvent(int key, INTBOOL down, bool foreground) ev.data1 = key; ev.data2 = Convert[key]; ev.data3 = 0; - if (CheckKey(DIK_LSHIFT) || CheckKey(DIK_RSHIFT)) ev.data3 |= 1; + if (CheckKey(DIK_LSHIFT) || CheckKey(DIK_RSHIFT)) ev.data3 |= GKM_SHIFT; + if (CheckKey(DIK_LCONTROL) || CheckKey(DIK_RCONTROL)) ev.data3 |= GKM_CTRL; + if (CheckKey(DIK_LALT) || CheckKey(DIK_RALT)) ev.data3 |= GKM_ALT; D_PostEvent(&ev); }