Skip to content

fix(wasm): Stuck and flickering keyboard modifier state (6.8) (backport #25155) - #25775

Merged
agneszitte merged 8 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-25155
Oct 28, 2026
Merged

agneszitte merged 8 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-25155

Conversation

@mergify

@mergify mergify Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: unoplatform/kahua-private#545 (backport of #24575)

PR Type:

🐞 Bugfix

What changed? 🚀

Backport of #24575 to 6.8. All 8 commits are cherry-picked with -x.

KeyboardStateTracker kept modifier state in a persistent dictionary, updated only by matched key down/key up pairs. That caused two bugs on WebAssembly:

  • Stuck modifiers after a focus steal. A modifier whose key up never reached the page stayed Down for the rest of the session. Opening dev tools with Ctrl+Shift+I reliably triggers this. CoreWindow.GetKeyState then reported Ctrl as held, so a DataGrid treated plain arrows as Ctrl+Arrow.
  • Locked flickering during auto-repeat. Locked was toggled on every key down, and a held key repeats key downs with no key up in between.

The fixes, the same as #24575:

  • Track only the Down state.
  • Resync the modifiers from the flags carried by key events, and on WebAssembly from pointer events too.
  • Report window activation and page visibility on WebAssembly.
  • Raise a key up for the soft keyboard's Enter key.
  • Enable detectable auto-repeat on X11.

Differences from #24575. Two commits conflicted because master has since been refactored around them. In both, the commit's own lines are unchanged:

  • fix(wasm): Raise key up for the soft keyboard Enter key: master reaches the focused text box through ITextBoxHost/core.Owner, while 6.8 still uses TextBox. The key-up raise is applied to 6.8's TextBox form.
  • fix(x11): Enable detectable auto-repeat: master creates its windows through the graphics negotiation pipeline, while 6.8 still has its explicit Vulkan, GL and EGL renderer selection. The per-connection XkbSetDetectableAutoRepeat call goes right after the second display connection opens, as on master, ahead of 6.8's renderer selection.

Validation:

  • Unit tests: Given_KeyboardStateTracker passes 12/12 on servicing/6.8, which is every test in the file.
  • Compile: these all build on servicing/6.8:
    • the Uno.UI.Runtime.Skia.WebAssembly.Browser runtime, C# and TypeScript;
    • the Uno.UI.Runtime.Skia.X11 runtime;
    • the desktop SamplesApp, with the new KeyboardStateProbe sample.
  • Not validated at runtime on 6.8: the focus-steal, auto-repeat and X11 held-key cases. fix(wasm): Stuck and flickering keyboard modifier state #24575 covered them on master, and the changed code is the same.

PR Checklist ✅

🤖 Generated with Claude Code


This is an automatic backport of pull request #25155 done by [Mergify](https://mergify.com).

ramezgerges and others added 8 commits October 28, 2026 01:15
KeyboardStateTracker emulated the Locked flag as a per-key press parity
counter. That is only equivalent to the Win32 "toggled" bit it mirrors if
every physical press produces exactly one update, which no platform
guarantees: routed key events are raised once per element while bubbling,
so the resulting flag depended on the focused element's depth in the
visual tree, and OS auto-repeat flipped it again for a key held down.

Nothing reads the flag, and for Caps Lock - the one key where an app would
consult it - a press counter is the wrong source anyway, since the lock can
be toggled before the app starts or while it is in the background.

Dropping it also makes the tracker idempotent, which removes the need to
tell an auto-repeat apart from a key down whose key up was never delivered:
both mean the key is down. It also fixes the drag modifiers in
PointerRoutedEventArgs.GetState, which compare against Down exactly and
silently dropped whenever the parity landed on Down | Locked.

See #17100

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit b580458)
(cherry picked from commit ee98140)
Key downs and key ups cannot be trusted to stay paired: a modifier
released while the browser or the OS holds focus - opening dev tools
mid-keystroke, for instance - never produces a key up, leaving the key
reported as held for the rest of the session.

Every key event already carries the real state of all four modifiers
alongside its own payload, so apply that in OnKey before dispatching.
This is the single per-event entry point, so it runs once per physical
key rather than once per element while bubbling.

The key the event is about needs no special treatment: the key down/up
applied while the event bubbles lands after this and wins, which also
avoids relying on how a platform reports a modifier's own key up.

See #17100

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit a9ff5c6)
(cherry picked from commit 285b760)
A mobile on-screen keyboard can raise Shift during auto-capitalization
without ever releasing it, with no window blur involved. In a touch-only
session no key event follows either, so neither the key event resync nor
the activation reset can correct it and every tap reads as Shift+tap.

Pointer events carry the browser's own ctrl/shift on every occurrence, so
feed those to the tracker as well. The write is skipped when the value is
unchanged, to keep pointermove free of dictionary churn. Alt and Meta are
not reported on pointer events and stay on the key event path.

See #17100

Co-Authored-By: Jacques Bourque <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 3a6454e)
(cherry picked from commit 0a65287)
WebAssemblyWindowWrapper already had OnNativeActivated and
OnNativeVisibilityChanged, but nothing ever called them: this was the only
Skia target not feeding the shared activation path. Android, AppleUIKit
and X11 all wire theirs.

Map the browser equivalents onto it - window focus/blur for activation,
document visibilitychange for visibility. Window.Activated and
Window.VisibilityChanged consequently start being raised on this target,
where they never fired before.

This also restores the reset of the tracked keyboard state that
BaseWindowImplementation performs on an activation change, which is what
stops a modifier held while the browser steals focus from being reported
as held once the page gets focus back.

See #17100

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 4ebc924)
(cherry picked from commit de132fc)
OnEnterKeyPressed raised KeyDown with no matching KeyUp, so every Enter
pressed on the on-screen keyboard left the key reported as held for the
rest of the session. The AppleUIKit equivalent already raises both.

See #17100

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 9852c2d)
(cherry picked from commit 2a4cbfb)
By default the server reports auto-repeat as a KeyRelease/KeyPress pair,
so a key held down arrives as a rapid sequence of presses and releases and
CoreWindow.GetKeyState reports it as not held in between. Detectable
auto-repeat delivers repeated key presses instead, matching every other
platform; GTK, Qt and SDL all request it.

It is set per connection, and key events are read from whichever
connection owns the window they target, so request it on both.

See #17100

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit ac564bb)
(cherry picked from commit 3c528bc)
Reports CoreWindow.GetKeyState for the modifier keys and the last key
pressed, so a modifier that stays reported as held, or a held key whose
state is not stable, is visible without a debugger. Also written to the
console, where the transition matters more than the current value.

See #17100

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 92deeda)
(cherry picked from commit 929750e)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 9bfda24)
(cherry picked from commit 7567b44)
@github-actions github-actions Bot added area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/automation Categorizes an issue or PR as relevant to project automation labels Oct 28, 2026
@agneszitte
agneszitte merged commit be94e45 into release/stable/6.7 Oct 28, 2026
11 of 18 checks passed
@agneszitte
agneszitte deleted the mergify/bp/release/stable/6.7/pr-25155 branch October 28, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants