From a189f52bcbdb06bd50c3265a3636f5f11c07d40d Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Fri, 17 Sep 2021 15:01:43 +0800 Subject: [PATCH] testing stuff for now --- .../DBusSystemTray/SNIDBus.cs | 194 ++++++++++++++++++ src/Avalonia.X11/X11TrayIconImpl.cs | 7 +- 2 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs diff --git a/src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs b/src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs new file mode 100644 index 0000000000..a4bc659d20 --- /dev/null +++ b/src/Avalonia.FreeDesktop/DBusSystemTray/SNIDBus.cs @@ -0,0 +1,194 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using Tmds.DBus; + +[assembly: InternalsVisibleTo(Tmds.DBus.Connection.DynamicAssemblyName)] +namespace Avalonia.FreeDesktop.DBusSystemTray +{ + public class SNIDBus + { + public SNIDBus() + { + + } + + public async void Initialize() + { + + var serviceName = $"AvaloniaSNITest_{Guid.NewGuid()}"; + + var path = + Connection.Session.CreateProxy("org.kde.StatusNotifierWatcher", + "org.kde.StatusNotifierWatcher"); + await path.RegisterStatusNotifierHostAsync(serviceName); + + await path.WatchStatusNotifierHostRegisteredAsync(() => + { + + }, z => + { + + }); + + + + } + } + + [DBusInterface("org.kde.StatusNotifierWatcher")] + interface IStatusNotifierWatcher : IDBusObject + { + 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] + class StatusNotifierWatcherProperties + { + private string[] _RegisteredStatusNotifierItems = default(string[]); + public string[] RegisteredStatusNotifierItems + { + get + { + return _RegisteredStatusNotifierItems; + } + + set + { + _RegisteredStatusNotifierItems = (value); + } + } + + private bool _IsStatusNotifierHostRegistered = default(bool); + public bool IsStatusNotifierHostRegistered + { + get + { + return _IsStatusNotifierHostRegistered; + } + + set + { + _IsStatusNotifierHostRegistered = (value); + } + } + + private int _ProtocolVersion = default(int); + public int ProtocolVersion + { + get + { + return _ProtocolVersion; + } + + set + { + _ProtocolVersion = (value); + } + } + } + + 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.gtk.Actions")] + interface IActions : IDBusObject + { + Task ListAsync(); + Task<(bool description, Signature, object[])> DescribeAsync(string ActionName); + Task> DescribeAllAsync(); + Task ActivateAsync(string ActionName, object[] Parameter, IDictionary PlatformData); + Task SetStateAsync(string ActionName, object Value, IDictionary PlatformData); + Task WatchChangedAsync(Action<(string[] removals, IDictionary enableChanges, IDictionary stateChanges, IDictionary additions)> handler, Action onError = null); + } + + [DBusInterface("org.gtk.Application")] + interface IApplication : IDBusObject + { + Task ActivateAsync(IDictionary PlatformData); + Task OpenAsync(string[] Uris, string Hint, IDictionary PlatformData); + Task CommandLineAsync(ObjectPath Path, byte[][] Arguments, IDictionary PlatformData); + Task GetAsync(string prop); + Task GetAllAsync(); + Task SetAsync(string prop, object val); + Task WatchPropertiesAsync(Action handler); + } + + [Dictionary] + class ApplicationProperties + { + private bool _Busy = default(bool); + public bool Busy + { + get + { + return _Busy; + } + + set + { + _Busy = (value); + } + } + } + + static class ApplicationExtensions + { + public static Task GetBusyAsync(this IApplication o) => o.GetAsync("Busy"); + } + + [DBusInterface("org.freedesktop.Application")] + interface IApplication0 : IDBusObject + { + Task ActivateAsync(IDictionary PlatformData); + Task OpenAsync(string[] Uris, IDictionary PlatformData); + Task ActivateActionAsync(string ActionName, object[] Parameter, IDictionary PlatformData); + } + + [DBusInterface("org.gnome.Sysprof3.Profiler")] + interface IProfiler : IDBusObject + { + Task StartAsync(IDictionary Options, CloseSafeHandle Fd); + Task StopAsync(); + Task GetAsync(string prop); + Task GetAllAsync(); + Task SetAsync(string prop, object val); + Task WatchPropertiesAsync(Action handler); + } + + [Dictionary] + class ProfilerProperties + { + private IDictionary _Capabilities = default(IDictionary); + public IDictionary Capabilities + { + get + { + return _Capabilities; + } + + set + { + _Capabilities = (value); + } + } + } + + static class ProfilerExtensions + { + public static Task> GetCapabilitiesAsync(this IProfiler o) => o.GetAsync>("Capabilities"); + } +} diff --git a/src/Avalonia.X11/X11TrayIconImpl.cs b/src/Avalonia.X11/X11TrayIconImpl.cs index 8909a4604b..0ab34434fb 100644 --- a/src/Avalonia.X11/X11TrayIconImpl.cs +++ b/src/Avalonia.X11/X11TrayIconImpl.cs @@ -1,5 +1,6 @@ using System; using Avalonia.Controls.Platform; +using Avalonia.FreeDesktop.DBusSystemTray; using Avalonia.Platform; namespace Avalonia.X11 @@ -9,10 +10,12 @@ namespace Avalonia.X11 public INativeMenuExporter MenuExporter => null; public Action OnClicked { get; set; } - + private SNIDBus sni = new SNIDBus(); + public void Dispose() { + } public void SetIcon(IWindowIconImpl icon) @@ -27,7 +30,7 @@ namespace Avalonia.X11 public void SetToolTipText(string text) { - + sni.Initialize(); } } }