Skip to content

fix: leave the keyboard with the app while StableBar shows its menus - #943

Merged
M4n0x merged 2 commits into
stablebox:mainfrom
MaHofseth:fix/941-app-menus-leave-keyboard
Nov 27, 2026
Merged

M4n0x merged 2 commits into
stablebox:mainfrom
MaHofseth:fix/941-app-menus-leave-keyboard

Conversation

@MaHofseth

@MaHofseth MaHofseth commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Choosing an item in App menus did nothing in VS Code, such as File > Open Folder or File > New Text File, and New Tab in Ardia closed right after it opened. StableBar's menus took the keyboard when clicked, so the app in front had no key window when StableBar pressed the item, and VS Code drops a menu command then.

Fixes #941

Changes

  • PopupPanel.leavesKeyboard keeps a panel from becoming key. It's set on popups whose block is an app menu, which covers an app's menus, the » menu and the menus of menu bar items shown in the bar, and on the App menus tray and on submenus opened from a menu that has it. It stays off when the window the menu opens from has the keyboard, as under --focus, so menus opened from the keyboard can still be moved through. A menu opened from the menu bar items list still takes the keyboard, as before, because the list has it.
  • StableBar gets no modifier events while another app keeps the keyboard, so open app menus now watch Option with a global monitor too. Without it, Option alternates didn't follow the key.
  • WidgetPopup orders such a panel in without making it key, and a click inside it no longer makes it key.
  • Escape now goes to the app in front, so while such a popup is open the global event monitor also watches key presses and closes the popup on Escape. The app receives that Escape too.
  • The App menus section of the guide says the app keeps the keyboard, how that differs from a native menu, and how Escape behaves.

No configuration property changes, and nothing looks different.

Testing

  • New test anAppsMenusNeverTakeTheKeyboardFromTheApp (AppMenuKeyboardTests.swift) checks that the tray, a menu opened from it, that menu's submenu and a menu opened from the bar can't become key, while a widget's own popup still can. Without the first version of the fix, it failed for the tray and both menus; without the line that passes the setting to submenus, the submenu check fails.
  • The Option change has no automated test: a global monitor only hears events sent to other apps. Checked by hand with this and fix: choose a submenu item opened from the App menus tray #944 merged on 1fe18ea, in Finder's File menu opened through the tray: Get Info and Close Window changed to their alternates while Option was held and changed back when it was let go, also when the menu was opened with Option already held.
  • swift build --build-tests passes. The full suite (swift test, 1,462 tests) passes except workspaceLabelsFollowTheBarFromLightToDark and the three cases of tooltipsThatTakeThePointerLeaveClicksOnTheirWidgetToIt. Both tests also fail on an unchanged 8590fcd on the same Mac. With fix: choose a submenu item opened from the App menus tray #944 merged too, on 1fe18ea, the full suite (1,476 tests) fails only those. scripts/check.sh --quick and commitlint pass.
  • Manual check, before the Option change, on macOS 27.2.1 with VS Code 1.147.0 at Trace log level. On 0.19.0, File > New Text File from the bar logged menubar#runActionInRenderer: no active window found. With a development build that has this fix (it also had Clicking a submenu item from the App menus tray closes the menus without choosing it #942's fix and fix: show Countdown and Join in Settings after picking it #940's commits), the same click, File > Open Folder, and New Text File through the tray all ran, and VS Code logged each command. Ardia's New Tab stayed open, and Escape closed an open menu.
  • Not checked: Option alternates in a menu opened directly from the bar, menus opened from the keyboard under --focus (they still take the keyboard, as before), VoiceOver, and the Apple menu and menu bar item menus in a running app.

Merging

Two fix commits, so a patch release. A squash merge keeps one changelog line. It merges cleanly with #944, the fix for #942, which changes another part of WidgetPopup.swift.

🤖 Generated with Claude Code

Claude Sonnet 5.5 and Claude Opus 5.5 via Claude Code

App menus, their tray and their submenus took the keyboard when clicked, so the app in front had
no key window when StableBar pressed the chosen item. VS Code drops a menu command then, so File >
Open Folder and New Text File did nothing.

They now leave the keyboard with the app, as native menus do, unless the bar has it already, as
under --focus. Escape still closes them: StableBar watches for it while the app gets it.

Fixes #941

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

You’re at about 98% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Tip: cubic could auto-approve low-risk PRs like this, if it thinks it's safe to merge. Learn more

Re-trigger cubic

