diff --git a/src/main.cpp b/src/main.cpp index 08c6e69..b9c2082 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -703,6 +703,9 @@ int main(int argc, char* argv[]) savedWinW = sw; savedWinH = sh; DEBUG_LOGF("Restored window size from settings: %dx%d\n", sw, sh); + } else if (sw > 0 || sh > 0) { + DEBUG_LOGF("Ignored saved window size %dx%d (below 1024x720 minimum) — using default %dx%d\n", + sw, sh, savedWinW, savedWinH); } } } @@ -1062,13 +1065,21 @@ int main(int argc, char* argv[]) // (point) coordinates and the framebuffer handles pixel density, so // we must NOT multiply the window size by the content scale. #ifndef __APPLE__ - if (currentDpiScale > 1.01f) { + { int curW = 0, curH = 0; SDL_GetWindowSize(window, &curW, &curH); - int newW = (int)(curW * currentDpiScale); - int newH = (int)(curH * currentDpiScale); + int newW = curW, newH = curH; + if (currentDpiScale > 1.01f) { + // On a HiDPI display the saved size is logical px — scale it up to physical so the UI + // appears the same physical size as on a 100% display, and scale the minimum too. + newW = (int)(curW * currentDpiScale); + newH = (int)(curH * currentDpiScale); + SDL_SetWindowMinimumSize(window, (int)(1024 * currentDpiScale), (int)(720 * currentDpiScale)); + } - // Clamp to the display's work area so the window fits on screen. + // Clamp to the current display's work area — runs on EVERY startup (this clamp used to live + // inside the HiDPI branch, so a size saved on a larger/disconnected monitor could open the + // window off-screen or bigger than the screen on a same-DPI cold start). SDL_DisplayID did = SDL_GetDisplayForWindow(window); if (did) { SDL_Rect usable; @@ -1078,13 +1089,12 @@ int main(int argc, char* argv[]) } } - SDL_SetWindowSize(window, newW, newH); - SDL_SetWindowMinimumSize(window, - (int)(1024 * currentDpiScale), - (int)(720 * currentDpiScale)); - SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); - DEBUG_LOGF("HiDPI startup: window resized %dx%d -> %dx%d (scale %.2f)\n", - curW, curH, newW, newH, currentDpiScale); + if (newW != curW || newH != curH) { + SDL_SetWindowSize(window, newW, newH); + SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + DEBUG_LOGF("Startup: window fitted %dx%d -> %dx%d (scale %.2f)\n", + curW, curH, newW, newH, currentDpiScale); + } } #endif @@ -1853,6 +1863,8 @@ int main(int argc, char* argv[]) if (logW >= 1024 && logH >= 720) { app.settings()->setWindowSize(logW, logH); app.settings()->save(); + } else { + DEBUG_LOGF("Not saving window size %dx%d (logical, below 1024x720 minimum)\n", logW, logH); } }