tr2: improve reacting to resizes

Addresses parts of #2820.
This commit is contained in:
Marcin Kurczewski 2025-04-22 20:35:50 +02:00
parent 0320383eab
commit b75fa4d5c2
No known key found for this signature in database
GPG key ID: CC65E6FD28CAE42A

View file

@ -149,41 +149,35 @@ static void M_SyncToWindow(void)
static void M_SyncFromWindow(void) static void M_SyncFromWindow(void)
{ {
if (SDL_GetTicks() - m_UpdateDebounce < 1000) { // Determine if this call should sync config, i.e., skip immediate
// Setting the size programatically triggers resize events. // programmatic events
// Additionally, SDL_GetWindowSize() is not guaranteed to return the const Uint32 now = SDL_GetTicks();
// same values as passed to SDL_SetWindowSize(). In order to avoid const bool skip_config = (now - m_UpdateDebounce) < 100;
// infinite loops where the window dimensions are continuously updated,
// resize events are debounced.
return;
}
// Always pull current window state for logging and viewport reset
const Uint32 window_flags = SDL_GetWindowFlags(g_SDLWindow); const Uint32 window_flags = SDL_GetWindowFlags(g_SDLWindow);
const bool is_maximized = window_flags & SDL_WINDOW_MAXIMIZED; const bool is_maximized = window_flags & SDL_WINDOW_MAXIMIZED;
int32_t x, y;
int32_t width; int32_t width, height;
int32_t height;
SDL_GetWindowSize(g_SDLWindow, &width, &height); SDL_GetWindowSize(g_SDLWindow, &width, &height);
int32_t x;
int32_t y;
SDL_GetWindowPosition(g_SDLWindow, &x, &y); SDL_GetWindowPosition(g_SDLWindow, &x, &y);
LOG_INFO("%dx%d+%d,%d (maximized: %d)", width, height, x, y, is_maximized); LOG_INFO("%dx%d+%d,%d (maximized: %d)", width, height, x, y, is_maximized);
g_Config.window.is_maximized = is_maximized; // Update config only when not in debounce window
if (!is_maximized && !g_Config.window.is_fullscreen) { if (!skip_config) {
g_Config.window.x = x; g_Config.window.is_maximized = is_maximized;
g_Config.window.y = y; if (!is_maximized && !g_Config.window.is_fullscreen) {
g_Config.window.width = width; g_Config.window.x = x;
g_Config.window.height = height; g_Config.window.y = y;
} g_Config.window.width = width;
g_Config.window.height = height;
// Save the updated config, but ensure it was loaded first }
if (g_Config.loaded) { if (g_Config.loaded) {
Config_Write(); Config_Write();
}
} }
// Always refresh viewport to reflect the actual window size
M_RefreshRendererViewport(); M_RefreshRendererViewport();
} }