diff --git a/include/dusk/settings.h b/include/dusk/settings.h index 7bdb97370e..da8055b225 100644 --- a/include/dusk/settings.h +++ b/include/dusk/settings.h @@ -134,6 +134,9 @@ struct UserSettings { ConfigVar enableFpsOverlay; ConfigVar fpsOverlayCorner; ConfigVar maxFrameRate; + ConfigVar rememberWindowSize; + ConfigVar lastWindowWidth; + ConfigVar lastWindowHeight; } video; struct { diff --git a/src/dusk/settings.cpp b/src/dusk/settings.cpp index 0a58dfd1ec..74145e32ea 100644 --- a/src/dusk/settings.cpp +++ b/src/dusk/settings.cpp @@ -11,6 +11,9 @@ UserSettings g_userSettings = { .enableFpsOverlay {"game.enableFpsOverlay", false}, .fpsOverlayCorner {"game.fpsOverlayCorner", 0}, .maxFrameRate {"video.maxFrameRate", 240}, + .rememberWindowSize {"video.rememberWindowSize", false}, + .lastWindowWidth {"video.lastWindowWidth", 0}, + .lastWindowHeight {"video.lastWindowHeight", 0}, }, .audio = { @@ -200,6 +203,9 @@ void registerSettings() { Register(g_userSettings.video.enableFpsOverlay); Register(g_userSettings.video.fpsOverlayCorner); Register(g_userSettings.video.maxFrameRate); + Register(g_userSettings.video.rememberWindowSize); + Register(g_userSettings.video.lastWindowWidth); + Register(g_userSettings.video.lastWindowHeight); // Audio Register(g_userSettings.audio.masterVolume); diff --git a/src/dusk/ui/settings.cpp b/src/dusk/ui/settings.cpp index c0f1dc235a..49757aab20 100644 --- a/src/dusk/ui/settings.cpp +++ b/src/dusk/ui/settings.cpp @@ -802,6 +802,21 @@ SettingsWindow::SettingsWindow(bool prelaunch) : mPrelaunch(prelaunch) { pane.add_rml( "
Display the current framerate in a corner of the screen while playing."); }); + config_bool_select(leftPane, rightPane, getSettings().video.rememberWindowSize, + { + .key = "Remember Window Size", + .helpText = "Save and restore the previous session's window size when opening Dusklight.", + .onChange = + [](bool value) { + if (value && !dusk::getSettings().video.enableFullscreen) { + const auto windowSize = aurora::window::get_window_size(); + dusk::getSettings().video.lastWindowWidth.setValue(windowSize.width); + dusk::getSettings().video.lastWindowHeight.setValue(windowSize.height); + dusk::config::Save(); + } + }, + .isDisabled = [] { return IsMobile; }, + }); leftPane.add_section("Resolution"); graphics_tuner_control(*this, leftPane, rightPane, getSettings().game.internalResolutionScale, diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 12d2202e36..8fedae1f6a 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -259,6 +259,13 @@ void main01(void) { dusk::ui::handle_event(event->sdl); dusk::g_imguiConsole.HandleSDLEvent(event->sdl); break; + case AURORA_WINDOW_RESIZED: + if (dusk::getSettings().video.rememberWindowSize && !dusk::getSettings().video.enableFullscreen) { + dusk::getSettings().video.lastWindowWidth.setValue(event->windowSize.width); + dusk::getSettings().video.lastWindowHeight.setValue(event->windowSize.height); + dusk::config::Save(); + } + break; case AURORA_DISPLAY_SCALE_CHANGED: dusk::ImGuiEngine_Initialize(event->windowSize.scale); break; @@ -584,8 +591,18 @@ int game_main(int argc, char* argv[]) { config.startFullscreen = dusk::getSettings().video.enableFullscreen; config.windowPosX = -1; config.windowPosY = -1; - config.windowWidth = defaultWindowWidth * 2; - config.windowHeight = defaultWindowHeight * 2; + + const int lastWindowWidth = dusk::getSettings().video.lastWindowWidth.getValue(); + const int lastWindowHeight = dusk::getSettings().video.lastWindowHeight.getValue(); + + if (dusk::getSettings().video.rememberWindowSize && lastWindowWidth > 0 && lastWindowHeight > 0) { + config.windowWidth = lastWindowWidth; + config.windowHeight = lastWindowHeight; + } else { + config.windowWidth = defaultWindowWidth * 2; + config.windowHeight = defaultWindowHeight * 2; + } + config.desiredBackend = ResolveDesiredBackend(parsed_arg_options); config.logCallback = &aurora_log_callback; config.logLevel = startupLogLevel;