|
|
@ -16,7 +16,7 @@ namespace Avalonia.Win32 |
|
|
{ |
|
|
{ |
|
|
internal class TrayIconImpl : ITrayIconImpl |
|
|
internal class TrayIconImpl : ITrayIconImpl |
|
|
{ |
|
|
{ |
|
|
private static readonly Win32Icon s_emptyIcon; |
|
|
private static Win32Icon? s_emptyIcon; |
|
|
private readonly int _uniqueId; |
|
|
private readonly int _uniqueId; |
|
|
private static int s_nextUniqueId; |
|
|
private static int s_nextUniqueId; |
|
|
private static nint s_taskBarMonitor; |
|
|
private static nint s_taskBarMonitor; |
|
|
@ -31,13 +31,6 @@ namespace Avalonia.Win32 |
|
|
private bool _disposedValue; |
|
|
private bool _disposedValue; |
|
|
private static readonly uint WM_TASKBARCREATED = RegisterWindowMessage("TaskbarCreated"); |
|
|
private static readonly uint WM_TASKBARCREATED = RegisterWindowMessage("TaskbarCreated"); |
|
|
|
|
|
|
|
|
static TrayIconImpl() |
|
|
|
|
|
{ |
|
|
|
|
|
using var bitmap = new WriteableBitmap( |
|
|
|
|
|
new PixelSize(32, 32), new Vector(96, 96), PixelFormats.Bgra8888, AlphaFormat.Unpremul); |
|
|
|
|
|
s_emptyIcon = new Win32Icon(bitmap); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static void ChangeWindowMessageFilter(IntPtr hWnd) |
|
|
internal static void ChangeWindowMessageFilter(IntPtr hWnd) |
|
|
{ |
|
|
{ |
|
|
ChangeWindowMessageFilterEx(hWnd, WM_TASKBARCREATED, MessageFilterFlag.MSGFLT_ALLOW, IntPtr.Zero); |
|
|
ChangeWindowMessageFilterEx(hWnd, WM_TASKBARCREATED, MessageFilterFlag.MSGFLT_ALLOW, IntPtr.Zero); |
|
|
@ -145,7 +138,7 @@ namespace Avalonia.Win32 |
|
|
{ |
|
|
{ |
|
|
iconData.uFlags = NIF.TIP | NIF.MESSAGE | NIF.ICON; |
|
|
iconData.uFlags = NIF.TIP | NIF.MESSAGE | NIF.ICON; |
|
|
iconData.uCallbackMessage = (int)CustomWindowsMessage.WM_TRAYMOUSE; |
|
|
iconData.uCallbackMessage = (int)CustomWindowsMessage.WM_TRAYMOUSE; |
|
|
iconData.hIcon = (_iconStale ? newIcon : _icon)?.Handle ?? s_emptyIcon.Handle; |
|
|
iconData.hIcon = (_iconStale ? newIcon : _icon)?.Handle ?? GetOrCreateEmptyIcon().Handle; |
|
|
iconData.szTip = _tooltipText ?? ""; |
|
|
iconData.szTip = _tooltipText ?? ""; |
|
|
|
|
|
|
|
|
if (!_iconAdded) |
|
|
if (!_iconAdded) |
|
|
@ -172,7 +165,19 @@ namespace Avalonia.Win32 |
|
|
_iconStale = false; |
|
|
_iconStale = false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Win32Icon GetOrCreateEmptyIcon() |
|
|
|
|
|
{ |
|
|
|
|
|
if (s_emptyIcon is null) |
|
|
|
|
|
{ |
|
|
|
|
|
using var bitmap = new WriteableBitmap( |
|
|
|
|
|
new PixelSize(32, 32), new Vector(96, 96), PixelFormats.Bgra8888, AlphaFormat.Unpremul); |
|
|
|
|
|
s_emptyIcon = new Win32Icon(bitmap); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return s_emptyIcon; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private double GetTaskBarMonScalingOrDefault() |
|
|
private double GetTaskBarMonScalingOrDefault() |
|
|
{ |
|
|
{ |
|
|
if (ShCoreAvailable && Win32Platform.WindowsVersion > PlatformConstants.Windows8_1) |
|
|
if (ShCoreAvailable && Win32Platform.WindowsVersion > PlatformConstants.Windows8_1) |
|
|
|