Fix menubar popover across macOS spaces#12
Merged
handlecusion merged 2 commits intoJun 4, 2026
Conversation
509e163 to
4dee08e
Compare
Owner
|
Thanks for the detailed fix and write-up, @Nanako0129 . I reproduced the full-screen Space issue locally against I pushed one small follow-up commit ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Tokcat is a macOS menubar app, so the main window behaves like a popover rather than a regular desktop window. Before this change, the first Space that opened the popover could effectively become the window's remembered Space. When the user clicked the menu bar icon from another Space, macOS could switch back to the original Space instead of opening Tokcat where the click happened.
Full-screen app Spaces had a second failure mode: after preventing the Space switch, the popover could still fail to appear because it was not ordered above the full-screen app window.
Problem Matrix
Root Cause
This is not a React state issue. It comes from AppKit's native management of
NSWindow, Spaces, and full-screen Spaces.flowchart TD CLICK[User clicks menu bar icon] --> SHOW[Tauri shows main WebviewWindow] SHOW --> SPACE{Which Space owns the window?} SPACE -->|Reusable hidden window| OLD[macOS may return to the original Space] SPACE -->|Only joins all regular Spaces| FS[Full-screen Space may not order the window in front] OLD --> BAD[User is moved away from the current Space] FS --> HIDDEN[Popover exists but is not visible above the full-screen app]mainWebviewWindow. Afterhide(), a latershow()can preserve the original Space relationship.set_focus()is not enough for full-screen Spacescurrent_monitor()can reflect the hidden window's previous location instead of the menu bar icon that was clicked.Implementation
src-tauri/tauri.conf.jsonvisibleOnAllWorkspaces: truesrc-tauri/src/tray.rsprepare_popover_window()before showing the popoversrc-tauri/src/tray.rsCanJoinAllSpaces,CanJoinAllApplications,FullScreenAuxiliary,IgnoresCycle, andTransientsrc-tauri/src/tray.rsNSPopUpMenuWindowLevelsrc-tauri/src/tray.rsorderFrontRegardless()aftershow()andset_focus()src-tauri/src/tray.rsmonitor_from_point(tray_x, tray_y)instead ofcurrent_monitor()Open Flow
flowchart TD CLICK[Menu bar icon click] --> GETWIN[Get main WebviewWindow] GETWIN --> VISIBLE{Is it visible?} VISIBLE -->|Yes| HIDE[Hide popover] VISIBLE -->|No| PREP[prepare_popover_window] PREP --> POSITION[Position from tray rect and tray monitor] POSITION --> SHOW[window.show] SHOW --> FRONT1[orderFrontRegardless] FRONT1 --> FOCUS[set_focus] FOCUS --> FRONT2[orderFrontRegardless] FRONT2 --> EVENT[emit popover-shown]Verification
Tokcat.appCommands run locally:
rustfmt --check src/tray.rs npx tauri build --debug --no-bundle npx tauri build --debug --bundles app --no-sign --config '{"bundle":{"createUpdaterArtifacts":false}}'Manual test coverage:
Risk And Tradeoffs
#[cfg(target_os = "macos")]; non-macOS keeps the existingset_visible_on_all_workspaces(true)path.NSPopUpMenuWindowLevelmatches menu/popover UI and fixes foreground ordering in full-screen Spaces.ns_window()handle and objc2 AppKit APIs without modifying Tauri runtime or vendored tray-icon code.IgnoresCycleandTransientkeep the popover out of normal window cycling, matching expected menubar-popover behavior.Implementation Summary
Issue
Fixes #13