From e2dc0ead8b38ab444c2b5e240654a5a0e6f28fba Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Sat, 18 Sep 2021 00:40:24 +0800 Subject: [PATCH] sigh... icons still not working here --- .../DBusSystemTray/SNIDBus.cs | 74 ++++++++++++------- src/Avalonia.X11/X11TrayIconImpl.cs | 2 - 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs b/src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs index bc0350f321..ab0294e2d3 100644 --- a/src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs +++ b/src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs @@ -23,7 +23,7 @@ namespace Avalonia.FreeDesktop.DBusSystemTray private static int GetTID() { - trayinstanceID = (int)new Random().Next(0, 100); + trayinstanceID = 4; return trayinstanceID; } @@ -65,13 +65,12 @@ namespace Avalonia.FreeDesktop.DBusSystemTray // await Task.Delay(2000); // tx.InvalidateAll(); // }); - } public async void Dispose() { var con = DBusHelper.Connection; - + if (await con.UnregisterServiceAsync(_sysTraySrvName)) { con.UnregisterObject(_statusNotifierItem); @@ -107,8 +106,10 @@ namespace Avalonia.FreeDesktop.DBusSystemTray props = new StatusNotifierItemProperties { Title = "Avalonia Test Tray", - Status = "Avalonia Test Tray", - Id = "Avalonia Test Tray" + Status = "Avalonia Test Tray", + Id = "Avalonia Test Tray", + AttentionIconPixmap = new[] { new Pixmap(0, 0, new byte[] { }), new Pixmap(0, 0, new byte[] { }) }, + // IconPixmap = new[] { new Pixmap(1, 1, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }) } }; } @@ -123,21 +124,21 @@ namespace Avalonia.FreeDesktop.DBusSystemTray public async Task SecondaryActivateAsync(int X, int Y) { - //throw new NotImplementedException(); + //throw new NotImplementedException();5 } public async Task ScrollAsync(int Delta, string Orientation) { } - - + public void InvalidateAll() { OnTitleChanged?.Invoke(); OnIconChanged?.Invoke(); OnOverlayIconChanged?.Invoke(); + OnAttentionIconChanged?.Invoke(); } - + public async Task WatchNewTitleAsync(Action handler, Action onError = null) { OnTitleChanged += handler; @@ -216,8 +217,8 @@ namespace Avalonia.FreeDesktop.DBusSystemTray public void SetIcon(Pixmap pixmap) { - props.IconPixmap = pixmap; - InvalidateAll(); + props.IconPixmap = new[] { pixmap }; + InvalidateAll(); } } @@ -372,32 +373,49 @@ namespace Avalonia.FreeDesktop.DBusSystemTray public string IconName; - public Pixmap IconPixmap; + public Pixmap[] IconPixmap; public string OverlayIconName; - public Pixmap OverlayIconPixmap; + public Pixmap[] OverlayIconPixmap; public string AttentionIconName; - public Pixmap AttentionIconPixmap; + public Pixmap[] AttentionIconPixmap; public string AttentionMovieName; - public (string, Pixmap, string, string) ToolTip; + public ToolTip ToolTip; } - public struct Pixmap - { - private readonly int Width; - private readonly int Height; - private readonly byte[] Data; - - public Pixmap(int width, int height, byte[] data) - { - Width = width; - Height = height; - Data = data; - } - } + public readonly struct ToolTip + { + public readonly string First; + public readonly Pixmap[] Second; + public readonly string Third; + public readonly string Fourth; + + public ToolTip(string first, Pixmap[] second, string third, string fourth) + { + First = first; + Second = second; + Third = third; + Fourth = fourth; + } + } + + + public readonly struct Pixmap + { + public readonly int Width; + public readonly int Height; + public readonly byte[] Data; + + public Pixmap(int width, int height, byte[] data) + { + Width = width; + Height = height; + Data = data; + } + } } diff --git a/src/Avalonia.X11/X11TrayIconImpl.cs b/src/Avalonia.X11/X11TrayIconImpl.cs index 3eb8e8d1b6..6006107d21 100644 --- a/src/Avalonia.X11/X11TrayIconImpl.cs +++ b/src/Avalonia.X11/X11TrayIconImpl.cs @@ -77,8 +77,6 @@ namespace Avalonia.X11 sni.SetIcon(new Pixmap(w, h, byteBuf)); } } - - ; } public void SetIsVisible(bool visible)