Windows: Preserve the non-maximized window size

Fixes #15435
This commit is contained in:
Henrik Rydgård
2026-01-23 15:31:22 +01:00
parent 9a2e74d210
commit b90bb6da70
5 changed files with 46 additions and 8 deletions
+1
View File
@@ -328,6 +328,7 @@ static const ConfigSetting generalSettings[] = {
ConfigSetting("WindowY", SETTING(g_Config, iWindowY), -1, CfgFlag::DEFAULT),
ConfigSetting("WindowWidth", SETTING(g_Config, iWindowWidth), 0, CfgFlag::DEFAULT), // 0 will be automatically reset later (need to do the AdjustWindowRect dance).
ConfigSetting("WindowHeight", SETTING(g_Config, iWindowHeight), 0, CfgFlag::DEFAULT),
ConfigSetting("WindowSizeState", SETTING(g_Config, iWindowSizeState), (int)WindowSizeState::Normal, CfgFlag::DEFAULT),
ConfigSetting("ShrinkIfWindowSmall", SETTING(g_Config, bShrinkIfWindowSmall), false, CfgFlag::DEFAULT),
#endif
+2
View File
@@ -293,6 +293,8 @@ public:
int iWindowY;
int iWindowWidth; // Windows and other windowed environments
int iWindowHeight;
int iWindowSizeState; // WindowSizeState enum
bool bShowMenuBar; // Windows-only
float fUITint;
+7
View File
@@ -97,6 +97,13 @@ enum TextureFiltering {
TEX_FILTER_AUTO_MAX_QUALITY = 4,
};
// Can't be named WindowState due to collision with SDL.
enum class WindowSizeState {
Normal = 0,
Minimized = 1,
Maximized = 2,
};
enum ReplacementTextureLoadSpeed {
SLOW = 0,
MEDIUM = 1,
+35 -7
View File
@@ -188,14 +188,22 @@ namespace MainWindow
WINDOWPLACEMENT placement{};
GetWindowPlacement(hwndMain, &placement);
if (placement.showCmd == SW_SHOWNORMAL) {
RECT rc;
GetWindowRect(hwndMain, &rc);
g_Config.iWindowX = rc.left;
g_Config.iWindowY = rc.top;
g_Config.iWindowWidth = rc.right - rc.left;
g_Config.iWindowHeight = rc.bottom - rc.top;
switch (placement.showCmd) {
case SW_SHOWMAXIMIZED:
g_Config.iWindowSizeState = (int)WindowSizeState::Maximized;
break;
case SW_SHOWMINIMIZED:
g_Config.iWindowSizeState = (int)WindowSizeState::Minimized;
break;
case SW_SHOWNORMAL:
g_Config.iWindowSizeState = (int)WindowSizeState::Normal;
break;
}
g_Config.iWindowX = placement.rcNormalPosition.left;
g_Config.iWindowY = placement.rcNormalPosition.top;
g_Config.iWindowWidth = placement.rcNormalPosition.right - placement.rcNormalPosition.left;
g_Config.iWindowHeight = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top;
}
static void GetWindowSizeAtResolution(int xres, int yres, int *windowWidth, int *windowHeight) {
@@ -475,6 +483,25 @@ namespace MainWindow
hwndMain = CreateWindowEx(0, szWindowClass, L"", style,
rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);
WINDOWPLACEMENT placement = {sizeof(WINDOWPLACEMENT)};
placement.showCmd = SW_SHOWNORMAL;
switch ((WindowSizeState)g_Config.iWindowSizeState) {
case WindowSizeState::Maximized:
placement.showCmd = SW_SHOWMAXIMIZED;
break;
case WindowSizeState::Minimized:
placement.showCmd = SW_SHOWMINIMIZED;
break;
default:
break;
}
placement.rcNormalPosition.left = g_Config.iWindowX;
placement.rcNormalPosition.top = g_Config.iWindowY;
placement.rcNormalPosition.right = g_Config.iWindowX + g_Config.iWindowWidth;
placement.rcNormalPosition.bottom = g_Config.iWindowY + g_Config.iWindowHeight;
SetWindowPlacement(hwndMain, &placement);
if (!hwndMain)
return FALSE;
@@ -874,6 +901,7 @@ namespace MainWindow
default:
break;
}
SavePosition();
break;
// Wheel events have to stay in WndProc for compatibility with older Windows(7). See #12156