Skip to content

Commit

Permalink
Addressed review
Browse files Browse the repository at this point in the history
  • Loading branch information
kekekeks committed Dec 16, 2024
1 parent 6efaff7 commit c6b10c9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Avalonia.X11/X11WindowModes/XEmbedClientWindowMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class XEmbedClientWindowMode : X11WindowMode
EmbeddableControlRoot? Root => Window._inputRoot as EmbeddableControlRoot;
private bool _focusedInEmbedder;
private bool _embedderActivated;
private IInputElement? _savedFocus;
private bool _disabled;
private IntPtr _currentEmbedder;
private bool _suppressConfigureEvents;
Expand All @@ -25,6 +24,14 @@ public double Scaling
get => Window._scalingOverride ?? 1;
set => Window._scalingOverride = value;
}

private WeakReference<IInputElement>? _savedFocus;

private IInputElement? SavedFocus
{
get => _savedFocus?.TryGetTarget(out var target) == true ? target : null;
set => _savedFocus = value == null ? null : new WeakReference<IInputElement>(value);
}

public override void OnHandleCreated(IntPtr handle)
{
Expand Down Expand Up @@ -76,7 +83,7 @@ static XEmbedClientWindowMode()
&& window._mode is XEmbedClientWindowMode xembedMode
&& xembedMode._currentEmbedder != IntPtr.Zero)
{
xembedMode._savedFocus = KeyboardDevice.Instance.FocusedElement;
xembedMode.SavedFocus = KeyboardDevice.Instance.FocusedElement;
xembedMode.SendXEmbedMessage(XEmbedMessage.RequestFocus);
}
}
Expand Down Expand Up @@ -131,13 +138,12 @@ private void UpdateActivation()
if (active)
{
((FocusManager?)Root?.FocusManager)?.SetFocusScope(Root);
if (_savedFocus != null)
KeyboardDevice.Instance?.SetFocusedElement(_savedFocus, NavigationMethod.Unspecified, KeyModifiers.None);
_savedFocus = null;
SavedFocus?.Focus();
SavedFocus = null;
}
else
{
_savedFocus = Root?.IsKeyboardFocusWithin == true ? Root.FocusManager?.GetFocusedElement() : null;
SavedFocus = Root?.IsKeyboardFocusWithin == true ? Root.FocusManager?.GetFocusedElement() : null;
Window.LostFocus?.Invoke();
}
}
Expand Down

0 comments on commit c6b10c9

Please sign in to comment.