feat(macos): support applicationDockMenu: (right-click Dock menu) - #1295
Open
thomnico wants to merge 1 commit into
Open
feat(macos): support applicationDockMenu: (right-click Dock menu)#1295thomnico wants to merge 1 commit into
thomnico wants to merge 1 commit into
Conversation
Adds EventLoopWindowTargetExtMacOS::set_dock_menu(), letting apps register a menu shown on right-click / Control-click / long-press of the Dock icon. Previously unsupported — macOS falls back to Cocoa's default minimal menu (Show/Hide, Quit) with no way to add custom items. The menu is stored in a small module-level Mutex (main-thread only, same invariant as the rest of app_state.rs's `id` usage) because `applicationDockMenu:` must return its value synchronously — unlike e.g. Event::Reopen, there's no round-trip through tao's event queue available for this callback.
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.
Summary
Adds support for
applicationDockMenu:— the menu Cocoa shows when the user right-clicks (or Control-clicks / long-presses) the application's Dock icon. Currently unsupported: macOS falls back to its default minimal menu (Show/Hide, Quit) with no way for the app to customize it.New public API on
EventLoopWindowTargetExtMacOS:Same shape as the existing
set_badge_label/set_dock_visibilitymethods. Can be called at any point after the event loop starts, including from a menu item's own click handler (e.g. to rebuild the menu with an updated checkmark) — the next right-click picks up the change.Why a small module instead of an
EventvariantapplicationDockMenu:must return its value synchronously to Cocoa — there's no round-trip available through tao's event queue the way there is for e.g.Event::Reopen. So the menu is stored in a small module-levelMutex(platform_impl/macos/dock_menu.rs), read directly by the newapplication_dock_menuhandler inapp_delegate.rs. Same main-thread-only invariant as the rest of that file'sidusage (documented inline).Testing
Used this in a real app (menu bar app built on tao 0.36,
EventLoopBuilder::<UserEvent>::with_user_event()) — right-click on the Dock icon now shows a customCheckMenuItembuilt withmuda, synced with the same toggle exposed elsewhere in the app (tray menu, application menu bar). Confirmed working on macOS (tested by the end user, not just compiled).Notes
"NSMenu"to theobjc2-app-kitfeature list inCargo.toml(was missing, needed forNSMenu/Retained<NSMenu>).cargo fmt --checkandcargo check --target aarch64-apple-darwinpass.dock_menuexample underexamples/if useful for review — didn't want to guess at what you'd want there without asking first.