Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use floating DIPs throughout the stack #18027

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ namespace winrt::TerminalApp::implementation
void TerminalPage::_MoveContent(std::vector<Settings::Model::ActionAndArgs>&& actions,
const winrt::hstring& windowName,
const uint32_t tabIndex,
const std::optional<til::point>& dragPoint)
const std::optional<winrt::Windows::Foundation::Point>& dragPoint)
{
const auto winRtActions{ winrt::single_threaded_vector<ActionAndArgs>(std::move(actions)) };
const auto str{ ActionAndArgs::Serialize(winRtActions) };
Expand All @@ -2249,7 +2249,7 @@ namespace winrt::TerminalApp::implementation
tabIndex);
if (dragPoint.has_value())
{
request->WindowPosition(dragPoint->to_winrt_point());
request->WindowPosition(*dragPoint);
}
RequestMoveContent.raise(*this, *request);
}
Expand Down Expand Up @@ -5175,16 +5175,17 @@ namespace winrt::TerminalApp::implementation
// position the dropped window.

// First, the position of the pointer, from the CoreWindow
const til::point pointerPosition{ til::math::rounding, CoreWindow::GetForCurrentThread().PointerPosition() };
const auto pointerPosition = CoreWindow::GetForCurrentThread().PointerPosition();
// Next, the position of the tab itself:
const til::point tabPosition{ til::math::rounding, eventTab.TransformToVisual(nullptr).TransformPoint({ 0, 0 }) };
const auto tabPosition = eventTab.TransformToVisual(nullptr).TransformPoint({ 0, 0 });
// Now, we need to add the origin of our CoreWindow to the tab
// position.
const auto& coreWindowBounds{ CoreWindow::GetForCurrentThread().Bounds() };
const til::point windowOrigin{ til::math::rounding, coreWindowBounds.X, coreWindowBounds.Y };
const auto realTabPosition = windowOrigin + tabPosition;
const auto windowOrigin = CoreWindow::GetForCurrentThread().Bounds();
// Subtract the two to get the offset.
_stashed.dragOffset = til::point{ pointerPosition - realTabPosition };
_stashed.dragOffset = {
pointerPosition.X - windowOrigin.X - tabPosition.X,
pointerPosition.Y - windowOrigin.Y - tabPosition.Y,
};

// Into the DataPackage, let's stash our own window ID.
const auto id{ _WindowProperties.WindowId() };
Expand Down Expand Up @@ -5358,14 +5359,17 @@ namespace winrt::TerminalApp::implementation

// -1 is the magic number for "new window"
// 0 as the tab index, because we don't care. It's making a new window. It'll be the only tab.
const til::point adjusted = til::point{ til::math::rounding, pointerPoint } - _stashed.dragOffset;
const winrt::Windows::Foundation::Point adjusted = {
pointerPoint.X - _stashed.dragOffset.X,
pointerPoint.Y - _stashed.dragOffset.Y,
};
_sendDraggedTabToWindow(winrt::hstring{ L"-1" }, 0, adjusted);
}
}

void TerminalPage::_sendDraggedTabToWindow(const winrt::hstring& windowId,
const uint32_t tabIndex,
std::optional<til::point> dragPoint)
std::optional<winrt::Windows::Foundation::Point> dragPoint)
{
auto startupActions = _stashed.draggedTab->BuildStartupActions(BuildStartupKind::Content);
_DetachTabFromWindow(_stashed.draggedTab);
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ namespace winrt::TerminalApp::implementation
struct StashedDragData
{
winrt::com_ptr<winrt::TerminalApp::implementation::TabBase> draggedTab{ nullptr };
til::point dragOffset{ 0, 0 };
winrt::Windows::Foundation::Point dragOffset{ 0, 0 };
} _stashed;

winrt::Microsoft::Terminal::TerminalConnection::ConptyConnection::NewConnection_revoker _newConnectionRevoker;
Expand Down Expand Up @@ -561,8 +561,8 @@ namespace winrt::TerminalApp::implementation
void _MoveContent(std::vector<winrt::Microsoft::Terminal::Settings::Model::ActionAndArgs>&& actions,
const winrt::hstring& windowName,
const uint32_t tabIndex,
const std::optional<til::point>& dragPoint = std::nullopt);
void _sendDraggedTabToWindow(const winrt::hstring& windowId, const uint32_t tabIndex, std::optional<til::point> dragPoint);
const std::optional<winrt::Windows::Foundation::Point>& dragPoint = std::nullopt);
void _sendDraggedTabToWindow(const winrt::hstring& windowId, const uint32_t tabIndex, std::optional<winrt::Windows::Foundation::Point> dragPoint);

