Skip to content

linux: focus follows window activation - #98

Draft
sduguay-devolutions wants to merge 2 commits into
AvaloniaUI:mainfrom
Devolutions:fix/focus-follows-window-activation
Draft

sduguay-devolutions wants to merge 2 commits into
AvaloniaUI:mainfrom
Devolutions:fix/focus-follows-window-activation

Conversation

@sduguay-devolutions

Copy link
Copy Markdown
Contributor

Issue

Related to #85

Click into another application and the web view act as if it still had focus.
The text caret keeps blinking and the page still reports document.hasFocus() true.

Focus only ever reached the adapter through the control's OnGotFocus and OnLostFocus,
which follow Avalonia's logical focus inside the window. Avalonia leaves that focus on
the control when the window is deactivated and ResignFocus is never
called.

Fix

Follow the top level's activation as well as the control's focus. On attach we take
TopLevel.GetTopLevel(this) as WindowBase and listen for Activated and Deactivated,
resigning focus on the way out and taking it back on the way in, in both cases only
while the control actually holds focus. Unsubscribed on detach, and re-resolved if the
control is attached somewhere else.

Verified on both Linux adapters, offscreen and native X11.

One thing to know

sduguay-devolutions and others added 2 commits September 30, 2026 10:49
Focus reached the native web view only through the control's OnGotFocus and
OnLostFocus, which follow Avalonia's logical focus inside the window. Avalonia
leaves that focus on the control while the window is deactivated, so the adapter
was never told, and a GTK toplevel that is offscreen or reparented into another
window never hears from the window manager either. The focus synthesized for the
caret therefore stood while the user worked in another application: the caret
went on blinking and the page still reported document.hasFocus().

Follow the top level's activation as well, resigning while the control holds
focus and taking it back when the window is activated again.
@sduguay-devolutions sduguay-devolutions changed the title Fix/focus follows window activation linux: focus follows window activation Oct 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant