mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-06-26 18:11:00 +12:00
Fix mouse position for shell context menu when menu/app key is used.
Mouse capture outside window mus be enabled otherwise screen 0:0 is returned. However, we keep using native function as suggested by Mouse.GetPosition remarks.
This commit is contained in:
parent
8311d9fd5b
commit
f8f2338b73
|
@ -7,6 +7,7 @@ namespace SystemTrayMenu.Handler
|
|||
using System;
|
||||
using System.Windows.Input;
|
||||
using SystemTrayMenu.DataClasses;
|
||||
using SystemTrayMenu.DllImports;
|
||||
using SystemTrayMenu.UserInterface;
|
||||
using SystemTrayMenu.Utilities;
|
||||
using static SystemTrayMenu.Helpers.GlobalHotkeys;
|
||||
|
@ -109,14 +110,7 @@ namespace SystemTrayMenu.Handler
|
|||
case Key.Apps:
|
||||
if (modifiers == ModifierKeys.None)
|
||||
{
|
||||
Menu? menu = focussedMenu;
|
||||
RowData? itemData = menu?.SelectedItem;
|
||||
if (menu != null && itemData != null)
|
||||
{
|
||||
var position = Mouse.GetPosition(menu);
|
||||
position.Offset(menu.Left, menu.Top);
|
||||
itemData.OpenShellContextMenu(position);
|
||||
}
|
||||
focussedMenu?.SelectedItem?.OpenShellContextMenu(NativeMethods.Screen.CursorPosition);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -63,12 +63,20 @@ namespace SystemTrayMenu.DllImports
|
|||
{
|
||||
get
|
||||
{
|
||||
#if TODO // Maybe use Windows.Desktop instead of Win32 API?
|
||||
// See: https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.mouse.getposition?view=windowsdesktop-8.0
|
||||
if (Mouse.Capture(menu))
|
||||
{
|
||||
LastCursorPosition = Mouse.GetPosition(menu);
|
||||
Mouse.Capture(null);
|
||||
}
|
||||
#else
|
||||
NativeMethods.POINT lpPoint;
|
||||
if (NativeMethods.GetCursorPos(out lpPoint))
|
||||
{
|
||||
LastCursorPosition = new(lpPoint.X, lpPoint.Y);
|
||||
}
|
||||
|
||||
#endif
|
||||
return LastCursorPosition;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue