Subject: Re: bug#56155: 29.0.50; Options menu, toggle menu items not updated

From: Po Lu <[email-masked]>
Date: Wed, 29 Jun 2022 14:12:11 +0800

Daniel Martín <[email-masked]> writes:

> That's interesting.  Could you put a breakpoint on that C function on
> GNU/Linux to see if it's called, for example, when you close the menu?
> That may be the key difference between macOS and the other operating
> systems.  I don't have a GNU/Linux system at hand right now, but I can
> investigate if needed.
>
> (BTW, as an aside, getting a Lisp backtrace using LLDB on macOS is a bit
> time-consuming because of all the manual steps to print the pointer
> structures.  If I have time, I'd like to write an .lldbinit file with
> LLDB commands to make this process much simpler, although I don't know
> how many people are debugging Emacs using LLDB here.)

The problem is well known (to me, at least.)  [EmacsMenu
menuNeedsUpdate:] only updates the menu bar if it was actually "dirtied"
by a previous "shallow" update (see set_frame_menubar in nsmenu.m), but
that never happens when only the value of a toggle item changes.

The other window systems intercept button presses on the menu bar, and
run Lisp in the keyboard loop to update the menu bar, before pushing the
button press event back onto the event queue.  But I can't figure out
how to do that on NS, and [EmacsMenu menuNeedsUpdate:] is called too
often to not utilize the "dirty" flag.

If someone does find out how to intercept events that will open the menu
bar, then most of the NS menu bar updating logic can be thrown out the
window, which will resolve not just this problem, but several others as
well.