Skip to content

Commit

Permalink
Use DIPs for the window bounds when tearing out (#15094)
Browse files Browse the repository at this point in the history
Fixes a bug where you'd drag across the boundary and the new window
would be at the wrong size

related to #14957
  • Loading branch information
zadjii-msft authored Apr 4, 2023
1 parent 5de1fd9 commit c0f1456
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/cascadia/TerminalApp/TerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,11 @@ 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. Huzzah!
// Just return that.
// use that size instead. _contentBounds is in DIPs. Scale
// accordingly to the new pixel size.
return {
_contentBounds.Value().Width,
_contentBounds.Value().Height
_contentBounds.Value().Width * scale,
_contentBounds.Value().Height * scale
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,6 @@ winrt::TerminalApp::TerminalWindow AppHost::Logic()
void AppHost::_handleMoveContent(const winrt::Windows::Foundation::IInspectable& /*sender*/,
winrt::TerminalApp::RequestMoveContentArgs args)
{
winrt::Windows::Foundation::Rect rect{};
winrt::Windows::Foundation::IReference<winrt::Windows::Foundation::Rect> windowBoundsReference{ nullptr };

if (args.WindowPosition() && _window)
Expand Down Expand Up @@ -1280,12 +1279,13 @@ void AppHost::_handleMoveContent(const winrt::Windows::Foundation::IInspectable&
dragPositionInPixels.y -= nonClientFrame.top;
windowSize = windowSize - nonClientFrame.size();

// Convert to DIPs for the size, so that dragging across a DPI boundary
// retains the correct dimensions.
const auto sizeInDips = windowSize.scale(til::math::rounding, 1.0f / scale);
til::rect inDips{ dragPositionInPixels, sizeInDips };

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

_windowManager.RequestMoveContent(args.Window(), args.Content(), args.TabIndex(), windowBoundsReference);
Expand Down
4 changes: 2 additions & 2 deletions src/inc/til/size.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
}

template<typename TilMath, typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr size scale(TilMath math, const T scale) const
[[nodiscard]] constexpr size scale(TilMath math, const T scale) const
{
return {
math,
Expand All @@ -84,7 +84,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
};
}

constexpr size divide_ceil(const size other) const
[[nodiscard]] constexpr size divide_ceil(const size other) const
{
// The integer ceil division `((a - 1) / b) + 1` only works for numbers >0.
// Support for negative numbers wasn't deemed useful at this point.
Expand Down
4 changes: 2 additions & 2 deletions src/til/ut_til/SizeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class SizeTests
constexpr auto scale = 1e12f;

auto fn = [&]() {
sz.scale(til::math::ceiling, scale);
std::ignore = sz.scale(til::math::ceiling, scale);
};

VERIFY_THROWS(fn(), gsl::narrowing_error);
Expand Down Expand Up @@ -359,7 +359,7 @@ class SizeTests
const til::size divisor{ 3, 2 };

auto fn = [&]() {
sz.divide_ceil(divisor);
std::ignore = sz.divide_ceil(divisor);
};

VERIFY_THROWS(fn(), std::invalid_argument);
Expand Down

0 comments on commit c0f1456

Please sign in to comment.