Skip to content

Commit d73fe0b

Browse files
committed
win32: Hide the borders when showing a fullscreen window
If it is known that the window will immediately enter fullscreen upon being shown, set the borderless style when showing the window to hide the borders, or they may linger in the background if the client takes some time to draw the first frame. Unnecessarily calling ShowWindow with SW_RESTORE when applying the window flags must be suppressed in this case, or the borders can reappear in a weird, partial state.
1 parent ab12b7c commit d73fe0b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/video/windows/SDL_windowswindow.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,9 @@ void WIN_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *
10621062

10631063
void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
10641064
{
1065+
SDL_WindowData *data = window->internal;
1066+
HWND hwnd = data->hwnd;
10651067
DWORD style;
1066-
HWND hwnd;
10671068

10681069
bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, true);
10691070

@@ -1072,17 +1073,30 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
10721073
WIN_SetWindowPosition(_this, window);
10731074
}
10741075

1075-
hwnd = window->internal->hwnd;
1076+
// If the window isn't borderless and will be fullscreen, use the borderless style to hide the initial borders.
1077+
if (window->pending_flags & SDL_WINDOW_FULLSCREEN) {
1078+
if (!(window->flags & SDL_WINDOW_BORDERLESS)) {
1079+
window->flags |= SDL_WINDOW_BORDERLESS;
1080+
style = GetWindowLong(hwnd, GWL_STYLE);
1081+
style &= ~STYLE_MASK;
1082+
style |= GetWindowStyle(window);
1083+
SetWindowLong(hwnd, GWL_STYLE, style);
1084+
window->flags &= ~SDL_WINDOW_BORDERLESS;
1085+
}
1086+
}
10761087
style = GetWindowLong(hwnd, GWL_EXSTYLE);
10771088
if (style & WS_EX_NOACTIVATE) {
10781089
bActivate = false;
10791090
}
1091+
1092+
data->showing_window = true;
10801093
if (bActivate) {
10811094
ShowWindow(hwnd, SW_SHOW);
10821095
} else {
10831096
// Use SetWindowPos instead of ShowWindow to avoid activating the parent window if this is a child window
10841097
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, window->internal->copybits_flag | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
10851098
}
1099+
data->showing_window = false;
10861100

10871101
if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_NOT_FOCUSABLE) && bActivate) {
10881102
WIN_SetKeyboardFocus(window, true);
@@ -1230,10 +1244,12 @@ void WIN_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window)
12301244
{
12311245
SDL_WindowData *data = window->internal;
12321246
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
1233-
HWND hwnd = data->hwnd;
1234-
data->expected_resize = true;
1235-
ShowWindow(hwnd, SW_RESTORE);
1236-
data->expected_resize = false;
1247+
if (!data->showing_window || window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED)) {
1248+
HWND hwnd = data->hwnd;
1249+
data->expected_resize = true;
1250+
ShowWindow(hwnd, SW_RESTORE);
1251+
data->expected_resize = false;
1252+
}
12371253
} else {
12381254
data->windowed_mode_was_maximized = false;
12391255
}

src/video/windows/SDL_windowswindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct SDL_WindowData
8484
bool in_window_deactivation;
8585
bool force_ws_maximizebox;
8686
bool disable_move_size_events;
87+
bool showing_window;
8788
int in_modal_loop;
8889
RECT initial_size_rect;
8990
RECT cursor_clipped_rect; // last successfully committed clipping rect for this window

0 commit comments

Comments
 (0)