From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani
On Sat, May 19, 2018 at 04:42:54PM +1200, Nick Helm wrote:
> On Sat, 19 May 2018 at 07:36:32 +1200, Alan Third wrote:
>
> > There are two problems, though.
> >
> > * Application Menu
> >
> > When the last NS frame is deleted the menus aren=E2=80=99t update= d, so I think
> > they=E2=80=99ll be the menus as defined for the last frame. They = should
> > probably be cut right back to just the =E2=80=98Emacs=E2=80=99 me= nu, and perhaps
> > =E2=80=98help=E2=80=99.
>
> This is interesting. I think we could tweak the EmacsMenu side of thin= gs
> to do this, even with the current code. We'd want to make sure to<= br> > include some kind of new frame command somewhere.
>
> These menus are derived dynamically from Lisp though, and it might be<= br> > difficult to convince it to provide valid entries when no frame is
> selected.
I=E2=80=99m not sure if the =E2=80=98Emacs=E2=80=99 menu is derived from li= sp. If you turn off
menus completely it still exists.
> One way around that might be to create a new menu containing
> static NSMenu versions of File and Help, much like we do for the appMe= nu
> now. When no frame is selected and there are no Lisp menu entries, we<= br> > switch mainMenu to this new menu. When a frame is created, we switch > back.
Perhaps we could modify ns_update_menubar to handle the case where
there=E2=80=99s no frame?
> > * Dock Menu
> >
> > This has a =E2=80=98new frame=E2=80=99 option but just plain does= n=E2=80=99t work. I think the
> > problem is the way it=E2=80=99s trying to create a new frame:...<= br> > >
> > This seems to rely on there being an existing NS frame, but we=E2= =80=99ve
> > deleted the last one. I assume if we were clever we=E2=80=99d be = able to use
> > the, still open, terminal frame.
>
> With all of this discussion, I feel like I'm missing something rea= lly
> fundamental. Putting emacsclient aside for a moment, if we were dealin= g
> with a standard Cocoa app, the window server and NSApp loop would keep=
> running in the background and we could close everything, then create a=
> new frame (as a view on an NSWindow instance) as needed.
FWIW, the NSApp loop does keep running, but it=E2=80=99s embedded in ns_sel= ect
and ns_read_socket. We can, in theory, create a new frame directly,
but it needs to run through Emacs first.
> How is the architecture of Emacs on NS so different from standard Coco= a
> that these kinds of workarounds are necessary?
The fundamental issue in the NS port is that we have two bosses: the
NSApp run loop, and Emacs lisp, and we need to mediate between them.
A standard Cocoa app responds to events from the NSApp loop, and
that=E2=80=99s pretty much it. As I understand it you can make a complete a= pp
without very much work this way. The NSApp loop is the boss.
Emacs=E2=80=99 architecture expects everything to go through lisp and it ma= kes
decisions on what we do with our GUI. Emacs lisp is the boss.
We can=E2=80=99t react directly to NS events like a normal NS app. We get input from the NSApp loop and send it to lisp. Lisp might tell us to
do something any time. We also need to know how Emacs expects to do
things (the GUI code was originally written for a completely different
platform after all) and then try and make Cocoa/GNUstep handle it
correctly.
In an ideal world (and I believe the Mac port has gone this way) we
would put the NSApp run loop in one thread, and Emacs lisp in another
and let them communicate with each other asynchronously. This wouldn=E2=80= =99t
solve everything, but it would make some of our problems easier.
We can=E2=80=99t easily do that, though, as the inter=E2=80=90thread commun= ication
systems provided in Objective=E2=80=90C are either a pain to implement with=
complex types like Lisp_Object, or aren=E2=80=99t compatible with GCC and/o= r
GNUstep (Grand Central Dispatch).
Additionally I think we sometimes have workarounds fixing workarounds
fixing hacks, all written by different people, and the simplest
solution is to strip it right back to the basics. I have a feeling the
menus fall somewhat into this category, and the drag=E2=80=90n=E2=80=90drop= stuff
definitely does.
In an ideal world (and I believe the Mac port has gone this way) we
TL;DR: Emacs internal architecture doesn=E2=80=99t fit well into the standa= rd
NS application architecture.