Fix T88500: Constrain window top position (Win32)

Do not allow a window to be created that has a top position that
can obscure all or part of title bar. Right and Left edges can
still be specified slightly outside of monitor bounds, but top
edge must be clamped to monitor top.

see D11371 for more details.

https://developer.blender.org/D11371

Reviewed by Ray Molenkamp
This commit is contained in:
Pratik Borhade 2021-05-24 11:42:30 -07:00 committed by Harley Acheson
parent 9c53690b30
commit 0606a37e1a
Notes: blender-bot 2023-02-14 03:34:17 +01:00
Referenced by issue #89332, Grease pencil. Blender crashes when setting a masking layer to scale=0 via transform properties
Referenced by issue #88500, Maximize button in the header is broken
1 changed files with 6 additions and 4 deletions

View File

@ -121,19 +121,21 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system,
monitor.dwFlags = 0;
GetMonitorInfo(MonitorFromRect(&win_rect, MONITOR_DEFAULTTONEAREST), &monitor);
/* Constrain size to fit within this monitor. */
/* Constrain requested size and position to fit within this monitor. */
width = min(monitor.rcWork.right - monitor.rcWork.left, win_rect.right - win_rect.left);
height = min(monitor.rcWork.bottom - monitor.rcWork.top, win_rect.bottom - win_rect.top);
win_rect.left = min(max(monitor.rcWork.left, win_rect.left), monitor.rcWork.right - width);
win_rect.right = win_rect.left + width;
win_rect.top = min(max(monitor.rcWork.top, win_rect.top), monitor.rcWork.bottom - height);
win_rect.bottom = win_rect.top + height;
/* Adjust our requested values to allow for caption, borders, shadows, etc.
Windows API Note: You cannot specify WS_OVERLAPPED when calling. */
/* Adjust to allow for caption, borders, shadows, scaling, etc. Resulting values can be
* correctly outside of monitor bounds. Note: You cannot specify WS_OVERLAPPED when calling. */
AdjustWindowRectEx(&win_rect, style & ~WS_OVERLAPPED, FALSE, extended_style);
/* But never allow a top position that can hide part of the title bar. */
win_rect.top = max(monitor.rcWork.top, win_rect.top);
m_hWnd = ::CreateWindowExW(extended_style, // window extended style
s_windowClassName, // pointer to registered class name
title_16, // pointer to window name