Skip to content

Fix Menus on macOS 27 - #159

Merged
jdtsmith merged 2 commits into
fix/live-resize-27from
fix/menus-27
Nov 17, 2026
Merged

jdtsmith merged 2 commits into
fix/live-resize-27from
fix/menus-27

Conversation

@jdtsmith

@jdtsmith jdtsmith commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

This is a draft fix for #148. It builds on top of #157. Read the commit messages for more details, but the short summary is: mouse menu tracking now happens out of process on macOS27. So we need to update menu contents on LISP "just in time" prior to their being displayed, which we do in menuNeedsUpdate:. This is a distinct path from the earlier menu handling, which is left in place for earlier systems and keyboard-based menu interaction. Co-authored with Claude Opus 5.5.

This also incorporates and supersedes #149.

Please test, especially on macOS26/15/earlier.

* src/macappkit.m (mac_fill_menubar): Re-use existing [NSApp
windowsMenu], removing from parent and resetting as the app Windows
menu.
macOS 27 moved menu tracking out of process, rendering inoperative our
existing trick of noticing menu clicks (or key presses) on GUI during
event processing, posting a MENU_BAR_ACTIVATE_EVENT and processing
that event synchronously on LISP, building the menus there.  We leave
that apparatus in place for earlier systems.  For v27+, we now request
LISP to update the relevant menu just prior to it being displayed.
Since menus will be visible while popup_activated() is false, we also
take care to display help in the echo area in this case.  This also
fixes the missing Window menu shortcut keys on open (#140).

* src/macappkit.m: ([EmacsController setMenuItemSelectionToTag:]): On
macOS27, handle menu item selection here (i.e. in the menu item's
action) if no popup is activated (i.e. when menu tracking is happening
out of process).
([EmacsController handleQueuedNSEventsWithHoldingQuitIn:]): Reset menu
updated flag when new events arrive.
([NSMenu replaceEmacsItemsWithWidgetValue:]): New helper to replace
menu items in-place, to keep system-inserted menu items intact.
([NSMenu addItemWithWidgetValue:]): Mark separators as ours as well.
([EmacsMenu menuDidBeginTracking:]): Do not cancel menu tracking on
macOS 27, even if popup_activated() is false: we expect this now!
([EmacsController menuNeedsUpdate:]): Update menus via synchronous
LISP execution just in time, needed on macOS 27.
([EmacsController menu:willHighlightItem:]): Show help messages in
the echo area for our menu items even when popup_activated() is false
during out-of-process menu tracking.
(mac_menu_show_help_function): New help display function helper.
(mac_track_menu_with_block): Use it.
(mac_show_menu_bar_help): Show help for menu bar items during macOS
27 out of process tracking.
(mac_update_menubar_in_place_1, mac_update_menubar_in_place_handler,
mac_update_menubar_in_place, mac_handle_menu_bar_selection): New
helpers to update menu bars on LISP just in time.
(mac_fill_menubar): Update menus items in place if requested.  Also assign
emacsController as delegate for all submenus and release the (unused)
newMenu if updating in place.  We leave the Window menu alone to
ensure its shortcut keys remain bound.
(mac_wake_up_select): New helper to write wake byte.
* src/macappkit.h: Declare [NSMenu replaceEmacsItemsWithWidgetValue:].
@jdtsmith

Copy link
Copy Markdown
Owner Author

I'm going to merge this stack now despite some questions about whether it DTRT on v27.2, since at least 27.0 folks will be able to use it.

@jdtsmith
jdtsmith merged commit d3e85a1 into emacs-mac-31 Nov 17, 2026
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