From 9777b9a5ee12f45cf99d4ae4f3f37717393b9c9b Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 15:01:31 +0300 Subject: [PATCH 1/8] fix --- .../Platform/DefaultMenuInteractionHandler.cs | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index 726d2c596c..dd3388b30e 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -99,7 +99,7 @@ namespace Avalonia.Controls.Platform { root.Deactivated -= WindowDeactivated; } - + if (_root is TopLevel tl) tl.PlatformImpl.LostFocus -= TopLevelLostPlatformFocus; @@ -148,116 +148,116 @@ namespace Avalonia.Controls.Platform { case Key.Up: case Key.Down: - { - if (item?.IsTopLevel == true) { - if (item.HasSubMenu && !item.IsSubMenuOpen) + if (item?.IsTopLevel == true) { - Open(item, true); - e.Handled = true; + if (item.HasSubMenu && !item.IsSubMenuOpen) + { + Open(item, true); + e.Handled = true; + } } + else + { + goto default; + } + break; } - else - { - goto default; - } - break; - } case Key.Left: - { - if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) { - parent.Close(); - parent.Focus(); - e.Handled = true; - } - else - { - goto default; + if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) + { + parent.Close(); + parent.Focus(); + e.Handled = true; + } + else + { + goto default; + } + break; } - break; - } case Key.Right: - { - if (item != null && !item.IsTopLevel && item.HasSubMenu) { - Open(item, true); - e.Handled = true; + if (item != null && !item.IsTopLevel && item.HasSubMenu) + { + Open(item, true); + e.Handled = true; + } + else + { + goto default; + } + break; } - else + + case Key.Enter: { - goto default; + if (item != null) + { + if (!item.HasSubMenu) + { + Click(item); + } + else + { + Open(item, true); + } + + e.Handled = true; + } + break; } - break; - } - case Key.Enter: - { - if (item != null) + case Key.Escape: { - if (!item.HasSubMenu) + if (item?.Parent is IMenuElement parent) { - Click(item); + parent.Close(); + parent.Focus(); } else { - Open(item, true); + Menu!.Close(); } e.Handled = true; + break; } - break; - } - - case Key.Escape: - { - if (item?.Parent is IMenuElement parent) - { - parent.Close(); - parent.Focus(); - } - else - { - Menu!.Close(); - } - - e.Handled = true; - break; - } default: - { - var direction = e.Key.ToNavigationDirection(); - - if (direction?.IsDirectional() == true) { - if (item == null && _isContextMenu) + var direction = e.Key.ToNavigationDirection(); + + if (direction?.IsDirectional() == true) { - if (Menu!.MoveSelection(direction.Value, true) == true) + if (item == null && _isContextMenu) { - e.Handled = true; + if (Menu!.MoveSelection(direction.Value, true) == true) + { + e.Handled = true; + } } - } - else if (item?.Parent?.MoveSelection(direction.Value, true) == true) - { - // If the the parent is an IMenu which successfully moved its selection, - // and the current menu is open then close the current menu and open the - // new menu. - if (item.IsSubMenuOpen && - item.Parent is IMenu && - item.Parent.SelectedItem is object) + else if (item?.Parent?.MoveSelection(direction.Value, true) == true) { - item.Close(); - Open(item.Parent.SelectedItem, true); + // If the the parent is an IMenu which successfully moved its selection, + // and the current menu is open then close the current menu and open the + // new menu. + if (item.IsSubMenuOpen && + item.Parent is IMenu && + item.Parent.SelectedItem is object) + { + item.Close(); + Open(item.Parent.SelectedItem, true); + } + e.Handled = true; } - e.Handled = true; } - } - break; - } + break; + } } if (!e.Handled && item?.Parent is IMenuItem parentItem) @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu) + if (item.HasSubMenu && item.IsEnabled) { Open(item, true); } @@ -441,7 +441,7 @@ namespace Avalonia.Controls.Platform { Menu?.Close(); } - + private void TopLevelLostPlatformFocus() { Menu?.Close(); From 63716e19d7988fc732b1c82c6edcea22ab1abbe8 Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 15:14:06 +0300 Subject: [PATCH 2/8] Revert "fix" This reverts commit 9777b9a5ee12f45cf99d4ae4f3f37717393b9c9b. --- .../Platform/DefaultMenuInteractionHandler.cs | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index dd3388b30e..726d2c596c 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -99,7 +99,7 @@ namespace Avalonia.Controls.Platform { root.Deactivated -= WindowDeactivated; } - + if (_root is TopLevel tl) tl.PlatformImpl.LostFocus -= TopLevelLostPlatformFocus; @@ -148,116 +148,116 @@ namespace Avalonia.Controls.Platform { case Key.Up: case Key.Down: + { + if (item?.IsTopLevel == true) { - if (item?.IsTopLevel == true) + if (item.HasSubMenu && !item.IsSubMenuOpen) { - if (item.HasSubMenu && !item.IsSubMenuOpen) - { - Open(item, true); - e.Handled = true; - } - } - else - { - goto default; + Open(item, true); + e.Handled = true; } - break; } + else + { + goto default; + } + break; + } case Key.Left: + { + if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) { - if (item?.Parent is IMenuItem parent && !parent.IsTopLevel && parent.IsSubMenuOpen) - { - parent.Close(); - parent.Focus(); - e.Handled = true; - } - else - { - goto default; - } - break; + parent.Close(); + parent.Focus(); + e.Handled = true; + } + else + { + goto default; } + break; + } case Key.Right: + { + if (item != null && !item.IsTopLevel && item.HasSubMenu) { - if (item != null && !item.IsTopLevel && item.HasSubMenu) - { - Open(item, true); - e.Handled = true; - } - else - { - goto default; - } - break; + Open(item, true); + e.Handled = true; } - - case Key.Enter: + else { - if (item != null) - { - if (!item.HasSubMenu) - { - Click(item); - } - else - { - Open(item, true); - } - - e.Handled = true; - } - break; + goto default; } + break; + } - case Key.Escape: + case Key.Enter: + { + if (item != null) { - if (item?.Parent is IMenuElement parent) + if (!item.HasSubMenu) { - parent.Close(); - parent.Focus(); + Click(item); } else { - Menu!.Close(); + Open(item, true); } e.Handled = true; - break; } + break; + } - default: + case Key.Escape: + { + if (item?.Parent is IMenuElement parent) { - var direction = e.Key.ToNavigationDirection(); + parent.Close(); + parent.Focus(); + } + else + { + Menu!.Close(); + } - if (direction?.IsDirectional() == true) + e.Handled = true; + break; + } + + default: + { + var direction = e.Key.ToNavigationDirection(); + + if (direction?.IsDirectional() == true) + { + if (item == null && _isContextMenu) { - if (item == null && _isContextMenu) + if (Menu!.MoveSelection(direction.Value, true) == true) { - if (Menu!.MoveSelection(direction.Value, true) == true) - { - e.Handled = true; - } + e.Handled = true; } - else if (item?.Parent?.MoveSelection(direction.Value, true) == true) + } + else if (item?.Parent?.MoveSelection(direction.Value, true) == true) + { + // If the the parent is an IMenu which successfully moved its selection, + // and the current menu is open then close the current menu and open the + // new menu. + if (item.IsSubMenuOpen && + item.Parent is IMenu && + item.Parent.SelectedItem is object) { - // If the the parent is an IMenu which successfully moved its selection, - // and the current menu is open then close the current menu and open the - // new menu. - if (item.IsSubMenuOpen && - item.Parent is IMenu && - item.Parent.SelectedItem is object) - { - item.Close(); - Open(item.Parent.SelectedItem, true); - } - e.Handled = true; + item.Close(); + Open(item.Parent.SelectedItem, true); } + e.Handled = true; } - - break; } + + break; + } } if (!e.Handled && item?.Parent is IMenuItem parentItem) @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu && item.IsEnabled) + if (item.HasSubMenu) { Open(item, true); } @@ -441,7 +441,7 @@ namespace Avalonia.Controls.Platform { Menu?.Close(); } - + private void TopLevelLostPlatformFocus() { Menu?.Close(); From a13e9c1c1c932a124513a478ae8493203fdf4782 Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 15:14:29 +0300 Subject: [PATCH 3/8] fix --- src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index 726d2c596c..cde78ae839 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu) + if (item.HasSubMenu && item.IsEnabled) { Open(item, true); } From cfc50e45f54b5ea7727ec07cb17413011771c76f Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 23 Sep 2021 16:37:18 +0300 Subject: [PATCH 4/8] upd --- src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs index cde78ae839..e361e7b736 100644 --- a/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs +++ b/src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs @@ -275,7 +275,7 @@ namespace Avalonia.Controls.Platform return; } - if (item.HasSubMenu && item.IsEnabled) + if (item.HasSubMenu && item.IsEffectivelyEnabled) { Open(item, true); } From d56715b38858978d3b4a0a0d1a854415b800fbd0 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Sun, 26 Sep 2021 23:52:30 +0300 Subject: [PATCH 5/8] Used EqualityComparer.Default to check values for equality --- src/Avalonia.Visuals/Media/FormattedText.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Media/FormattedText.cs b/src/Avalonia.Visuals/Media/FormattedText.cs index a843be4c4b..ddffbe7500 100644 --- a/src/Avalonia.Visuals/Media/FormattedText.cs +++ b/src/Avalonia.Visuals/Media/FormattedText.cs @@ -200,7 +200,7 @@ namespace Avalonia.Media private void Set(ref T field, T value) { - if (field != null && field.Equals(value)) + if (EqualityComparer.Default.Equals(field, value)) { return; } From d60d96e554fcdaa29b5450bda36e116dee0aba3a Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 28 Sep 2021 01:57:56 +0800 Subject: [PATCH 6/8] fix x11 deferred renderer performance regression --- src/Avalonia.X11/X11Window.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Avalonia.X11/X11Window.cs b/src/Avalonia.X11/X11Window.cs index f0d2d5ca8a..14645bc415 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/src/Avalonia.X11/X11Window.cs @@ -192,11 +192,6 @@ namespace Avalonia.X11 if (platform.Options.UseDBusMenu) NativeMenuExporter = DBusMenuExporter.TryCreate(_handle); NativeControlHost = new X11NativeControlHost(_platform, this); - DispatcherTimer.Run(() => - { - Paint?.Invoke(default); - return _handle != IntPtr.Zero; - }, TimeSpan.FromMilliseconds(100)); InitializeIme(); } From 49e23bc07ff46d27bb2020d1ae04be654af81ab2 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 28 Sep 2021 12:06:59 +0200 Subject: [PATCH 7/8] Use IRendererFactory in framebuffer backend. If an `IRendererFactory` is provided, use this to supply the renderer; otherwise fall back to the existing `DeferredRenderer`. --- .../Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs b/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs index b097e0917f..8688671d3b 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs @@ -30,10 +30,9 @@ namespace Avalonia.LinuxFramebuffer public IRenderer CreateRenderer(IRenderRoot root) { - return new DeferredRenderer(root, AvaloniaLocator.Current.GetService()) - { - - }; + var factory = AvaloniaLocator.Current.GetService(); + var renderLoop = AvaloniaLocator.Current.GetService(); + return factory?.Create(root, renderLoop) ?? new DeferredRenderer(root, renderLoop); } public void Dispose() @@ -41,7 +40,7 @@ namespace Avalonia.LinuxFramebuffer throw new NotSupportedException(); } - + public void Invalidate(Rect rect) { } From 23dcab47d4461d54bed91eec470c30f74e062843 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 28 Sep 2021 12:41:11 +0200 Subject: [PATCH 8/8] Allow customizing the framebuffer FPS. --- .../LinuxFramebufferPlatform.cs | 6 ++++-- .../LinuxFramebufferPlatformOptions.cs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatformOptions.cs diff --git a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs index 7fb601eb62..f4db6bf48a 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs @@ -37,15 +37,17 @@ namespace Avalonia.LinuxFramebuffer Threading = new InternalPlatformThreadingInterface(); if (_fb is IGlOutputBackend gl) AvaloniaLocator.CurrentMutable.Bind().ToConstant(gl.PlatformOpenGlInterface); + + var opts = AvaloniaLocator.Current.GetService(); + AvaloniaLocator.CurrentMutable .Bind().ToConstant(Threading) - .Bind().ToConstant(new DefaultRenderTimer(60)) + .Bind().ToConstant(new DefaultRenderTimer(opts?.Fps ?? 60)) .Bind().ToConstant(new RenderLoop()) .Bind().ToTransient() .Bind().ToConstant(new KeyboardDevice()) .Bind().ToSingleton() .Bind().ToSingleton(); - } diff --git a/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatformOptions.cs b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatformOptions.cs new file mode 100644 index 0000000000..bf925bbd75 --- /dev/null +++ b/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatformOptions.cs @@ -0,0 +1,14 @@ +namespace Avalonia.LinuxFramebuffer +{ + /// + /// Platform-specific options which apply to the Linux framebuffer. + /// + public class LinuxFramebufferPlatformOptions + { + /// + /// Gets or sets the number of frames per second at which the renderer should run. + /// Default 60. + /// + public int Fps { get; set; } = 60; + } +}