From 7b8cf10fe0e69d99199567330a8c7840b251b2db Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 11 Jul 2019 10:59:19 -0700 Subject: [PATCH] Fix wrong maximized window offset on non primary monitors (#1921) The overhang of a maximized window is currently calculated with this: ```cpp auto offset = 0; if (rcMaximum.left == 0) { offset = windowPos->x; } else if (rcMaximum.top == 0) { offset = windowPos->y; } ``` This always works on the primary monitor but on a non primary monitor, it isn't always the case that `left` or `top` can be 0. Examples are when you offset a monitor. In those cases, `offset` will be 0 and the window will be cut off. Instead I've changed the calculation to calculate the width of the windows frame which is how much it would overhang. Admittedly, the old calculation could be kept and take into consideration the current monitor. --- .../WindowsTerminal/NonClientIslandWindow.cpp | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp index 368961817c4..f5a7813bc27 100644 --- a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp @@ -607,27 +607,19 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos) ((suggestedWidth > maxWidth) || (suggestedHeight > maxHeight))) { - auto offset = 0; - // Determine which side of the window to use for the offset - // calculation. If the taskbar is on the left or top of the screen, - // then the x or y coordinate of the work rect might not be 0. - // Check both, and use whichever is 0. - if (rcMaximum.left == 0) - { - offset = windowPos->x; - } - else if (rcMaximum.top == 0) - { - offset = windowPos->y; - } - const auto offsetX = offset; - const auto offsetY = offset; - - _maximizedMargins.cxRightWidth = -offset; - _maximizedMargins.cxLeftWidth = -offset; - - _maximizedMargins.cyTopHeight = -offset; - _maximizedMargins.cyBottomHeight = -offset; + RECT frame{}; + // Calculate the maxmized window overhang by getting the size of the window frame. + // We use the style without WS_CAPTION otherwise the caption height is included. + // Only remove WS_DLGFRAME since WS_CAPTION = WS_DLGFRAME | WS_BORDER, + // but WS_BORDER is needed as it modifies the calculation of the width of the frame. + const auto targetStyle = windowStyle & ~WS_DLGFRAME; + AdjustWindowRectExForDpi(&frame, targetStyle, false, GetWindowExStyle(_window.get()), _currentDpi); + + // Frame left and top will be negative + _maximizedMargins.cxLeftWidth = frame.left * -1; + _maximizedMargins.cyTopHeight = frame.top * -1; + _maximizedMargins.cxRightWidth = frame.right; + _maximizedMargins.cyBottomHeight = frame.bottom; _isMaximized = true; THROW_IF_FAILED(_UpdateFrameMargins());