Port the context menu positioning logic from 8bbf00e

This commit is contained in:
Dustin L. Howett 2025-06-24 17:04:53 -05:00
parent ede606b837
commit 54a7f2fd63

View File

@ -3983,17 +3983,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TermControl::_contextMenuHandler(IInspectable /*sender*/, void TermControl::_contextMenuHandler(IInspectable /*sender*/,
Control::ContextMenuRequestedEventArgs args) Control::ContextMenuRequestedEventArgs args)
{ {
// Position the menu where the pointer is. This was the best way I found how. const auto inverseScale = 1.0f / static_cast<float>(XamlRoot().RasterizationScale());
const til::point absolutePointerPos{ til::math::rounding, CoreWindow::GetForCurrentThread().PointerPosition() }; const auto padding = GetPadding();
const til::point absoluteWindowOrigin{ til::math::rounding, const auto pos = args.Position();
CoreWindow::GetForCurrentThread().Bounds().X, _showContextMenuAt({
CoreWindow::GetForCurrentThread().Bounds().Y }; til::math::rounding,
// Get the offset (margin + tabs, etc..) of the control within the window pos.X * inverseScale + static_cast<float>(padding.Left),
const til::point controlOrigin{ til::math::flooring, pos.Y * inverseScale + static_cast<float>(padding.Top),
this->TransformToVisual(nullptr).TransformPoint(Windows::Foundation::Point(0, 0)) }; });
const auto pos = (absolutePointerPos - absoluteWindowOrigin - controlOrigin);
_showContextMenuAt(pos);
} }
void TermControl::_showContextMenuAt(const til::point& controlRelativePos) void TermControl::_showContextMenuAt(const til::point& controlRelativePos)