1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

HotkeyBox - Focus fixes

This commit is contained in:
Robert 2023-06-06 20:17:30 +02:00
parent aa4a740b78
commit 34824dde42

View File

@ -41,7 +41,7 @@ public partial class HotkeyBox : UserControl
{ {
_inputService.KeyboardKeyDown += InputServiceOnKeyboardKeyDown; _inputService.KeyboardKeyDown += InputServiceOnKeyboardKeyDown;
_inputService.KeyboardKeyUp += InputServiceOnKeyboardKeyUp; _inputService.KeyboardKeyUp += InputServiceOnKeyboardKeyUp;
base.OnGotFocus(e); base.OnGotFocus(e);
} }
@ -50,10 +50,10 @@ public partial class HotkeyBox : UserControl
{ {
_inputService.KeyboardKeyDown -= InputServiceOnKeyboardKeyDown; _inputService.KeyboardKeyDown -= InputServiceOnKeyboardKeyDown;
_inputService.KeyboardKeyUp -= InputServiceOnKeyboardKeyUp; _inputService.KeyboardKeyUp -= InputServiceOnKeyboardKeyUp;
base.OnLostFocus(e); base.OnLostFocus(e);
} }
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{ {
if (e.Property == HotkeyProperty) if (e.Property == HotkeyProperty)
@ -68,7 +68,7 @@ public partial class HotkeyBox : UserControl
Hotkey ??= new Hotkey(); Hotkey ??= new Hotkey();
Hotkey.Key = e.Key; Hotkey.Key = e.Key;
Hotkey.Modifiers = e.Modifiers; Hotkey.Modifiers = e.Modifiers;
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Post(() =>
{ {
UpdateDisplayTextBox(); UpdateDisplayTextBox();
@ -79,7 +79,19 @@ public partial class HotkeyBox : UserControl
private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e) private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e)
{ {
if (e.Modifiers == KeyboardModifierKey.None) if (e.Modifiers == KeyboardModifierKey.None)
Dispatcher.UIThread.Post(() => this.FindAncestorOfType<InputElement>()?.Focus()); Dispatcher.UIThread.Post(ClearFocus);
}
private void ClearFocus()
{
InputElement? element = this.FindAncestorOfType<InputElement>();
if (element == null)
return;
bool wasFocusable = element.Focusable;
element.Focusable = true;
element.Focus();
element.Focusable = wasFocusable;
} }
private void UpdateDisplayTextBox() private void UpdateDisplayTextBox()
@ -97,7 +109,7 @@ public partial class HotkeyBox : UserControl
private void Button_OnClick(object? sender, RoutedEventArgs e) private void Button_OnClick(object? sender, RoutedEventArgs e)
{ {
Hotkey = null; Hotkey = null;
this.FindAncestorOfType<InputElement>()?.Focus(); ClearFocus();
UpdateDisplayTextBox(); UpdateDisplayTextBox();
} }