mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-09 05:35:08 +00:00
Use DIPs for the window bounds when tearing out (#15094)
Fixes a bug where you'd drag across the boundary and the new window would be at the wrong size related to #14957
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user