@M4n0x M4n0x added the deep-review CodeRabbit reviews this pull request: big or risky changes label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Popup panels now distinguish whether they can take keyboard focus. App-menu popups opened from non-key windows leave focus with the app. Panels that leave the keyboard close on Escape. AppMenuList also monitors modifier changes locally and globally.

Changes: App menu keyboard focus

Layer / File(s) Summary
Popup focus policy and opening behavior
Sources/StableBar/Popups/PopupPanels.swift, Sources/StableBar/Popups/WidgetPopup.swift, Sources/StableBar/MenuBar/AppMenu.swift
PopupPanel.leavesKeyboard controls whether a panel can become key. WidgetPopup sets this value for row and app-menu popups, and avoids making non-key-capable panels key. Submenus inherit the setting from a parent PopupPanel.
Modifier-key monitoring
Sources/StableBar/Popups/AppMenuList.swift
AppMenuList registers local and global modifier-change monitors to update optionHeld. It removes both monitors when the view disappears.
Escape handling and regression coverage
Sources/StableBar/Popups/WidgetPopup.swift, Tests/StableBarTests/AppMenuKeyboardTests.swift, docs/widgets.md
Global key-down monitoring applies to panels that leave the keyboard and closes them on Escape. Tests check focus behavior for app-menu and widget popups. The documentation describes keyboard focus and Escape handling.

Possibly related PRs

  • stablebox/StableBar#944: Both PRs change Escape and submenu behavior for App menus. #944 adjusts tray event handling for descendant submenu windows.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 526a1

App-menu popups opened by pointer now leave keyboard input with the app, and Escape closes them. No concrete merge-blocking risk was found. Keyboard-opened menus under --focus and VoiceOver were not tested manually.

Security architecture risk: Minimal · up to 526a1

App menus can stay open without taking keyboard focus from the active app. The review found no material security regression: observing Escape or Option does not itself execute a menu command.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The new event sources are desktop-local: an open app-menu list can observe modifier changes delivered from outside StableBar, and a keyboard-leaving popup can observe Escape. Neither observer forwards the event to the Accessibility action dispatcher.

Trust Boundaries and Controls

  • observed — The existing app-menu read checks Accessibility trust and reads the selected app by process ID. The menu-opening path retains its owner check, and an enabled leaf row still invokes the existing press path using the entry's Accessibility element, not a target supplied by either event monitor.

Resilience and Maintainability Implications

  • observed — Replacing a popup goes through close before installing new monitors; close removes and clears the monitor tokens. The menu list separately removes its modifier-monitor tokens when the view disappears.
Pre-merge checks: Passed 3

Check name Status Explanation
Linked Issues check Passed Directly linked issue #941 requires that App menu items run in VS Code, that keyboard use of the bar (#212) and popups (#517) is kept, and that Escape closes a menu. The diff of PopupPanels.swift adds…
Out of Scope Changes check Passed Each changed area connects to #941. PopupPanels.swift adds the keyboard flag that controls app menu panels. AppMenu.swift applies the flag to submenus. WidgetPopup.swift applies it to the tray, bar-op…
Description check Passed The description follows the repository template closely. It has a Problem section that states the bug and links issue #941 with "Fixes #941". The Changes section lists each area and gives the reason f…
Full details: Linked Issues check

Explanation

Directly linked issue #941 requires that App menu items run in VS Code, that keyboard use of the bar (#212) and popups (#517) is kept, and that Escape closes a menu. The diff of PopupPanels.swift adds PopupPanel.leavesKeyboard (default false) and sets canBecomeKey to !leavesKeyboard. This removes the cause the issue names, where canBecomeKey was always true. The WidgetPopup.swift diff could not be read (blobs unavailable), so its present, keepOpen, showRow, and watchEvents changes rest on the change summary. The summary states that such panels order in without becoming key, that clicks inside them do not make them key, that the bar keeps the keyboard when its window is key (covering #212), and that Escape closes such a popup while the app also receives it. AppMenu.swift sets leavesKeyboard on submenus from the parent panel. The test anAppsMenusNeverTakeTheKeyboardFromTheApp covers the tray, a tray-opened menu, and a bar-opened menu, and checks that a widget popup can still become key. The author reports a manual check on VS Code 1.147.0 and Ardia showing the commands run and Escape closes the menu. Those reports are not independently verified. Previous PASS conclusion is still supported by the PopupPanels.swift diff and the summary.

Full details: Out of Scope Changes check

Explanation

