Browse Source

make the icon converter delegate static to avoid unnecessary allocs

pull/6779/head
Jumar Macato 5 years ago
parent
commit
fc4c0b09ca
No known key found for this signature in database GPG Key ID: 85076C4D9D3155A3
  1. 2
      src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs
  2. 22
      src/Avalonia.X11/X11Platform.cs

2
src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs

@ -41,7 +41,7 @@ namespace Avalonia.FreeDesktop
public bool IsActive { get; private set; } public bool IsActive { get; private set; }
public INativeMenuExporter? MenuExporter { get; } public INativeMenuExporter? MenuExporter { get; }
public Action? OnClicked { get; set; } public Action? OnClicked { get; set; }
public Func<IWindowIconImpl, uint[]>? IconConverterDelegate { get; set; } public Func<IWindowIconImpl?, uint[]> IconConverterDelegate { get; set; }
public DBusTrayIconImpl() public DBusTrayIconImpl()
{ {

22
src/Avalonia.X11/X11Platform.cs

@ -105,23 +105,25 @@ namespace Avalonia.X11
public IntPtr DeferredDisplay { get; set; } public IntPtr DeferredDisplay { get; set; }
public IntPtr Display { get; set; } public IntPtr Display { get; set; }
public ITrayIconImpl CreateTrayIcon () private static uint[] X11IconConverter(IWindowIconImpl? icon)
{
if (!(icon is X11IconData x11icon))
return Array.Empty<uint>();
return x11icon.Data.Select(x => x.ToUInt32()).ToArray();
}
public ITrayIconImpl CreateTrayIcon()
{ {
var dbusTrayIcon = new DBusTrayIconImpl(); var dbusTrayIcon = new DBusTrayIconImpl();
if (!dbusTrayIcon.IsActive) return new XEmbedTrayIconImpl(); if (!dbusTrayIcon.IsActive) return new XEmbedTrayIconImpl();
dbusTrayIcon.IconConverterDelegate = (icon) =>
{
if (!(icon is X11IconData x11icon))
return Array.Empty<uint>();
return x11icon.Data.Select(x=>x.ToUInt32()).ToArray(); dbusTrayIcon.IconConverterDelegate = X11IconConverter;
};
return dbusTrayIcon; return dbusTrayIcon;
} }
public IWindowImpl CreateWindow() public IWindowImpl CreateWindow()
{ {
return new X11Window(this, null); return new X11Window(this, null);

Loading…
Cancel
Save