Added a hint to retain window content during state changes

In my testing window content is always retained, but this makes our intent explicit.
main
Sam Lantinga 2023-03-16 20:43:07 -07:00
parent ed0937598e
commit e4be1247d0
2 changed files with 15 additions and 7 deletions

View File

@ -337,6 +337,11 @@ static int SetupWindowData(_THIS, SDL_Window *window, HWND hwnd, HWND parent, SD
data->initializing = SDL_TRUE; data->initializing = SDL_TRUE;
data->last_displayID = window->last_displayID; data->last_displayID = window->last_displayID;
data->scaling_dpi = WIN_GetScalingDPIForHWND(videodata, hwnd); data->scaling_dpi = WIN_GetScalingDPIForHWND(videodata, hwnd);
if (SDL_GetHintBoolean("SDL_WINDOW_RETAIN_CONTENT", SDL_FALSE)) {
data->copybits_flag = 0;
} else {
data->copybits_flag = SWP_NOCOPYBITS;
}
#ifdef HIGHDPI_DEBUG #ifdef HIGHDPI_DEBUG
SDL_Log("SetupWindowData: initialized data->scaling_dpi to %d", data->scaling_dpi); SDL_Log("SetupWindowData: initialized data->scaling_dpi to %d", data->scaling_dpi);
@ -386,7 +391,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, HWND hwnd, HWND parent, SD
/* Figure out what the window area will be */ /* Figure out what the window area will be */
WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_FALSE); WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_FALSE);
data->expected_resize = SDL_TRUE; data->expected_resize = SDL_TRUE;
SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, data->copybits_flag | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
data->expected_resize = SDL_FALSE; data->expected_resize = SDL_FALSE;
} else { } else {
window->w = w; window->w = w;
@ -788,12 +793,12 @@ void WIN_SetWindowPosition(_THIS, SDL_Window *window)
* the window to resize (e.g. AdjustWindowRectExForDpi frame sizes are different). * the window to resize (e.g. AdjustWindowRectExForDpi frame sizes are different).
*/ */
WIN_ConstrainPopup(window); WIN_ConstrainPopup(window);
WIN_SetWindowPositionInternal(window, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); WIN_SetWindowPositionInternal(window, window->driverdata->copybits_flag | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
} }
void WIN_SetWindowSize(_THIS, SDL_Window *window) void WIN_SetWindowSize(_THIS, SDL_Window *window)
{ {
WIN_SetWindowPositionInternal(window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); WIN_SetWindowPositionInternal(window, window->driverdata->copybits_flag | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
} }
int WIN_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right) int WIN_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right)
@ -886,7 +891,7 @@ void WIN_ShowWindow(_THIS, SDL_Window *window)
if (window->parent) { if (window->parent) {
/* Update our position in case our parent moved while we were hidden */ /* Update our position in case our parent moved while we were hidden */
WIN_SetWindowPositionInternal(window, SWP_NOCOPYBITS | SWP_NOACTIVATE); WIN_SetWindowPositionInternal(window, window->driverdata->copybits_flag | SWP_NOACTIVATE);
} }
hwnd = window->driverdata->hwnd; hwnd = window->driverdata->hwnd;
@ -987,7 +992,7 @@ void WIN_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
data->in_border_change = SDL_TRUE; data->in_border_change = SDL_TRUE;
SetWindowLong(hwnd, GWL_STYLE, style); SetWindowLong(hwnd, GWL_STYLE, style);
WIN_SetWindowPositionInternal(window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); WIN_SetWindowPositionInternal(window, data->copybits_flag | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
data->in_border_change = SDL_FALSE; data->in_border_change = SDL_FALSE;
} }
@ -1101,7 +1106,7 @@ void WIN_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *displa
} }
SetWindowLong(hwnd, GWL_STYLE, style); SetWindowLong(hwnd, GWL_STYLE, style);
data->expected_resize = SDL_TRUE; data->expected_resize = SDL_TRUE;
SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE); SetWindowPos(hwnd, top, x, y, w, h, data->copybits_flag | SWP_NOACTIVATE);
data->expected_resize = SDL_FALSE; data->expected_resize = SDL_FALSE;
#ifdef HIGHDPI_DEBUG #ifdef HIGHDPI_DEBUG
@ -1329,7 +1334,7 @@ void WIN_OnWindowEnter(_THIS, SDL_Window *window)
} }
if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) { if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) {
WIN_SetWindowPositionInternal(window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE); WIN_SetWindowPositionInternal(window, data->copybits_flag | SWP_NOSIZE | SWP_NOACTIVATE);
} }
} }

View File

@ -75,6 +75,9 @@ struct SDL_WindowData
* between dpi-scaled points and pixels. Only used if videodata->dpi_scaling_enabled. * between dpi-scaled points and pixels. Only used if videodata->dpi_scaling_enabled.
*/ */
int scaling_dpi; int scaling_dpi;
/* Whether we retain the content of the window when changing state */
UINT copybits_flag;
}; };
extern int WIN_CreateWindow(_THIS, SDL_Window *window); extern int WIN_CreateWindow(_THIS, SDL_Window *window);