From f6a4bd90eb69e9125502878b8ec33aa875b3552c Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Sat, 18 Sep 2021 17:41:01 +0800 Subject: [PATCH] some fixes --- src/Avalonia.FreeDesktop/DBusMenuExporter.cs | 4 - .../DBusSystemTray/DBusSysTray.cs | 89 ++++++------------- src/Avalonia.X11/X11TrayIconImpl.cs | 16 ++-- 3 files changed, 36 insertions(+), 73 deletions(-) diff --git a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs index 95aea86dfe..52450560c0 100644 --- a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs +++ b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs @@ -18,8 +18,6 @@ namespace Avalonia.FreeDesktop { public static ITopLevelNativeMenuExporter TryCreateTopLevelNativeMenu(IntPtr xid) { - return null; - if (DBusHelper.Connection == null) return null; @@ -94,8 +92,6 @@ namespace Avalonia.FreeDesktop // and it's not important to know if it succeeds // since even if we register the window it's not guaranteed that // menu will be actually exported - - Dispose(); } } diff --git a/src/Avalonia.FreeDesktop/DBusSystemTray/DBusSysTray.cs b/src/Avalonia.FreeDesktop/DBusSystemTray/DBusSysTray.cs index 8fd324e84c..dc5b98a41f 100644 --- a/src/Avalonia.FreeDesktop/DBusSystemTray/DBusSysTray.cs +++ b/src/Avalonia.FreeDesktop/DBusSystemTray/DBusSysTray.cs @@ -55,9 +55,9 @@ namespace Avalonia.FreeDesktop.DBusSystemTray } } - public void SetIcon(Pixmap pixmap) + public void SetIcon(DbusPixmap dbusPixmap) { - _statusNotifierItemDbusObj.SetIcon(pixmap); + _statusNotifierItemDbusObj.SetIcon(dbusPixmap); } public void SetTitleAndTooltip(string text) @@ -70,7 +70,7 @@ namespace Avalonia.FreeDesktop.DBusSystemTray _statusNotifierItemDbusObj.ActivationDelegate = activationDelegate; } } - + /// /// DBus Object used for setting system tray icons. /// @@ -90,7 +90,7 @@ namespace Avalonia.FreeDesktop.DBusSystemTray public Action NewStatusAsync { get; set; } public Action ActivationDelegate { get; set; } public ObjectPath ObjectPath { get; } - + public StatusNotifierItemDbusObj() { var ID = Guid.NewGuid().ToString().Replace("-", ""); @@ -102,10 +102,11 @@ namespace Avalonia.FreeDesktop.DBusSystemTray _backingProperties = new StatusNotifierItemProperties { - Menu = "/MenuBar", // Needs a dbus menu somehow - ItemIsMenu = false, + Menu = dbusmenuPath, // Needs a dbus menu somehow ToolTip = new ToolTip("") }; + + InvalidateAll(); } public async Task ContextMenuAsync(int X, int Y) @@ -139,7 +140,7 @@ namespace Avalonia.FreeDesktop.DBusSystemTray OnTitleChanged += handler; return Disposable.Create(() => OnTitleChanged -= handler); } - + public async Task WatchNewIconAsync(Action handler, Action onError = null) { OnIconChanged += handler; @@ -151,7 +152,7 @@ namespace Avalonia.FreeDesktop.DBusSystemTray OnAttentionIconChanged += handler; return Disposable.Create(() => OnAttentionIconChanged -= handler); } - + public async Task WatchNewOverlayIconAsync(Action handler, Action onError = null) { OnOverlayIconChanged += handler; @@ -172,6 +173,10 @@ namespace Avalonia.FreeDesktop.DBusSystemTray public async Task GetAsync(string prop) { + if (prop.Contains("Menu")) + { + return _backingProperties.Menu; + } return default; } @@ -188,9 +193,9 @@ namespace Avalonia.FreeDesktop.DBusSystemTray return Disposable.Create(() => OnPropertyChange -= handler); } - public void SetIcon(Pixmap pixmap) + public void SetIcon(DbusPixmap dbusPixmap) { - _backingProperties.IconPixmap = new[] { pixmap }; + _backingProperties.IconPixmap = new[] { dbusPixmap }; InvalidateAll(); } @@ -211,43 +216,8 @@ namespace Avalonia.FreeDesktop.DBusSystemTray { Task RegisterStatusNotifierItemAsync(string Service); Task RegisterStatusNotifierHostAsync(string Service); - - Task WatchStatusNotifierItemRegisteredAsync(Action handler, - Action onError = null); - - Task WatchStatusNotifierItemUnregisteredAsync(Action handler, - Action onError = null); - - Task WatchStatusNotifierHostRegisteredAsync(Action handler, Action onError = null); - Task GetAsync(string prop); - Task GetAllAsync(); - Task SetAsync(string prop, object val); - Task WatchPropertiesAsync(Action handler); } - [Dictionary] - internal class StatusNotifierWatcherProperties - { - public string[] RegisteredStatusNotifierItems; - - public bool IsStatusNotifierHostRegistered; - - public int ProtocolVersion; - } - - internal static class StatusNotifierWatcherExtensions - { - public static Task GetRegisteredStatusNotifierItemsAsync(this IStatusNotifierWatcher o) => - o.GetAsync("RegisteredStatusNotifierItems"); - - public static Task GetIsStatusNotifierHostRegisteredAsync(this IStatusNotifierWatcher o) => - o.GetAsync("IsStatusNotifierHostRegistered"); - - public static Task GetProtocolVersionAsync(this IStatusNotifierWatcher o) => - o.GetAsync("ProtocolVersion"); - } - - [DBusInterface("org.kde.StatusNotifierItem")] interface IStatusNotifierItem : IDBusObject { @@ -267,7 +237,6 @@ namespace Avalonia.FreeDesktop.DBusSystemTray Task WatchPropertiesAsync(Action handler); } - [Dictionary] internal class StatusNotifierItemProperties { @@ -289,40 +258,38 @@ namespace Avalonia.FreeDesktop.DBusSystemTray public string IconName; - public Pixmap[] IconPixmap; + public DbusPixmap[] IconPixmap; public string OverlayIconName; - public Pixmap[] OverlayIconPixmap; + public DbusPixmap[] OverlayIconPixmap; public string AttentionIconName; - public Pixmap[] AttentionIconPixmap; + public DbusPixmap[] AttentionIconPixmap; public string AttentionMovieName; public ToolTip ToolTip; } - public struct ToolTip + internal struct ToolTip { public readonly string First; - public readonly Pixmap[] Second; + public readonly DbusPixmap[] Second; public readonly string Third; public readonly string Fourth; - private static readonly Pixmap[] s_blankPixmaps = + private static readonly DbusPixmap[] s_blank = { - new Pixmap(0, 0, new byte[] { }), - new Pixmap(0, 0, new byte[] { }) + new DbusPixmap(0, 0, new byte[] { }), new DbusPixmap(0, 0, new byte[] { }) }; - - public ToolTip(string message) : this("", s_blankPixmaps, message, "") + + public ToolTip(string message) : this("", s_blank, message, "") { - } - - public ToolTip(string first, Pixmap[] second, string third, string fourth) + + public ToolTip(string first, DbusPixmap[] second, string third, string fourth) { First = first; Second = second; @@ -331,13 +298,13 @@ namespace Avalonia.FreeDesktop.DBusSystemTray } } - public readonly struct Pixmap + public readonly struct DbusPixmap { public readonly int Width; public readonly int Height; public readonly byte[] Data; - public Pixmap(int width, int height, byte[] data) + public DbusPixmap(int width, int height, byte[] data) { Width = width; Height = height; diff --git a/src/Avalonia.X11/X11TrayIconImpl.cs b/src/Avalonia.X11/X11TrayIconImpl.cs index 0971ee51ee..74aae49606 100644 --- a/src/Avalonia.X11/X11TrayIconImpl.cs +++ b/src/Avalonia.X11/X11TrayIconImpl.cs @@ -7,16 +7,16 @@ using Avalonia.Platform; namespace Avalonia.X11 { - class X11TrayIconImpl : ITrayIconImpl + internal class X11TrayIconImpl : ITrayIconImpl { - public INativeMenuExporter MenuExporter { get; } - public Action OnClicked { get; set; } - + private readonly DBusSysTray _dBusSysTray; - private X11IconData lastIcon; + + public INativeMenuExporter MenuExporter { get; } + public Action OnClicked { get; set; } - + public X11TrayIconImpl() { _dBusSysTray = new DBusSysTray(); @@ -53,7 +53,7 @@ namespace Avalonia.X11 pixByteArray[pixByteArrayCounter++] = (byte)(u & 0xFF); } - _dBusSysTray.SetIcon(new Pixmap(w, h, pixByteArray)); + _dBusSysTray.SetIcon(new DbusPixmap(w, h, pixByteArray)); _dBusSysTray.SetActivationDelegate(() => { @@ -69,7 +69,7 @@ namespace Avalonia.X11 } else { - _dBusSysTray.SetIcon(new Pixmap(1, 1, new byte[] { 0, 0, 0, 0 })); + _dBusSysTray.SetIcon(new DbusPixmap(1, 1, new byte[] { 0, 0, 0, 0 })); } }