Skip to content

Commit

Permalink
Fix wrong maximized window offset on non primary monitors (#1921)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dsafa authored and DHowett committed Jul 11, 2019
1 parent 60a444c commit 7b8cf10
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 7b8cf10

Please sign in to comment.