From 566a45017e9764ef06f193f89c6badfa33d8f171 Mon Sep 17 00:00:00 2001 From: Hashim Khan <64767361+Hashim1999164@users.noreply.github.com> Date: Sat, 15 Aug 2026 07:07:07 +0500 Subject: [PATCH] window: toggle borderless fullscreen with F11 and Alt+Enter (#246) * window: toggle borderless fullscreen with F11 and Alt+Enter Match the existing SDL_WINDOW_FULLSCREEN_DESKTOP startup path so testers can switch modes at runtime. Reserve F11 in host input mappings. Fixes #217. * window: consume fullscreen hotkey input --------- Co-authored-by: nmzik --- .../presentation/window/hostInput.cpp | 3 +- src/graphics/presentation/window/window.cpp | 36 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/graphics/presentation/window/hostInput.cpp b/src/graphics/presentation/window/hostInput.cpp index dea6635d3..37b9aa522 100644 --- a/src/graphics/presentation/window/hostInput.cpp +++ b/src/graphics/presentation/window/hostInput.cpp @@ -119,7 +119,8 @@ public: } const bool reserved = - binding.key == SDLK_ESCAPE || binding.key == SDLK_SPACE || binding.key == SDLK_F1; + binding.key == SDLK_ESCAPE || binding.key == SDLK_SPACE || binding.key == SDLK_F1 || + binding.key == SDLK_F11; if (binding.control == INVALID_CONTROL || reserved || (binding.key == SDLK_UNKNOWN && binding.mouse_button == 0)) { EXIT("Invalid input mapping: %s\n", value.c_str()); diff --git a/src/graphics/presentation/window/window.cpp b/src/graphics/presentation/window/window.cpp index a5d962f54..a6708eda9 100644 --- a/src/graphics/presentation/window/window.cpp +++ b/src/graphics/presentation/window/window.cpp @@ -219,7 +219,24 @@ static void GameEventTerminate(WindowLoopState& game) { game.need_exit = true; } +static void ToggleDesktopFullscreen() { + if (g_window == nullptr || g_window->window == nullptr) { + return; + } + + const auto flags = static_cast(SDL_GetWindowFlags(g_window->window)); + const bool fullscreen = + (flags & static_cast(SDL_WINDOW_FULLSCREEN_DESKTOP)) != 0u; + const auto mode = + fullscreen ? 0u : static_cast(SDL_WINDOW_FULLSCREEN_DESKTOP); + if (SDL_SetWindowFullscreen(g_window->window, mode) != 0) { + LOGF("Toggle fullscreen failed: %s\n", SDL_GetError()); + } +} + static void GameEventKeyboard(WindowLoopState& game, const EventKeyboard& key) { + static SDL_Keycode fullscreen_key = SDLK_UNKNOWN; + #ifdef KYTY_DBG_INPUT LOGF("Key: time = %.04f, %s%s, %s%s, %s, scan = %d, key = %d, mod = %04" PRIx16 "\n", key.timestamp_seconds, (key.down ? "down" : ""), (key.up ? "up" : ""), @@ -237,13 +254,30 @@ static void GameEventKeyboard(WindowLoopState& game, const EventKeyboard& key) { RenderDocRequestCapture(); } break; + case SDLK_F11: + if (!key.repeat) { + ToggleDesktopFullscreen(); + } + break; + case SDLK_RETURN: + case SDLK_KP_ENTER: + if (!key.repeat && (key.mod & KMOD_ALT) != 0) { + ToggleDesktopFullscreen(); + fullscreen_key = key.key_code; + } + break; default: break; } } #endif - if ((key.down || key.up) && !key.repeat) { + const bool fullscreen_key_event = + fullscreen_key != SDLK_UNKNOWN && key.key_code == fullscreen_key; + if (fullscreen_key_event && key.up) { + fullscreen_key = SDLK_UNKNOWN; + } + if ((key.down || key.up) && !key.repeat && !fullscreen_key_event) { HostInputKey(key.key_code, key.down); } }