Skip to content

fix(ui-windows): Tab/arrow keyboard navigation was dead (IsDialogMessageW + WS_EX_CONTROLPARENT)#6638

Merged
proggeramlug merged 2 commits into
mainfrom
fix/win-ui-tab-navigation
Jul 21, 2026
Merged

fix(ui-windows): Tab/arrow keyboard navigation was dead (IsDialogMessageW + WS_EX_CONTROLPARENT)#6638
proggeramlug merged 2 commits into
mainfrom
fix/win-ui-tab-navigation

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Problem

Keyboard navigation was completely dead in Perry Windows apps: every input control sets WS_TABSTOP, but the message pump is a raw GetMessageW → TranslateMessage → DispatchMessageW loop that never invokes the dialog manager — so the tab stops had no effect. Tab did nothing, in any Perry window, ever.

Fix (three pieces, each necessary)

  1. Pump (app.rs): for keyboard-class messages (WM_KEYFIRST..=WM_KEYLAST), route through IsDialogMessageW(GetAncestor(msg.hwnd, GA_ROOT), &msg); when it handles the message it has already translated+dispatched, so skip the normal dispatch. Runs after the existing shortcut and onKeyDown/onKeyUp dispatch, so app shortcuts still win and JS key events still observe Tab.
  2. Gating (wants_dialog_navigation): only messages targeting our own windows/widgets qualify — the target chain (≤4 ancestor hops, so a composite control's inner EDIT still qualifies) must hit a registered widget or one of our top-levels. Two subtleties found by testing:
    • our top-level windows qualify directly — before any control is focused, key messages target the window itself, and the first Tab must bootstrap focus into the first tab stop (without this, Tab never engaged at all);
    • WebViews are excluded (new webview::is_webview(handle) — they register as WidgetKind::Image, so a kind check can't identify them): WebView2's Chromium children own their keyboard handling and must keep Tab for web content.
  3. Containers get WS_EX_CONTROLPARENT (vstack/hstack/zstack/scrollview/navstack/form): without it the dialog manager does not recurse into child windows, and testing showed focus landing on the VStack container and sticking there. With it, GetNextDlgTabItem walks through containers to the real controls.

Verification (Windows 11 x64, real window, cross-process GetGUIThreadInfo probe)

Smoke app (Button + TextField + Slider in a VStack), three Tab presses via SendKeys:

state before after
start PerryMainWindow PerryMainWindow
Tab 1 PerryMainWindow (stuck) msctls_trackbar32
Tab 2 PerryMainWindow (stuck) Edit
Tab 3 PerryMainWindow (stuck) Button

cargo build --release -p perry-ui-windows clean.

Known limitation (documented, standard dialog behavior): Tab moves focus out of a multiline TextArea unless the control claims tabs via WM_GETDLGCODE; Enter-to-default-button is inert until a default button concept exists (WM_GETDEFID returns 0).

No version bump / changelog per maintainer instruction.

Summary by CodeRabbit

  • New Features
    • Improved Windows keyboard focus navigation (Tab/Shift-Tab) across Perry controls, including nested layouts and grouped sections.
  • Bug Fixes
    • Enhanced focus traversal by enabling container dialog-style navigation behavior (via extended control parent styling) so focus reliably reaches eligible WS_TABSTOP controls.
    • Preserved correct keyboard handling for embedded web content by avoiding interference with WebView2’s internal key processing.

WS_TABSTOP was dead: a raw GetMessage/Dispatch pump never runs the
dialog manager. Route keyboard-class messages through IsDialogMessageW
(gated to our own windows/widgets; WebView2 children excluded so web
content keeps its keys; our top-levels qualify directly so the first
Tab bootstraps focus), and give container classes WS_EX_CONTROLPARENT
so GetNextDlgTabItem recurses into them instead of parking focus on
the VStack.

Verified with a cross-process GetGUIThreadInfo probe: focus now
cycles trackbar -> Edit -> Button on Tab; previously it never left
the main window.
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fff78ccd-be03-4244-a01e-980743d12f73

📥 Commits

Reviewing files that changed from the base of the PR and between a206d48 and 00df237.

📒 Files selected for processing (2)
  • crates/perry-ui-windows/src/app.rs
  • crates/perry-ui-windows/src/widgets/scrollview.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/perry-ui-windows/src/widgets/scrollview.rs
  • crates/perry-ui-windows/src/app.rs

📝 Walkthrough

Walkthrough

Windows containers now enable recursive WS_TABSTOP navigation. The message loop identifies eligible Perry keyboard targets, excludes WebView2 handling, and routes handled messages through IsDialogMessageW.

Changes

Windows dialog navigation

Layer / File(s) Summary
Enable recursive container navigation
crates/perry-ui-windows/src/widgets/form.rs, crates/perry-ui-windows/src/widgets/hstack.rs, crates/perry-ui-windows/src/widgets/navstack.rs, crates/perry-ui-windows/src/widgets/scrollview.rs, crates/perry-ui-windows/src/widgets/vstack.rs, crates/perry-ui-windows/src/widgets/zstack.rs
Form, groupbox, and stack-based containers now use WS_EX_CONTROLPARENT when created on Windows.
Route eligible keyboard messages
crates/perry-ui-windows/src/window.rs, crates/perry-ui-windows/src/widgets/webview.rs, crates/perry-ui-windows/src/app.rs
New helpers classify Perry windows and WebView handles; eligible keyboard messages are passed to IsDialogMessageW, skipping normal dispatch when handled.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MessageLoop
  participant NavigationCheck
  participant DialogManager
  participant WebView2
  MessageLoop->>NavigationCheck: inspect keyboard message target
  NavigationCheck->>WebView2: exclude WebView2-owned target
  NavigationCheck-->>MessageLoop: return eligibility
  MessageLoop->>DialogManager: call IsDialogMessageW for root ancestor
  DialogManager-->>MessageLoop: report handled message
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the Windows keyboard-navigation fix with the key mechanisms involved.
Description check ✅ Passed The description covers the problem, fix, verification, and limitation details, with only the template sections like related issue left implicit.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/win-ui-tab-navigation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@proggeramlug
proggeramlug merged commit d422797 into main Jul 21, 2026
27 checks passed
@proggeramlug
proggeramlug deleted the fix/win-ui-tab-navigation branch July 21, 2026 06:50
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