From be0cf257fe5ba68afb1ef328ab47527a060adad7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 12 Aug 2022 18:13:42 -0700 Subject: [PATCH] Only force the resize event in the DPI changed case OpenGL windows don't actually get the WM_WINDOWPOSCHANGED event in the SetWindowPos() call in WIN_SetWindowFullscreen(), so setting the window size to zero never gets reset and we're stuck with a zero sized window. Instead, just force the resize event in WM_DPICHANGED handling, where we know we need it. If we end up needing to force it in WIN_SetWindowFullscreen(), just set a flag in the window data and respond to that in WM_WINDOWPOSCHANGED, but that's a fairly risky behavior change as suddenly all applications would start getting SDL_WINDOWEVENT_SIZE_CHANGED when going fullscreen, and they may respond to that in expensive and potentially disruptive ways. For later we'll probably create a DPI changed event and respond to that in the renderer instead of this window size changed hack. This fixes https://github.com/libsdl-org/SDL/issues/6033 @ericwa --- src/video/windows/SDL_windowsevents.c | 9 ++++++++- src/video/windows/SDL_windowswindow.c | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index aa29da1579..e2b95ad4ec 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -1548,7 +1548,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) data->scaling_dpi = newDPI; /* Send a SDL_WINDOWEVENT_SIZE_CHANGED saying that the client size (in dpi-scaled points) is unchanged. - Renderers need to get this to know that the framebuffer size changed. */ + Renderers need to get this to know that the framebuffer size changed. + + We clear the window size to force the event to be delivered, but what we really + want for SDL3 is a new event to notify that the DPI changed and then watch for + that in the renderer directly. + */ + data->window->w = 0; + data->window->h = 0; SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SIZE_CHANGED, data->window->w, data->window->h); } diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 58f7b98092..eb536bbe46 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -932,11 +932,6 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_Log("WIN_SetWindowFullscreen: %d", (int)fullscreen); #endif - /* Clear the window size, to force SDL_SendWindowEvent to send a SDL_WINDOWEVENT_RESIZED - event in WM_WINDOWPOSCHANGED. */ - data->window->w = 0; - data->window->h = 0; - if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_ALWAYS_ON_TOP)) { top = HWND_TOPMOST; } else {