aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Windows64/Windows64_Minecraft.cpp
diff options
context:
space:
mode:
authorMarlian <84173858+MCbabel@users.noreply.github.com>2026-03-04 21:50:06 +0100
committerGitHub <noreply@github.com>2026-03-05 03:50:06 +0700
commit3f1388e06f8fa59cf32bffff51812d15d520e53e (patch)
treead9cfa34aead0796a6e4510eaaba7656681c6ba5 /Minecraft.Client/Windows64/Windows64_Minecraft.cpp
parentc517f31b3db053ba5138ac401c59299dae245acd (diff)
Persist fullscreen setting and start windowed mode maximized (#446)
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
Diffstat (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp')
-rw-r--r--Minecraft.Client/Windows64/Windows64_Minecraft.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp
index 61257b89..49c43cea 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();