Browse Source
make the icon converter delegate static to avoid unnecessary allocs
pull/6779/head
Jumar Macato
5 years ago
No known key found for this signature in database
GPG Key ID: 85076C4D9D3155A3
2 changed files with
13 additions and
11 deletions
-
src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs
-
src/Avalonia.X11/X11Platform.cs
|
|
|
@ -41,7 +41,7 @@ namespace Avalonia.FreeDesktop |
|
|
|
public bool IsActive { get; private set; } |
|
|
|
public INativeMenuExporter? MenuExporter { get; } |
|
|
|
public Action? OnClicked { get; set; } |
|
|
|
public Func<IWindowIconImpl, uint[]>? IconConverterDelegate { get; set; } |
|
|
|
public Func<IWindowIconImpl?, uint[]> IconConverterDelegate { get; set; } |
|
|
|
|
|
|
|
public DBusTrayIconImpl() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -105,23 +105,25 @@ namespace Avalonia.X11 |
|
|
|
public IntPtr DeferredDisplay { 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(); |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IWindowImpl CreateWindow() |
|
|
|
{ |
|
|
|
return new X11Window(this, null); |
|
|
|
|