mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-11 04:38:24 -06:00
Port the context menu positioning logic from 8bbf00e
This commit is contained in:
parent
ede606b837
commit
54a7f2fd63
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user