Win32: Fix rect of undecorated maximized windows

A window created maximized and undecorated would cover the whole monitor
Windows placed it on instead of just that monitor's workarea.

This commit adjusts the maximized rect to cover just the workarea,
similar to how undecorated windows that become maximized are handled
during WM_GETMINMAXINFO.

Fixes #1806

(cherry picked from commit a730acf8e5)
This commit is contained in:
Camilla Löwy 2022-03-07 18:14:16 +01:00
parent 35a65361ff
commit d9512b694b
2 changed files with 26 additions and 5 deletions

View File

@ -123,6 +123,8 @@ information on what to include when reporting a bug.
## Changelog ## Changelog
- [Win32] Bugfix: A window created maximized and undecorated would cover the whole
monitor (#1806)
- [Cocoa] Bugfix: `kUTTypeURL` was deprecated in macOS 12.0 (#2003) - [Cocoa] Bugfix: `kUTTypeURL` was deprecated in macOS 12.0 (#2003)
- [X11] Bugfix: Dynamic loading on OpenBSD failed due to soname differences - [X11] Bugfix: Dynamic loading on OpenBSD failed due to soname differences
- [X11] Bugfix: Waiting for events would fail if file descriptor was too large - [X11] Bugfix: Waiting for events would fail if file descriptor was too large

View File

@ -1285,18 +1285,22 @@ static int createNativeWindow(_GLFWwindow* window,
window->win32.scaleToMonitor = wndconfig->scaleToMonitor; window->win32.scaleToMonitor = wndconfig->scaleToMonitor;
// Adjust window rect to account for DPI scaling of the window frame and
// (if enabled) DPI scaling of the content area
// This cannot be done until we know what monitor the window was placed on
if (!window->monitor) if (!window->monitor)
{ {
RECT rect = { 0, 0, wndconfig->width, wndconfig->height }; RECT rect = { 0, 0, wndconfig->width, wndconfig->height };
WINDOWPLACEMENT wp = { sizeof(wp) }; WINDOWPLACEMENT wp = { sizeof(wp) };
const HMONITOR mh = MonitorFromWindow(window->win32.handle,
MONITOR_DEFAULTTONEAREST);
// Adjust window rect to account for DPI scaling of the window frame and
// (if enabled) DPI scaling of the content area
// This cannot be done until we know what monitor the window was placed on
// Only update the restored window rect as the window may be maximized
if (wndconfig->scaleToMonitor) if (wndconfig->scaleToMonitor)
{ {
float xscale, yscale; float xscale, yscale;
_glfwPlatformGetWindowContentScale(window, &xscale, &yscale); _glfwGetMonitorContentScaleWin32(mh, &xscale, &yscale);
if (xscale > 0.f && yscale > 0.f) if (xscale > 0.f && yscale > 0.f)
{ {
@ -1316,11 +1320,26 @@ static int createNativeWindow(_GLFWwindow* window,
else else
AdjustWindowRectEx(&rect, style, FALSE, exStyle); AdjustWindowRectEx(&rect, style, FALSE, exStyle);
// Only update the restored window rect as the window may be maximized
GetWindowPlacement(window->win32.handle, &wp); GetWindowPlacement(window->win32.handle, &wp);
wp.rcNormalPosition = rect; wp.rcNormalPosition = rect;
wp.showCmd = SW_HIDE; wp.showCmd = SW_HIDE;
SetWindowPlacement(window->win32.handle, &wp); SetWindowPlacement(window->win32.handle, &wp);
// Adjust rect of maximized undecorated window, because by default Windows will
// make such a window cover the whole monitor instead of its workarea
if (wndconfig->maximized && !wndconfig->decorated)
{
MONITORINFO mi = { sizeof(mi) };
GetMonitorInfo(mh, &mi);
SetWindowPos(window->win32.handle, HWND_TOP,
mi.rcWork.left,
mi.rcWork.top,
mi.rcWork.right - mi.rcWork.left,
mi.rcWork.bottom - mi.rcWork.top,
SWP_NOACTIVATE | SWP_NOZORDER);
}
} }
DragAcceptFiles(window->win32.handle, TRUE); DragAcceptFiles(window->win32.handle, TRUE);