diff --git a/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj b/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj
index 9607a10d8..21c5abd88 100644
--- a/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj
+++ b/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj
@@ -16,11 +16,11 @@
-
-
+
+
-
-
+
+
diff --git a/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj b/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj
index e674a2ad6..9e2fc0938 100644
--- a/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj
+++ b/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj
@@ -15,11 +15,11 @@
-
-
+
+
-
-
+
+
diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj
index 0c4439627..c0c66255d 100644
--- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj
+++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj
@@ -10,14 +10,14 @@
-
+
-
-
-
+
+
+
-
-
+
+
diff --git a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs
index 1b3124421..fd3352add 100644
--- a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs
+++ b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
@@ -68,7 +69,7 @@ public partial class DraggableNumberBox : UserControl
public DraggableNumberBox()
{
InitializeComponent();
-
+
PointerPressed += OnPointerPressed;
PointerMoved += OnPointerMoved;
PointerReleased += OnPointerReleased;
@@ -186,8 +187,9 @@ public partial class DraggableNumberBox : UserControl
private void HandleKeyUp(object? sender, KeyEventArgs e)
{
+ IInputElement? toFocus = this.GetLogicalAncestors().OfType().LastOrDefault();
if (e.Key == Key.Enter || e.Key == Key.Escape)
- FocusManager.Instance?.Focus(Parent as IInputElement);
+ toFocus?.Focus();
}
private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
@@ -215,7 +217,7 @@ public partial class DraggableNumberBox : UserControl
if (!_moved)
{
// Let our parent take focus, it would make more sense to take focus ourselves but that hides the collider
- FocusManager.Instance?.Focus(Parent as IInputElement);
+ (Parent as IInputElement)?.Focus();
_moved = true;
e.Pointer.Capture(this);
DragStarted?.Invoke(this, EventArgs.Empty);
diff --git a/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs b/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs
index 0448f9746..d5d02c63e 100644
--- a/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs
+++ b/src/Artemis.UI.Shared/Controls/HotkeyBox.axaml.cs
@@ -9,6 +9,7 @@ using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
+using Avalonia.VisualTree;
using DryIoc;
using FluentAvalonia.Core;
using Humanizer;
@@ -78,7 +79,7 @@ public partial class HotkeyBox : UserControl
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
{
if (e.Modifiers == KeyboardModifierKey.None)
- Dispatcher.UIThread.Post(() => FocusManager.Instance?.Focus(null));
+ Dispatcher.UIThread.Post(() => this.FindAncestorOfType()?.Focus());
}
private void UpdateDisplayTextBox()
@@ -96,7 +97,7 @@ public partial class HotkeyBox : UserControl
private void Button_OnClick(object? sender, RoutedEventArgs e)
{
Hotkey = null;
- FocusManager.Instance?.Focus(null);
+ this.FindAncestorOfType()?.Focus();
UpdateDisplayTextBox();
}
diff --git a/src/Artemis.UI.Shared/ReactiveAppWindow.cs b/src/Artemis.UI.Shared/ReactiveAppWindow.cs
index 58f4ad820..a751f4ee6 100644
--- a/src/Artemis.UI.Shared/ReactiveAppWindow.cs
+++ b/src/Artemis.UI.Shared/ReactiveAppWindow.cs
@@ -48,7 +48,7 @@ public class ReactiveAppWindow : AppWindow, IViewFor whe
return;
TransparencyBackgroundFallback = Brushes.Transparent;
- TransparencyLevelHint = WindowTransparencyLevel.Mica;
+ TransparencyLevelHint = new[] {WindowTransparencyLevel.Mica};
TryEnableMicaEffect();
}
diff --git a/src/Artemis.UI.Shared/Utilities.cs b/src/Artemis.UI.Shared/Utilities.cs
index cb2d58992..367e6b05c 100644
--- a/src/Artemis.UI.Shared/Utilities.cs
+++ b/src/Artemis.UI.Shared/Utilities.cs
@@ -1,7 +1,5 @@
using System;
-using System.ComponentModel;
using System.Reactive.Linq;
-using System.Reactive.Subjects;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Input.Platform;
@@ -14,12 +12,9 @@ namespace Artemis.UI.Shared;
///
public static class UI
{
- private static readonly BehaviorSubject KeyBindingsEnabledSubject = new(false);
-
static UI()
{
- if (KeyboardDevice.Instance != null)
- KeyboardDevice.Instance.PropertyChanged += InstanceOnPropertyChanged;
+ KeyBindingsEnabled = InputElement.GotFocusEvent.Raised.Select(e => e.Item2.Source is not TextBox);
}
///
@@ -35,15 +30,5 @@ public static class UI
///
/// Gets a boolean indicating whether hotkeys are to be disabled.
///
- public static IObservable KeyBindingsEnabled { get; } = KeyBindingsEnabledSubject.AsObservable();
-
- private static void InstanceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
- {
- if (KeyboardDevice.Instance == null || e.PropertyName != nameof(KeyboardDevice.FocusedElement))
- return;
-
- bool enabled = KeyboardDevice.Instance.FocusedElement is not TextBox;
- if (KeyBindingsEnabledSubject.Value != enabled)
- KeyBindingsEnabledSubject.OnNext(enabled);
- }
+ public static IObservable KeyBindingsEnabled { get; }
}
\ No newline at end of file
diff --git a/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj b/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj
index bdea0536c..3910a5e65 100644
--- a/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj
+++ b/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj
@@ -21,12 +21,12 @@
-
-
+
+
-
-
-
+
+
+
diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj
index ce2eaaf18..47da417f7 100644
--- a/src/Artemis.UI/Artemis.UI.csproj
+++ b/src/Artemis.UI/Artemis.UI.csproj
@@ -15,20 +15,20 @@
-
-
-
+
+
+
-
-
-
+
+
+
-
+
-
-
+
+
diff --git a/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs b/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs
index bd3845bfa..b23346427 100644
--- a/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs
+++ b/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs
@@ -103,8 +103,9 @@ public class SimpleContextDragBehavior : Behavior
private void AssociatedObject_PointerPressed(object? sender, PointerPressedEventArgs e)
{
+ IFocusManager? focusManager = TopLevel.GetTopLevel(AssociatedObject)?.FocusManager;
PointerPointProperties properties = e.GetCurrentPoint(AssociatedObject).Properties;
- if (!properties.IsLeftButtonPressed || FocusManager.Instance?.Current is TextBox)
+ if (!properties.IsLeftButtonPressed || focusManager?.GetFocusedElement() is TextBox)
return;
if (e.Source is not Control control || AssociatedObject?.DataContext != control.DataContext)
return;
@@ -130,8 +131,9 @@ public class SimpleContextDragBehavior : Behavior
private async void AssociatedObject_PointerMoved(object? sender, PointerEventArgs e)
{
+ IFocusManager? focusManager = TopLevel.GetTopLevel(AssociatedObject)?.FocusManager;
PointerPointProperties properties = e.GetCurrentPoint(AssociatedObject).Properties;
- if (!properties.IsLeftButtonPressed || FocusManager.Instance?.Current is TextBox)
+ if (!properties.IsLeftButtonPressed || focusManager?.GetFocusedElement() is TextBox)
return;
if (_triggerEvent is null)
diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs
index 1ef4838a8..9063787d5 100644
--- a/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs
+++ b/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs
@@ -1,5 +1,4 @@
using Avalonia.Input;
-using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.DefaultTypes.PropertyInput;
@@ -16,6 +15,6 @@ public partial class StringPropertyInputView : ReactiveUserControl
-