From 718ee71d1c1e6cfa20d2babe8a085f7fe079aaf7 Mon Sep 17 00:00:00 2001 From: MCbabel Date: Wed, 4 Mar 2026 18:38:00 +0100 Subject: [PATCH] Persist fullscreen setting and start windowed mode maximized Save fullscreen toggle state to options.txt when F11 is pressed, and restore it on the next launch. When starting in windowed mode, the window now opens maximized instead of at a smaller default size. Previously, g_isFullscreen was hardcoded to false and never persisted, so the game always started in windowed mode. The window also started at a non-maximized size requiring manual maximization. Fixes #391 --- .../Windows64/Windows64_Minecraft.cpp | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 61257b892..49c43ceac 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -124,6 +124,50 @@ static void CopyWideArgToAnsi(LPCWSTR source, char* dest, size_t destSize) dest[destSize - 1] = 0; } +// ---------- Persistent options (options.txt next to exe) ---------- +static void GetOptionsFilePath(char *out, size_t outSize) +{ + GetModuleFileNameA(NULL, out, (DWORD)outSize); + char *p = strrchr(out, '\\'); + if (p) *(p + 1) = '\0'; + strncat_s(out, outSize, "options.txt", _TRUNCATE); +} + +static void SaveFullscreenOption(bool fullscreen) +{ + char path[MAX_PATH]; + GetOptionsFilePath(path, sizeof(path)); + FILE *f = nullptr; + if (fopen_s(&f, path, "w") == 0 && f) + { + fprintf(f, "fullscreen=%d\n", fullscreen ? 1 : 0); + fclose(f); + } +} + +static bool LoadFullscreenOption() +{ + char path[MAX_PATH]; + GetOptionsFilePath(path, sizeof(path)); + FILE *f = nullptr; + if (fopen_s(&f, path, "r") == 0 && f) + { + char line[256]; + while (fgets(line, sizeof(line), f)) + { + int val = 0; + if (sscanf_s(line, "fullscreen=%d", &val) == 1) + { + fclose(f); + return val != 0; + } + } + fclose(f); + } + return false; +} +// ------------------------------------------------------------------ + static void ApplyScreenMode(int screenMode) { switch (screenMode) @@ -664,7 +708,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) return FALSE; } - ShowWindow(g_hWnd, nCmdShow); + ShowWindow(g_hWnd, (nCmdShow != SW_HIDE) ? SW_SHOWMAXIMIZED : nCmdShow); UpdateWindow(g_hWnd); return TRUE; @@ -873,6 +917,7 @@ void ToggleFullscreen() SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); } g_isFullscreen = !g_isFullscreen; + SaveFullscreenOption(g_isFullscreen); if (g_KBMInput.IsWindowFocused()) g_KBMInput.SetWindowFocused(true); @@ -1193,6 +1238,12 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, return 0; } + // Restore fullscreen state from previous session + if (LoadFullscreenOption() && !g_isFullscreen) + { + ToggleFullscreen(); + } + if (launchOptions.serverMode) { int serverResult = RunHeadlessServer();