chore(window): extend [WINLOG] with native-rect + min-track tracing

The first hardware capture showed handleDisplayScaleChange computing the correct
target (e.g. 1353x720, height = min) but the window never reaching it across all
30 deferred retries — stuck ~5% above target in BOTH DPI directions (759 vs 720
at 100%, 1136 vs 1080 at 150%). That rules out the earlier min-ordering / settle
logic and points at either the borderless WM_GETMINMAXINFO min-track
(720 * g_borderlessDpi) or a native-HWND non-client frame discrepancy on the
externally-created, SDL-wrapped DirectComposition window.

Add the data to disambiguate:
- winlogState now also logs the native GetWindowRect vs GetClientRect (+ pos),
  exposing any window-vs-client size mismatch that SDL_GetWindowSize hides.
- WM_GETMINMAXINFO logs g_borderlessDpi and the resulting min-track (once per
  change) so we can see the actual OS-enforced minimum during the transition.
- Forward-declared winlog so the WndProc can use it.

Windows-only, no behavior change. Grep the log for "[WINLOG]".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-10 01:05:49 -05:00
parent eb08b81706
commit 010465f835

View File

@@ -236,6 +236,8 @@ static float g_borderlessDpi = 1.0f; // DPI scale, updated from SDL each f
// Custom WndProc that removes the native title bar by extending the
// client area to cover the entire window (WM_NCCALCSIZE) and provides
// resize borders + caption drag zone (WM_NCHITTEST).
static void winlog(const char* fmt, ...); // [WINLOG] tracer (defined below)
static LRESULT CALLBACK BorderlessWndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
@@ -315,6 +317,12 @@ static LRESULT CALLBACK BorderlessWndProc(HWND hwnd, UINT msg,
// Scale min window size by DPI so it matches the SDL-side minimum.
mmi->ptMinTrackSize.x = (LONG)(1024 * g_borderlessDpi);
mmi->ptMinTrackSize.y = (LONG)(720 * g_borderlessDpi);
static float s_lastBd = -1.0f; // [WINLOG] log only when g_borderlessDpi changes (this fires a lot)
if (g_borderlessDpi != s_lastBd) {
s_lastBd = g_borderlessDpi;
winlog("WM_GETMINMAXINFO g_borderlessDpi=%.3f -> minTrack=%ldx%ld",
g_borderlessDpi, (long)mmi->ptMinTrackSize.x, (long)mmi->ptMinTrackSize.y);
}
return 0;
}
}
@@ -556,6 +564,18 @@ static void winlogState(SDL_Window* w, const char* tag)
SDL_DisplayID did = SDL_GetDisplayForWindow(w);
winlog("%-20s size=%dx%d px=%dx%d min=%dx%d dispScale=%.3f storedScale=%.3f display=%u",
tag, sw, sh, pw, ph, mw, mh, ds, st, (unsigned)did);
#ifdef _WIN32
HWND hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(w),
SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr);
if (hwnd) {
RECT wr = {}, cr = {};
GetWindowRect(hwnd, &wr);
GetClientRect(hwnd, &cr);
winlog("%-20s native win=%ldx%ld client=%ldx%ld pos=%ld,%ld",
tag, (long)(wr.right - wr.left), (long)(wr.bottom - wr.top),
(long)(cr.right - cr.left), (long)(cr.bottom - cr.top), (long)wr.left, (long)wr.top);
}
#endif
}
// Handle SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: save the old-scale size,
@@ -1364,6 +1384,7 @@ int main(int argc, char* argv[])
winlog("RETRY done: reached target %dx%d", dpiTargetW, dpiTargetH);
dpiResizeRetries = 0;
}
if (dpiResizeRetries == 1) winlogState(window, "RETRY-last(stuck?)");
--dpiResizeRetries;
needsRedraw = true;
}