Skip to content

Commit 02e55d8

Browse files
committed
Fix WinAPI glitch on first window resize: Window moves to background
When hiding the visible window it seems to not be possible to bring it right back to the foreground. We usually don't need that anyway, so only hide for resolution changes.
1 parent 74f9cda commit 02e55d8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

extras/videoDrivers/WinAPI/WinAPI.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ bool VideoWinAPI::ResizeScreen(const VideoMode newSize, DisplayMode displayMode)
113113
if(displayMode == displayMode_ && newSize == GetWindowSize())
114114
return true;
115115

116-
ShowWindow(screen, SW_HIDE);
117-
118116
VideoMode windowSize = (displayMode == DisplayMode::Fullscreen) ? FindClosestVideoMode(newSize) : newSize;
119117
// Try to switch full screen first
120118
if(displayMode_ == DisplayMode::Fullscreen && displayMode != DisplayMode::Fullscreen)
121119
{
120+
ShowWindow(screen, SW_HIDE);
122121
if(ChangeDisplaySettings(nullptr, 0) != DISP_CHANGE_SUCCESSFUL)
123122
return false;
124123
} else if(displayMode == DisplayMode::Fullscreen)
125124
{
125+
ShowWindow(screen, SW_HIDE);
126126
if(!MakeFullscreen(windowSize))
127127
return false;
128128
}
@@ -141,6 +141,7 @@ bool VideoWinAPI::ResizeScreen(const VideoMode newSize, DisplayMode displayMode)
141141
SetNewSize(adjustedSize, Extent(adjustedSize.width, adjustedSize.height));
142142

143143
ShowWindow(screen, SW_SHOW);
144+
SetActiveWindow(screen);
144145
SetForegroundWindow(screen);
145146
SetFocus(screen);
146147

@@ -197,6 +198,9 @@ std::pair<Rect, VideoMode> VideoWinAPI::CalculateWindowRect(const DisplayMode mo
197198
// Calculate real right/bottom based on the window style
198199
const auto [style, exStyle] = GetStyleFlags(mode);
199200
AdjustWindowRectEx(&wRect, style, false, exStyle);
201+
// Make sure border/title bar is visible
202+
wRect.left = std::max<LONG>(wRect.left, 0);
203+
wRect.top = std::max<LONG>(wRect.top, 0);
200204
return std::make_pair(Rect(wRect.left, wRect.top, wRect.right - wRect.left, wRect.bottom - wRect.top),
201205
size);
202206
}

0 commit comments

Comments
 (0)