Skip to content

Commit

Permalink
[party] tear out of maximized doesn't open maximized
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Mar 16, 2023
1 parent 704220f commit 805b880
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/cascadia/TerminalApp/TerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,12 @@ namespace winrt::TerminalApp::implementation
if (_contentBounds)
{
// If we've been created as a torn-out window, then we'll need to
// use that size instead. _contentBounds is in raw pixels, so
// convert it to _our_ DIPs.
proposedSize = {
_contentBounds.Value().Width * scale,
_contentBounds.Value().Height * scale
// use that size instead. _contentBounds is in raw pixels. Huzzah!
// Just return that.
return {
_contentBounds.Value().Width,
_contentBounds.Value().Height
};
return proposedSize;
}

// GH#2061 - If the global setting "Always show tab bar" is
Expand Down
39 changes: 31 additions & 8 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,20 +1243,43 @@ void AppHost::_handleMoveContent(const winrt::Windows::Foundation::IInspectable&

// Fortunately, the window position is already in pixels.
til::rect windowBoundsInPixels{ _window->GetWindowRect() };
til::size windowSize{ windowBoundsInPixels.size() };

// Adjust for the non-client bounds
const auto dpi = _window->GetCurrentDpi();
const auto nonClientArea = _window->GetNonClientFrame(dpi);
dragPositionInPixels.x -= nonClientArea.left;
dragPositionInPixels.y -= nonClientArea.top;
windowBoundsInPixels.right -= nonClientArea.width();
windowBoundsInPixels.bottom -= nonClientArea.height();
const auto nonClientFrame = _window->GetNonClientFrame(dpi);

// If this window is maximized, you don't _really_ want the new window
// showing up at the same size (the size of a maximized window). You
// want it to just make a normal-sized window. This logic was taken out
// of AppHost::_HandleCreateWindow.
if (IsZoomed(_window->GetHandle()))
{
auto initialSize = _windowLogic.GetLaunchDimensions(dpi);

const auto islandWidth = Utils::ClampToShortMax(static_cast<long>(ceil(initialSize.Width)), 1);
const auto islandHeight = Utils::ClampToShortMax(static_cast<long>(ceil(initialSize.Height)), 1);

// Get the size of a window we'd need to host that client rect. This will
// add the titlebar space.
const til::size nonClientSize{ _window->GetTotalNonClientExclusiveSize(dpi) };

auto adjustedWidth = islandWidth + nonClientSize.width;
auto adjustedHeight = islandHeight + nonClientSize.height;

windowSize = til::size{ Utils::ClampToShortMax(adjustedWidth, 1),
Utils::ClampToShortMax(adjustedHeight, 1) };
}

// Adjust for the non-client bounds
dragPositionInPixels.x -= nonClientFrame.left;
dragPositionInPixels.y -= nonClientFrame.top;
windowSize = windowSize - nonClientFrame.size();

// Use the drag event as the new position, and the size of the actual window.
winrt::Windows::Foundation::Rect rect{ static_cast<float>(dragPositionInPixels.x),
static_cast<float>(dragPositionInPixels.y),
static_cast<float>(windowBoundsInPixels.width()),
static_cast<float>(windowBoundsInPixels.height()) };
static_cast<float>(windowSize.width),
static_cast<float>(windowSize.height) };

_windowManager.RequestMoveContent(args.Window(),
args.Content(),
Expand Down

0 comments on commit 805b880

Please sign in to comment.