From 54a7f2fd6309a9a04ddbae3dda4155b41c332900 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Tue, 24 Jun 2025 17:04:53 -0500 Subject: [PATCH] Port the context menu positioning logic from 8bbf00e --- src/cascadia/TerminalControl/TermControl.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index d3482f8690..050a9467bf 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -3983,17 +3983,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation void TermControl::_contextMenuHandler(IInspectable /*sender*/, Control::ContextMenuRequestedEventArgs args) { - // Position the menu where the pointer is. This was the best way I found how. - const til::point absolutePointerPos{ til::math::rounding, CoreWindow::GetForCurrentThread().PointerPosition() }; - const til::point absoluteWindowOrigin{ til::math::rounding, - CoreWindow::GetForCurrentThread().Bounds().X, - CoreWindow::GetForCurrentThread().Bounds().Y }; - // Get the offset (margin + tabs, etc..) of the control within the window - const til::point controlOrigin{ til::math::flooring, - this->TransformToVisual(nullptr).TransformPoint(Windows::Foundation::Point(0, 0)) }; - - const auto pos = (absolutePointerPos - absoluteWindowOrigin - controlOrigin); - _showContextMenuAt(pos); + const auto inverseScale = 1.0f / static_cast(XamlRoot().RasterizationScale()); + const auto padding = GetPadding(); + const auto pos = args.Position(); + _showContextMenuAt({ + til::math::rounding, + pos.X * inverseScale + static_cast(padding.Left), + pos.Y * inverseScale + static_cast(padding.Top), + }); } void TermControl::_showContextMenuAt(const til::point& controlRelativePos)