mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Fix tray icon behaviour
This commit is contained in:
@@ -18,9 +18,9 @@ namespace RunnerV2.Helpers
|
|||||||
{
|
{
|
||||||
internal static class SettingsHelper
|
internal static class SettingsHelper
|
||||||
{
|
{
|
||||||
|
private static readonly SettingsUtils _settingsUtils = new();
|
||||||
private static Process? _process;
|
private static Process? _process;
|
||||||
private static TwoWayPipeMessageIPCManaged? _ipc;
|
private static TwoWayPipeMessageIPCManaged? _ipc;
|
||||||
private static SettingsUtils _settingsUtils = new();
|
|
||||||
|
|
||||||
public static void OpenSettingsWindow(bool showOobeWindow = false, bool showScoobeWindow = false, bool showFlyout = false, Point? flyoutPosition = null, string? additionalArguments = null)
|
public static void OpenSettingsWindow(bool showOobeWindow = false, bool showScoobeWindow = false, bool showFlyout = false, Point? flyoutPosition = null, string? additionalArguments = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,6 +32,18 @@ namespace RunnerV2.Helpers
|
|||||||
Shell_NotifyIcon(NIMADD, ref notifyicondata);
|
Shell_NotifyIcon(NIMADD, ref notifyicondata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void StopTrayIcon()
|
||||||
|
{
|
||||||
|
NOTIFYICONDATA notifyicondata = new()
|
||||||
|
{
|
||||||
|
CbSize = (uint)Marshal.SizeOf<NOTIFYICONDATA>(),
|
||||||
|
HWnd = Runner.RunnerHwnd,
|
||||||
|
UId = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
Shell_NotifyIcon(NIMDELETE, ref notifyicondata);
|
||||||
|
}
|
||||||
|
|
||||||
private enum TrayButton : uint
|
private enum TrayButton : uint
|
||||||
{
|
{
|
||||||
Settings = 1,
|
Settings = 1,
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace RunnerV2
|
|||||||
internal static partial bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
|
internal static partial bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
|
||||||
|
|
||||||
internal const uint NIMADD = 0x00000000;
|
internal const uint NIMADD = 0x00000000;
|
||||||
|
internal const uint NIMDELETE = 0x00000002;
|
||||||
|
|
||||||
internal struct NOTIFYICONDATA
|
internal struct NOTIFYICONDATA
|
||||||
{
|
{
|
||||||
@@ -130,6 +131,8 @@ namespace RunnerV2
|
|||||||
COMMAND = 0x0111,
|
COMMAND = 0x0111,
|
||||||
HOTKEY = 0x0312,
|
HOTKEY = 0x0312,
|
||||||
ICON_NOTIFY = 0x0800,
|
ICON_NOTIFY = 0x0800,
|
||||||
|
WINDOWPOSCHANGING = 0x0046,
|
||||||
|
DESTROY = 0x0002,
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
@@ -138,6 +141,9 @@ namespace RunnerV2
|
|||||||
[LibraryImport("user32.dll", SetLastError = false)]
|
[LibraryImport("user32.dll", SetLastError = false)]
|
||||||
internal static partial IntPtr DefWindowProcW(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
internal static partial IntPtr DefWindowProcW(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[LibraryImport("user32.dll", SetLastError = true)]
|
||||||
|
internal static partial uint RegisterWindowMessageW([MarshalAs(UnmanagedType.LPWStr)] string lpString);
|
||||||
|
|
||||||
[LibraryImport("user32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
|
[LibraryImport("user32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
|
||||||
internal static partial nint CreateWindowExW(
|
internal static partial nint CreateWindowExW(
|
||||||
uint dwExStyle,
|
uint dwExStyle,
|
||||||
|
|||||||
@@ -68,11 +68,14 @@ namespace RunnerV2
|
|||||||
}
|
}
|
||||||
|
|
||||||
afterInitializationAction();
|
afterInitializationAction();
|
||||||
|
|
||||||
MessageLoop();
|
MessageLoop();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly uint _taskbarCreatedMessage = RegisterWindowMessageW("TaskbarCreated");
|
||||||
|
|
||||||
private static void MessageLoop()
|
private static void MessageLoop()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
@@ -82,20 +85,7 @@ namespace RunnerV2
|
|||||||
TranslateMessage(ref msg);
|
TranslateMessage(ref msg);
|
||||||
DispatchMessageW(ref msg);
|
DispatchMessageW(ref msg);
|
||||||
|
|
||||||
switch (msg.Message)
|
HandleMessage(msg.HWnd, msg.Message, (nint)msg.WParam, (nint)msg.LParam);
|
||||||
{
|
|
||||||
case (uint)WindowMessages.HOTKEY:
|
|
||||||
HotkeyManager.ProcessHotkey(msg.WParam);
|
|
||||||
break;
|
|
||||||
case (uint)WindowMessages.ICON_NOTIFY:
|
|
||||||
TrayIconManager.ProcessTrayIconMessage(msg.LParam);
|
|
||||||
break;
|
|
||||||
case (uint)WindowMessages.COMMAND:
|
|
||||||
TrayIconManager.ProcessTrayMenuCommand(msg.WParam);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,7 +162,7 @@ namespace RunnerV2
|
|||||||
HInstance = hInstance,
|
HInstance = hInstance,
|
||||||
LpszClassName = TrayWindowClassName,
|
LpszClassName = TrayWindowClassName,
|
||||||
Style = CSHREDRAW | CSVREDRAW,
|
Style = CSHREDRAW | CSVREDRAW,
|
||||||
LpfnWndProc = TrayIconWindowProc,
|
LpfnWndProc = HandleMessage,
|
||||||
HIcon = hIcon,
|
HIcon = hIcon,
|
||||||
HbrBackground = IntPtr.Zero,
|
HbrBackground = IntPtr.Zero,
|
||||||
LpszMenuName = string.Empty,
|
LpszMenuName = string.Empty,
|
||||||
@@ -203,9 +193,34 @@ namespace RunnerV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IntPtr TrayIconWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
|
private static IntPtr HandleMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
|
||||||
{
|
{
|
||||||
TrayIconManager.ProcessTrayIconMessage(lParam.ToInt64());
|
switch (msg)
|
||||||
|
{
|
||||||
|
case (uint)WindowMessages.HOTKEY:
|
||||||
|
HotkeyManager.ProcessHotkey((nuint)wParam);
|
||||||
|
break;
|
||||||
|
case (uint)WindowMessages.ICON_NOTIFY:
|
||||||
|
TrayIconManager.ProcessTrayIconMessage(lParam);
|
||||||
|
break;
|
||||||
|
case (uint)WindowMessages.COMMAND:
|
||||||
|
TrayIconManager.ProcessTrayMenuCommand((nuint)wParam);
|
||||||
|
break;
|
||||||
|
case (uint)WindowMessages.WINDOWPOSCHANGING:
|
||||||
|
TrayIconManager.StartTrayIcon();
|
||||||
|
break;
|
||||||
|
case (uint)WindowMessages.DESTROY:
|
||||||
|
TrayIconManager.StopTrayIcon();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (msg == _taskbarCreatedMessage)
|
||||||
|
{
|
||||||
|
TrayIconManager.StartTrayIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user