bug#81510: 31.0.90; NS (macOS): clicking a disabled (:enable nil) tab-bar item crases Emacs

Alan Third <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
On Wed, Jul 29, 2026 at 03:41:28PM +0200, Stéphane Marks wrote:
> On Tue, Jul 28, 2026 at 10:30 PM Eli Zaretskii <[email protected]> wrote:
> 
> > > Date: Tue, 28 Jul 2026 20:10:00 +0100
> > > From: Alan Third <[email protected]>
> > > Cc: Al Haji-Ali <[email protected]>, [email protected]
> > >
> > > On Tue, Jul 28, 2026 at 09:06:45PM +0300, Eli Zaretskii wrote:
> > > > > From: Al Haji-Ali <[email protected]>
> > > > > Date: Tue, 28 Jul 2026 16:25:33 +0100
> > > > >
> > > > >
> > > > No, they both assign 'kind' unconditionally.  They then assign the
> > > > 'arg' member only if tab_bar_arg is non-nil.
> > > >
> > > > > Possible minimal fix: make handle_tab_bar_click's disabled-item
> > > > > branch return (Fcons (Qtab_bar, Qnil)) instead of bare Qnil, matching
> > > > > the "click missed" case, which nsterm.m (and presumably the other
> > > > > ports) already handle correctly as a harmless plain click. I haven't
> > > > > verified this doesn't have side effects for other callers of
> > > > > handle_tab_bar_click across the X11/w32 ports.
> > > >
> > > > I prefer that nsterm.m is changed to do the same we do in xterm.c and
> > > > w32term.c.  There's no need to change xdisp.c, which is a back-end
> > > > independent part of the display engine.
> > > >
> > > > Alan, WDYT?
> > >
> > > You mean something like this?
> >
> > Yes.
> >
> > > modified   src/nsterm.m
> > > @@ -7955,6 +7955,8 @@ - (void)mouseDown: (NSEvent *)theEvent
> > >        Lisp_Object tab_bar_arg = Qnil;
> > >        bool tab_bar_p = false;
> > >
> > > +      emacs_event->kind = MOUSE_CLICK_EVENT;
> > > +
> > >        if (WINDOWP (emacsframe->tab_bar_window)
> > >         && WINDOW_TOTAL_LINES (XWINDOW (emacsframe->tab_bar_window)))
> > >       {
> > > @@ -7971,9 +7973,12 @@ - (void)mouseDown: (NSEvent *)theEvent
> > >                                               EV_MODIFIERS (theEvent) |
> > EV_UDMODIFIERS (theEvent));
> > >       }
> > >
> > > -      if (!(tab_bar_p && NILP (tab_bar_arg)))
> > > -     emacs_event->kind = MOUSE_CLICK_EVENT;
> > > -      emacs_event->arg = tab_bar_arg;
> > > +      if (tab_bar_p && NILP (tab_bar_arg))
> > > +     emacs_event->kind = NO_EVENT;
> > > +
> > > +      if (!NILP (tab_bar_arg))
> > > +     emacs_event->arg = tab_bar_arg;
> > > +
> > >        emacs_event->code = EV_BUTTON (theEvent);
> > >        emacs_event->modifiers = EV_MODIFIERS (theEvent)
> > >                               | EV_UDMODIFIERS (theEvent);
> > >
> > > It looks functionally identical to me, but I don't really understand
> > > what's going on here...
> >
> > Does it fix the problem?
> >
> 
> Works for me.

Well, I guess I'll make it a proper patch, then.

Al Haji-Ali, are you able to check this fixes the problem for you too?
-- 
Alan Third
0001-Fix-crash-when-clicking-on-empty-tab-bar-entry-bug-8.patch (text/plain, 1.4 KB)
From 89e1986ad4fd54c91cdec75125bcb738c31d5174 Mon Sep 17 00:00:00 2001
From: Alan Third <[email protected]>
Date: Wed, 29 Jul 2026 18:43:48 +0100
Subject: [PATCH] Fix crash when clicking on empty tab bar entry (bug#81510)

* src/nsterm.m: ([EmacsView mouseDown:]): Copy order of operations
regarding mouse clicks from the w32 port.
---
 src/nsterm.m | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index a7f3fc292c7..a2ef3f19fe3 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7955,6 +7955,8 @@ - (void)mouseDown: (NSEvent *)theEvent
       Lisp_Object tab_bar_arg = Qnil;
       bool tab_bar_p = false;
 
+      emacs_event->kind = MOUSE_CLICK_EVENT;
+
       if (WINDOWP (emacsframe->tab_bar_window)
 	  && WINDOW_TOTAL_LINES (XWINDOW (emacsframe->tab_bar_window)))
 	{
@@ -7971,9 +7973,12 @@ - (void)mouseDown: (NSEvent *)theEvent
 						EV_MODIFIERS (theEvent) | EV_UDMODIFIERS (theEvent));
 	}
 
-      if (!(tab_bar_p && NILP (tab_bar_arg)))
-	emacs_event->kind = MOUSE_CLICK_EVENT;
-      emacs_event->arg = tab_bar_arg;
+      if (tab_bar_p && NILP (tab_bar_arg))
+	emacs_event->kind = NO_EVENT;
+
+      if (!NILP (tab_bar_arg))
+	emacs_event->arg = tab_bar_arg;
+
       emacs_event->code = EV_BUTTON (theEvent);
       emacs_event->modifiers = EV_MODIFIERS (theEvent)
                              | EV_UDMODIFIERS (theEvent);
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.