Each changed area connects to #941. PopupPanels.swift adds the keyboard flag that controls app menu panels. AppMenu.swift applies the flag to submenus. WidgetPopup.swift applies it to the tray, bar-opened menus, and Escape handling, per the summary. AppMenuList.swift replaces the single local flagsChanged monitor with local and global monitors, so optionHeld still updates when a non-key menu receives no modifier events. This follows directly from menus leaving the keyboard, so it supports the fix. It is not described in the PR description, but the linked fix needs it for Option alternates. The docs/widgets.md change documents the keyboard behavior the fix introduces. The summary reports no configuration or visual changes. The WidgetPopup.swift diff could not be read, so its exact hunks are not confirmed.

Full details: Description check

Explanation

The description follows the repository template closely. It has a Problem section that states the bug and links issue #941 with "Fixes #941". The Changes section lists each area and gives the reason for each. The Testing section names the automated test, the manual checks on macOS and VS Code, the test failures on unchanged main, and the items not checked. The Merging section states the merge method (squash keeps one changelog line, with a note on the commit type and the clean merge with #944). The final line names the models and harness (Claude Code), so the Description check can read it.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5edfe48 and 526a174.

Files selected for processing: 4

  • Sources/StableBar/Popups/AppMenuList.swift
  • Sources/StableBar/Popups/WidgetPopup.swift
  • Tests/StableBarTests/AppMenuKeyboardTests.swift
  • docs/widgets.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@M4n0x M4n0x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the new test fails without the fix and passes with it, and the whole suite is green locally (CI hasn't run yet). One blocking thing with the Option alternates, the rest is small

issue (blocking): Option alternates don't follow Option anymore. AppMenuList only listens to .flagsChanged with a local monitor, and StableBar doesn't get modifier events once the menu isn't key. So pressing Option with the Apple menu open does nothing, and if you open it with Option held then let go, Restart (the one without confirmation) stays in the menu and can be clicked. A global .flagsChanged monitor next to the local one should fix it, we have Accessibility anyway at that point

thought: a menu opened under --focus still has the keyboard when the item gets pressed, so VS Code should still drop the command there, fine for a follow-up issue imo

Comment thread docs/widgets.md Resolved
Comment thread Sources/StableBar/MenuBar/AppMenu.swift Resolved
A menu that leaves the keyboard with the app gets no modifier events, so holding Option showed no
alternates, and one opened with Option held kept them after Option was let go, such as Restart
without its confirmation. A global monitor now hears Option too.

Also test that a submenu leaves the keyboard like its menu, and say in the guide what differs from
a native menu.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@MaHofseth

Copy link
Copy Markdown
Contributor Author

Thanks, good catch on Option. Fixed in 526a174 with a global .flagsChanged monitor next to the local one. It has no automated test, so I checked it by hand, with #944 merged too, in Finder's File menu from the tray: alternates followed Option, also when the menu was opened with Option held and then let go. I didn't try the Apple menu or a menu opened directly from the bar. Agreed that menus under --focus can be a follow-up; I haven't tested that case.

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Before and after

main at 8590fcd → this pull request at 526a174 · 202 screens drawn · 0 changed

202 unchanged screens

docs/essentials-clock-settings-dark, docs/essentials-clock-settings-light, docs/essentials-dark, docs/essentials-light, docs/essentials-settings-dark, docs/essentials-settings-light, docs/hero-dark, docs/hero-light, docs/popups-dark, docs/popups-light, docs/settings-dark, docs/settings-light, docs/themes-dark, docs/themes-light, scenes/accessibility-guide-dark, scenes/app-menu-popup-dark, scenes/apple-menu-settings-dark, scenes/apple-menu-symbol-bar-dark, scenes/apple-menu-symbol-settings-dark, scenes/bar-dividers-dark, scenes/bottom-bar-popup-dark, scenes/chat-popup-dark, scenes/crowded-edit-bar-dark, scenes/disk-meter-bar-dark, scenes/dock-badges-bar-dark, scenes/edit-bar-wide-group-dark, scenes/essentials-clock-popup-dark, scenes/essentials-disk-popup-dark, scenes/filled-slider-popup-dark, scenes/glass-text-follows-background-bar-dark, scenes/glass-text-follows-background-bar-light, scenes/group-members-bar-dark, scenes/group-others-bar-dark, scenes/group-text-color-bar-dark, scenes/gruvbox-bar-dark, scenes/gruvbox-bar-light, scenes/horizontal-list-popup-dark, scenes/increase-contrast-bar-dark, scenes/increase-contrast-bar-light, scenes/increase-contrast-popup-dark, scenes/increase-contrast-popup-light, scenes/input-source-popup-dark, scenes/labeled-metric-built-in-dark, scenes/labeled-metric-catppuccin-dark, scenes/labeled-metric-catppuccin-light, scenes/meeting-live-popup-dark, scenes/meeting-soon-bar-dark, scenes/menu-bar-items-widget-settings-dark, scenes/menu-bar-items-widget-style-dark, scenes/merged-status-bar-dark, scenes/notch-flare-bar-dark, scenes/output-device-popup-dark, scenes/package-template-clash-bar-dark, scenes/popup-gap-bar-dark, scenes/popup-spacing-bar-dark, scenes/popup-view-dark, scenes/preset-dashboard-bar-dark, scenes/preset-developer-bar-dark, scenes/preset-everyday-bar-dark, scenes/preset-minimal-bar-dark, scenes/preset-workday-bar-dark, scenes/privacy-both-bar-dark, scenes/privacy-hide-when-idle-bar-dark, scenes/privacy-idle-bar-dark, scenes/privacy-microphone-bar-dark, scenes/privacy-settings-dark, scenes/quick-toggles-bar-dark, scenes/quick-toggles-displays-popup-dark, scenes/quick-toggles-every-tile-popup-dark, scenes/quick-toggles-network-popup-dark, scenes/quick-toggles-networks-popup-dark, scenes/quick-toggles-popup-dark, scenes/reduce-transparency-bar-dark, scenes/reduce-transparency-bar-light, scenes/reduce-transparency-glass-bar-dark, scenes/reduce-transparency-glass-bar-light, scenes/reduce-transparency-text-follows-background-bar-dark, scenes/reduce-transparency-text-follows-background-bar-light, scenes/ring-bar-dark, scenes/settings-bar-dark, scenes/settings-bar-link-dark, scenes/settings-bar-link-review-dark, scenes/settings-bar-link-workspace-color-dark, scenes/settings-bar-look-dark, scenes/settings-bar-look-light, scenes/settings-bar-placement-bottom-dark, scenes/settings-bar-placement-dark, scenes/settings-calendar-picker-dark, scenes/settings-calendar-widget-dark, scenes/settings-clock-widget-dark, scenes/settings-crashes-dark, scenes/settings-disk-widget-dark, scenes/settings-feedback-dark, scenes/settings-general-dark, scenes/settings-general-kiwidesk-dark, scenes/settings-general-macos15-dark, scenes/settings-general-macos27-dark, scenes/settings-general-manager-not-found-dark, scenes/settings-general-move-dark, scenes/settings-general-move-failed-dark, scenes/settings-general-move-moving-dark, scenes/settings-general-move-replace-dark, scenes/settings-general-setup-open-dark, scenes/settings-general-spaces-dark, scenes/settings-general-yabai-gap-dark, scenes/settings-group-dark, scenes/settings-group-defaults-dark, scenes/settings-group-defaults-light, scenes/settings-group-theme-color-dark, scenes/settings-group-theme-color-light, scenes/settings-help-dark, scenes/settings-help-starred-dark, scenes/settings-labeled-metric-dark, scenes/settings-narrow-dark, scenes/settings-package-dark, scenes/settings-package-widget-dark, scenes/settings-profiles-conditions-dark, scenes/settings-profiles-dark, scenes/settings-profiles-groups-dark, scenes/settings-profiles-theme-dark, scenes/settings-quick-toggles-dark, scenes/settings-store-dark, scenes/settings-theme-dark, scenes/settings-theme-edits-dark, scenes/settings-theme-edits-light, scenes/settings-theme-groups-dark, scenes/settings-theme-light, scenes/settings-theme-link-dark, scenes/settings-theme-link-light, scenes/settings-theme-origins-dark, scenes/settings-theme-versions-dark, scenes/settings-tiled-dark, scenes/settings-tiled-narrowest-dark, scenes/settings-uninstall-dark, scenes/settings-uninstall-failed-dark, scenes/settings-widget-backgrounds-dark, scenes/settings-widget-backgrounds-light, scenes/settings-widget-colors-dark, scenes/settings-widget-colors-light, scenes/settings-widget-style-theme-edits-dark, scenes/settings-widget-style-theme-edits-light, scenes/settings-workspace-hidden-dark, scenes/setup-allow-aerospace-gap-dark, scenes/setup-allow-automation-dark, scenes/setup-allow-below-menu-bar-dark, scenes/setup-allow-dark, scenes/setup-allow-dot-dark, scenes/setup-allow-macos27-dark, scenes/setup-allow-offline-dark, scenes/setup-allow-spaces-dark, scenes/setup-allow-workday-dark, scenes/setup-choose-dark, scenes/setup-choose-new-dark, scenes/setup-choose-no-battery-dark, scenes/setup-done-dark, scenes/setup-intro-dark, scenes/setup-intro-wallpaper-dark, scenes/setup-move-existing-dark, scenes/setup-move-failed-dark, scenes/setup-move-ready-dark, scenes/setup-move-replace-dark, scenes/shadow-offsets-bar-dark, scenes/shadow-offsets-bar-light, scenes/share-my-bar-dark, scenes/share-my-bar-dock-dark, scenes/share-my-bar-glass-dark, scenes/share-my-bar-glass-light, scenes/share-my-bar-landscape-dark, scenes/share-my-bar-link-dark, scenes/share-my-bar-macbook-dark, scenes/share-my-bar-post-dark, scenes/slider-end-stop-popup-dark, scenes/sound-details-popup-dark, scenes/stablebar-widget-bar-dark, scenes/stablebar-widget-settings-dark, scenes/starter-bar-dark, scenes/starter-edit-bar-dark, scenes/symbol-variants-bar-dark, scenes/system-monitor-memory-bar-dark, scenes/system-monitor-shows-settings-dark, scenes/system-monitor-split-warning-bar-dark, scenes/text-follows-background-bar-dark, scenes/text-follows-background-bar-light, scenes/themed-slider-inline-dark, scenes/themed-slider-inline-light, scenes/themed-slider-popup-dark, scenes/themed-slider-popup-light, scenes/themed-slider-tooltip-dark, scenes/themed-slider-tooltip-light, scenes/tinted-app-icons-bar-dark, scenes/tinted-app-icons-bar-light, scenes/tinted-image-bar-dark, scenes/tinted-image-bar-light, scenes/update-popup-dark, scenes/update-popup-star-github-cli-dark, scenes/update-popup-star-thanks-dark, scenes/workspace-badges-bar-dark, scenes/workspace-cells-bar-dark, scenes/workspace-focused-window-bar-dark, scenes/workspace-focused-window-padding-bar-dark, and 2 more

Visual review: 202 screens, none changed.

@M4n0x M4n0x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option follows again, tried it in a VM with the Apple menu, alternates show while held and go back on release. File > New Text File from the bar works in VS Code now (does nothing on main), Escape closes the menu. LGTM, --focus case as a follow-up

@M4n0x
M4n0x added this pull request to the merge queue Nov 27, 2026
Merged via the queue into stablebox:main with commit abc1c4f Nov 27, 2026
24 of 25 checks passed
stablebar-releases Bot pushed a commit that referenced this pull request Nov 29, 2026
## [0.20.0](v0.19.0...v0.20.0) (2026-11-29)

### Features

* animate widgets that a profile shows or hides ([#948](#948)) by @M4n0x ([eec8544](eec8544)), closes [#947](#947) [#947](#947)
* log quit causes and show unexpected quits in Status ([#953](#953)) by @M4n0x ([ea5a64e](ea5a64e)), closes [#952](#952)

### Bug Fixes

* choose a submenu item opened from the App menus tray ([#944](#944)) by @MaHofseth ([add49b0](add49b0)), closes [#942](#942)
* draw borders in whole pixels so they keep every edge on 1x screens ([#934](#934)) by @M4n0x ([8590fcd](8590fcd)), closes [#933](#933) [#933](#933)
* keep a package version installed when its folder is hidden ([#962](#962)) by @M4n0x ([2d97d15](2d97d15)), closes [#961](#961)
* keep the Sound details open and smooth when picking a device ([#931](#931)) by @M4n0x ([df96453](df96453)), closes [#928](#928) [#928](#928)
* keep windows clear of the bar after a double-click fills them ([#936](#936)) by @M4n0x ([c1478d1](c1478d1)), closes [#935](#935) [#935](#935)
* leave the keyboard with the app while StableBar shows its menus ([#943](#943)) by @MaHofseth ([abc1c4f](abc1c4f)), closes [#941](#941)
* play an app's first sound at its mixer volume ([#899](#899)) by @M4n0x ([2c38350](2c38350)), closes [#897](#897) [#897](#897)
* show a turned-off widget's last output when it comes back ([#950](#950)) by @M4n0x ([6776fcb](6776fcb)), closes [#949](#949) [#949](#949)
* show Countdown and Join in Settings after picking it ([#940](#940)) by @MaHofseth ([6ecaa72](6ecaa72))
* stop offering a package update that is already installed ([#956](#956)) by @M4n0x ([4592ebc](4592ebc))
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.20.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

deep-review CodeRabbit reviews this pull request: big or risky changes released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Choosing an app menu item does nothing in VS Code because StableBar's menu takes the keyboard

2 participants