void _PopulateContextMenu(const Microsoft::Terminal::Control::TermControl& control, const Microsoft::UI::Xaml::Controls::CommandBarFlyout& sender, const bool withSelection);
void _PopulateQuickFixMenu(const Microsoft::Terminal::Control::TermControl& control, const Windows::UI::Xaml::Controls::MenuFlyout& sender);
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/TerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ namespace winrt::TerminalApp::implementation
//
// contentBounds is in screen pixels, but that's okay! we want to
// return screen pixels out of here. Nailed it.
const til::rect bounds = { til::math::rounding, _contentBounds.Value() };
initialPosition = { bounds.left, bounds.top };
const auto bounds = _contentBounds.Value();
initialPosition = { lroundf(bounds.X), lroundf(bounds.Y) };
}
return {
initialPosition.X ? initialPosition.X.Value() : defaultInitialX,
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace Microsoft.Terminal.Control
UInt64 SwapChainHandle { get; };

Windows.Foundation.Size FontSize { get; };
Windows.Foundation.Size FontSizeInDips { get; };
UInt16 FontWeight { get; };
Single Opacity { get; };
Boolean UseAcrylic { get; };
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/ControlInteractivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

void ControlInteractivity::TouchPressed(const Core::Point contactPoint)
void ControlInteractivity::TouchPressed(const winrt::Windows::Foundation::Point contactPoint)
{
_touchAnchor = contactPoint;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return handledCompletely;
}

void ControlInteractivity::TouchMoved(const Core::Point newTouchPoint,
void ControlInteractivity::TouchMoved(const winrt::Windows::Foundation::Point newTouchPoint,
const bool focused)
{
if (focused &&
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalControl/ControlInteractivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const uint64_t timestamp,
const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
const Core::Point pixelPosition);
void TouchPressed(const Core::Point contactPoint);
void TouchPressed(const winrt::Windows::Foundation::Point contactPoint);

bool PointerMoved(Control::MouseButtonState buttonState,
const unsigned int pointerUpdateKind,
const ::Microsoft::Terminal::Core::ControlKeyStates modifiers,
const bool focused,
const Core::Point pixelPosition,
const bool pointerPressedInBounds);
void TouchMoved(const Core::Point newTouchPoint,
void TouchMoved(const winrt::Windows::Foundation::Point newTouchPoint,
const bool focused);

void PointerReleased(Control::MouseButtonState buttonState,
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

// If this is set, then we assume we are in the middle of panning the
// viewport via touch input.
std::optional<Core::Point> _touchAnchor;
std::optional<winrt::Windows::Foundation::Point> _touchAnchor;

using Timestamp = uint64_t;

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/ControlInteractivity.idl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Microsoft.Terminal.Control
UInt64 timestamp,
Microsoft.Terminal.Core.ControlKeyStates modifiers,
Microsoft.Terminal.Core.Point pixelPosition);
void TouchPressed(Microsoft.Terminal.Core.Point contactPoint);
void TouchPressed(Windows.Foundation.Point contactPoint);

Boolean PointerMoved(MouseButtonState buttonState,
UInt32 pointerUpdateKind,
Expand All @@ -50,7 +50,7 @@ namespace Microsoft.Terminal.Control
Microsoft.Terminal.Core.Point pixelPosition,
Boolean pointerPressedInBounds);

void TouchMoved(Microsoft.Terminal.Core.Point newTouchPoint,
void TouchMoved(Windows.Foundation.Point newTouchPoint,
Boolean focused);

void PointerReleased(MouseButtonState buttonState,
Expand Down
5 changes: 0 additions & 5 deletions src/cascadia/TerminalControl/HwndTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,11 +1092,6 @@ til::rect HwndTerminal::GetPadding() const noexcept
return {};
}

float HwndTerminal::GetScaleFactor() const noexcept
{
return static_cast<float>(_currentDpi) / static_cast<float>(USER_DEFAULT_SCREEN_DPI);
}

void HwndTerminal::ChangeViewport(const til::inclusive_rect& NewWindow)
{
if (!_terminal)
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/HwndTerminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ struct HwndTerminal : ::Microsoft::Console::Types::IControlAccessibilityInfo
// Inherited via IControlAccessibilityInfo
til::size GetFontSize() const noexcept override;
til::rect GetBounds() const noexcept override;
float GetScaleFactor() const noexcept override;
void ChangeViewport(const til::inclusive_rect& NewWindow) override;
HRESULT GetHostUiaProvider(IRawElementProviderSimple** provider) noexcept override;
til::rect GetPadding() const noexcept override;
Expand Down
14 changes: 7 additions & 7 deletions src/cascadia/TerminalControl/InteractivityAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
THROW_IF_FAILED(::Microsoft::WRL::MakeAndInitialize<::Microsoft::Terminal::TermControlUiaProvider>(&_uiaProvider, _interactivity->GetRenderData(), this));
};

// Bounds is expected to be in pixels.
void InteractivityAutomationPeer::SetControlBounds(const Windows::Foundation::Rect bounds)
{
_controlBounds = til::rect{ til::math::rounding, bounds };
_controlBounds = { til::math::rounding, bounds };
lhecker marked this conversation as resolved.
Show resolved Hide resolved
}

// Padding is expected to be in DIPs.
void InteractivityAutomationPeer::SetControlPadding(const Core::Padding padding)
{
_controlPadding = til::rect{ til::math::rounding, padding };
const auto scale = static_cast<float>(DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel());
_controlPadding = { til::math::rounding, padding.Left * scale, padding.Top * scale, padding.Right * scale, padding.Bottom * scale };
}

void InteractivityAutomationPeer::ParentProvider(AutomationPeer parentProvider)
{
_parentProvider = parentProvider;
Expand Down Expand Up @@ -169,11 +174,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _controlPadding;
}

float InteractivityAutomationPeer::GetScaleFactor() const noexcept
{
return static_cast<float>(DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel());
}

void InteractivityAutomationPeer::ChangeViewport(const til::inclusive_rect& NewWindow)
{
_interactivity->UpdateScrollbar(static_cast<float>(NewWindow.top));
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/InteractivityAutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
virtual til::size GetFontSize() const noexcept override;
virtual til::rect GetBounds() const noexcept override;
virtual til::rect GetPadding() const noexcept override;
virtual float GetScaleFactor() const noexcept override;
virtual void ChangeViewport(const til::inclusive_rect& NewWindow) override;
virtual HRESULT GetHostUiaProvider(IRawElementProviderSimple** provider) override;
#pragma endregion
Expand Down
Loading
Loading