Browse Source

Dispose of Win32 GDI handles when TrayIcon closed (#19583)

pull/19597/head
Colton 5 months ago
committed by GitHub
parent
commit
4e08e56866
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      src/Windows/Avalonia.Win32/TrayIconImpl.cs

18
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@ -274,10 +274,11 @@ namespace Avalonia.Win32
private class TrayPopupRoot : Window private class TrayPopupRoot : Window
{ {
private readonly ManagedPopupPositioner _positioner; private readonly ManagedPopupPositioner _positioner;
private readonly TrayIconManagedPopupPositionerPopupImplHelper _positionerHelper;
public TrayPopupRoot() public TrayPopupRoot()
{ {
_positioner = new ManagedPopupPositioner(new TrayIconManagedPopupPositionerPopupImplHelper(MoveResize)); _positionerHelper = new TrayIconManagedPopupPositionerPopupImplHelper(MoveResize);
_positioner = new ManagedPopupPositioner(_positionerHelper);
Topmost = true; Topmost = true;
Deactivated += TrayPopupRoot_Deactivated; Deactivated += TrayPopupRoot_Deactivated;
@ -292,6 +293,12 @@ namespace Avalonia.Win32
Close(); Close();
} }
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
_positionerHelper.Dispose();
}
private void MoveResize(PixelPoint position, Size size, double scaling) private void MoveResize(PixelPoint position, Size size, double scaling)
{ {
if (PlatformImpl is { } platformImpl) if (PlatformImpl is { } platformImpl)
@ -315,7 +322,7 @@ namespace Avalonia.Win32
}); });
} }
private class TrayIconManagedPopupPositionerPopupImplHelper : IManagedPopupPositionerPopup private class TrayIconManagedPopupPositionerPopupImplHelper : IManagedPopupPositionerPopup, IDisposable
{ {
private readonly Action<PixelPoint, Size, double> _moveResize; private readonly Action<PixelPoint, Size, double> _moveResize;
private readonly Window _hiddenWindow; private readonly Window _hiddenWindow;
@ -350,6 +357,11 @@ namespace Avalonia.Win32
_moveResize(new PixelPoint((int)devicePoint.X, (int)devicePoint.Y), virtualSize, Scaling); _moveResize(new PixelPoint((int)devicePoint.X, (int)devicePoint.Y), virtualSize, Scaling);
} }
public void Dispose()
{
_hiddenWindow.Close();
}
public double Scaling => _hiddenWindow.Screens.Primary?.Scaling ?? 1.0; public double Scaling => _hiddenWindow.Screens.Primary?.Scaling ?? 1.0;
} }
} }

Loading…
Cancel
Save