From b4b3b913f1f700c0aea700f5d85667eeff4cf400 Mon Sep 17 00:00:00 2001
From: affederaffe <68356204+affederaffe@users.noreply.github.com>
Date: Mon, 13 Mar 2023 21:04:01 +0100
Subject: [PATCH 1/3] Use Tmds.DBus.SourceGenerator 0.0.3
---
.../Avalonia.FreeDesktop.csproj | 2 +-
src/Avalonia.FreeDesktop/DBusMenuExporter.cs | 43 +++++++++++--------
src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs | 21 +++++----
3 files changed, 35 insertions(+), 31 deletions(-)
diff --git a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
index 8791efd313..19de358abb 100644
--- a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
+++ b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs
index d08828f796..06e085e4d5 100644
--- a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs
+++ b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs
@@ -60,38 +60,43 @@ namespace Avalonia.FreeDesktop
public override string Path { get; }
- protected override (uint revision, (int, Dictionary, DBusVariantItem[]) layout) OnGetLayout(int parentId, int recursionDepth, string[] propertyNames)
- {
- var menu = GetMenu(parentId);
- var layout = GetLayout(menu.item, menu.menu, recursionDepth, propertyNames);
- if (!IsNativeMenuExported)
+ protected override async ValueTask<(uint revision, (int, Dictionary, DBusVariantItem[]) layout)> OnGetLayoutAsync(int parentId, int recursionDepth, string[]? propertyNames) =>
+ await Dispatcher.UIThread.InvokeAsync(() =>
{
- IsNativeMenuExported = true;
- Dispatcher.UIThread.Post(() => OnIsNativeMenuExportedChanged?.Invoke(this, EventArgs.Empty));
- }
+ var menu = GetMenu(parentId);
+ var layout = GetLayout(menu.item, menu.menu, recursionDepth, propertyNames);
+ if (!IsNativeMenuExported)
+ {
+ IsNativeMenuExported = true;
+ OnIsNativeMenuExportedChanged?.Invoke(this, EventArgs.Empty);
+ }
- return (_revision, layout);
- }
+ return (_revision, layout);
+ });
- protected override (int, Dictionary)[] OnGetGroupProperties(int[] ids, string[] propertyNames) =>
- ids.Select(id => (id, GetProperties(GetMenu(id), propertyNames))).ToArray();
+ protected override async ValueTask<(int, Dictionary)[]> OnGetGroupPropertiesAsync(int[] ids, string[] propertyNames) =>
+ await Dispatcher.UIThread.InvokeAsync(() => ids.Select(id => (id, GetProperties(GetMenu(id), propertyNames))).ToArray());
- protected override DBusVariantItem OnGetProperty(int id, string name) => GetProperty(GetMenu(id), name) ?? new DBusVariantItem("i", new DBusInt32Item(0));
+ protected override async ValueTask OnGetPropertyAsync(int id, string name) =>
+ await Dispatcher.UIThread.InvokeAsync(() => GetProperty(GetMenu(id), name) ?? new DBusVariantItem("i", new DBusInt32Item(0)));
- protected override void OnEvent(int id, string eventId, DBusVariantItem data, uint timestamp) =>
+ protected override ValueTask OnEventAsync(int id, string eventId, DBusVariantItem data, uint timestamp)
+ {
Dispatcher.UIThread.Post(() => HandleEvent(id, eventId));
+ return new ValueTask();
+ }
- protected override int[] OnEventGroup((int, string, DBusVariantItem, uint)[] events)
+ protected override ValueTask OnEventGroupAsync((int, string, DBusVariantItem, uint)[] events)
{
foreach (var e in events)
Dispatcher.UIThread.Post(() => HandleEvent(e.Item1, e.Item2));
- return Array.Empty();
+ return new ValueTask(Array.Empty());
}
- protected override bool OnAboutToShow(int id) => false;
+ protected override ValueTask OnAboutToShowAsync(int id) => new(false);
- protected override (int[] updatesNeeded, int[] idErrors) OnAboutToShowGroup(int[] ids) =>
- (Array.Empty(), Array.Empty());
+ protected override ValueTask<(int[] updatesNeeded, int[] idErrors)> OnAboutToShowGroupAsync(int[] ids) =>
+ new((Array.Empty(), Array.Empty()));
private async Task InitializeAsync()
{
diff --git a/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs b/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs
index afbee77067..fed8b87bc9 100644
--- a/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs
+++ b/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs
@@ -1,8 +1,10 @@
using System;
using System.Diagnostics;
+using System.Threading.Tasks;
using Avalonia.Controls.Platform;
using Avalonia.Logging;
using Avalonia.Platform;
+using Avalonia.Threading;
using Tmds.DBus.Protocol;
using Tmds.DBus.SourceGenerator;
@@ -219,13 +221,6 @@ namespace Avalonia.FreeDesktop
Connection = connection;
BackingProperties.Menu = dbusMenuPath;
BackingProperties.ToolTip = (string.Empty, Array.Empty<(int, int, byte[])>(), string.Empty, string.Empty);
- BackingProperties.IconName = string.Empty;
- BackingProperties.AttentionIconName = string.Empty;
- BackingProperties.AttentionIconPixmap = new []{ DBusTrayIconImpl.EmptyPixmap };
- BackingProperties.AttentionMovieName = string.Empty;
- BackingProperties.IconThemePath = string.Empty;
- BackingProperties.OverlayIconName = string.Empty;
- BackingProperties.OverlayIconPixmap = new []{ DBusTrayIconImpl.EmptyPixmap };
InvalidateAll();
}
@@ -235,13 +230,17 @@ namespace Avalonia.FreeDesktop
public event Action? ActivationDelegate;
- protected override void OnContextMenu(int x, int y) { }
+ protected override ValueTask OnContextMenuAsync(int x, int y) => new();
- protected override void OnActivate(int x, int y) => ActivationDelegate?.Invoke();
+ protected override ValueTask OnActivateAsync(int x, int y)
+ {
+ Dispatcher.UIThread.Post(() => ActivationDelegate?.Invoke());
+ return new ValueTask();
+ }
- protected override void OnSecondaryActivate(int x, int y) { }
+ protected override ValueTask OnSecondaryActivateAsync(int x, int y) => new();
- protected override void OnScroll(int delta, string orientation) { }
+ protected override ValueTask OnScrollAsync(int delta, string orientation) => new();
public void InvalidateAll()
{
From 46fc6ff99c85c13d86524bcb5b80e27bce6988d7 Mon Sep 17 00:00:00 2001
From: robloo
Date: Tue, 14 Mar 2023 13:38:24 -0400
Subject: [PATCH 2/3] Fix Menu Popup placement
---
src/Avalonia.Themes.Fluent/Controls/Menu.xaml | 1 +
src/Avalonia.Themes.Simple/Controls/Menu.xaml | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/Avalonia.Themes.Fluent/Controls/Menu.xaml b/src/Avalonia.Themes.Fluent/Controls/Menu.xaml
index 692bac958a..039482d70f 100644
--- a/src/Avalonia.Themes.Fluent/Controls/Menu.xaml
+++ b/src/Avalonia.Themes.Fluent/Controls/Menu.xaml
@@ -37,6 +37,7 @@
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
IsLightDismissEnabled="True"
IsOpen="{TemplateBinding IsSubMenuOpen, Mode=TwoWay}"
+ PlacementMode="BottomEdgeAlignedLeft"
OverlayInputPassThroughElement="{Binding $parent[Menu]}">
Date: Wed, 15 Mar 2023 00:50:18 +0100
Subject: [PATCH 3/3] Use Tmds.DBus.SourceGenerator 0.0.4
---
.../Avalonia.FreeDesktop.csproj | 2 +-
src/Avalonia.FreeDesktop/DBusMenuExporter.cs | 33 +++++++++----------
2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
index 19de358abb..da9add1fa4 100644
--- a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
+++ b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs
index 06e085e4d5..3073ea580c 100644
--- a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs
+++ b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs
@@ -60,36 +60,35 @@ namespace Avalonia.FreeDesktop
public override string Path { get; }
- protected override async ValueTask<(uint revision, (int, Dictionary, DBusVariantItem[]) layout)> OnGetLayoutAsync(int parentId, int recursionDepth, string[]? propertyNames) =>
- await Dispatcher.UIThread.InvokeAsync(() =>
+ protected override ValueTask<(uint revision, (int, Dictionary, DBusVariantItem[]) layout)> OnGetLayoutAsync(int parentId, int recursionDepth, string[] propertyNames)
+ {
+ var menu = GetMenu(parentId);
+ var layout = GetLayout(menu.item, menu.menu, recursionDepth, propertyNames);
+ if (!IsNativeMenuExported)
{
- var menu = GetMenu(parentId);
- var layout = GetLayout(menu.item, menu.menu, recursionDepth, propertyNames);
- if (!IsNativeMenuExported)
- {
- IsNativeMenuExported = true;
- OnIsNativeMenuExportedChanged?.Invoke(this, EventArgs.Empty);
- }
+ IsNativeMenuExported = true;
+ OnIsNativeMenuExportedChanged?.Invoke(this, EventArgs.Empty);
+ }
- return (_revision, layout);
- });
+ return new ValueTask<(uint, (int, Dictionary, DBusVariantItem[]))>((_revision, layout));
+ }
- protected override async ValueTask<(int, Dictionary)[]> OnGetGroupPropertiesAsync(int[] ids, string[] propertyNames) =>
- await Dispatcher.UIThread.InvokeAsync(() => ids.Select(id => (id, GetProperties(GetMenu(id), propertyNames))).ToArray());
+ protected override ValueTask<(int, Dictionary)[]> OnGetGroupPropertiesAsync(int[] ids, string[] propertyNames)
+ => new(ids.Select(id => (id, GetProperties(GetMenu(id), propertyNames))).ToArray());
- protected override async ValueTask OnGetPropertyAsync(int id, string name) =>
- await Dispatcher.UIThread.InvokeAsync(() => GetProperty(GetMenu(id), name) ?? new DBusVariantItem("i", new DBusInt32Item(0)));
+ protected override ValueTask OnGetPropertyAsync(int id, string name) =>
+ new(GetProperty(GetMenu(id), name) ?? new DBusVariantItem("i", new DBusInt32Item(0)));
protected override ValueTask OnEventAsync(int id, string eventId, DBusVariantItem data, uint timestamp)
{
- Dispatcher.UIThread.Post(() => HandleEvent(id, eventId));
+ HandleEvent(id, eventId);
return new ValueTask();
}
protected override ValueTask OnEventGroupAsync((int, string, DBusVariantItem, uint)[] events)
{
foreach (var e in events)
- Dispatcher.UIThread.Post(() => HandleEvent(e.Item1, e.Item2));
+ HandleEvent(e.Item1, e.Item2);
return new ValueTask(Array.Empty());
}