Subject: bug#70086: Mouse clicks in tab-bar don't call commands bound in keymap properties

From: Adam Porter <[email-masked]>
Date: Fri, 29 Mar 2024 21:25:25 -0500

Hi Juri, et al,

In my listen.el package on GNU ELPA, I'm trying to make mouse clicks in 
the `global-mode-string' construct work when `mode-line-misc-info' is 
shown in the tab-bar by including `tab-bar-format-global' in 
`tab-bar-format'.  I'm including this construct in the `global-mode-string':

   `(listen-mode (:propertize listen-mode-lighter
                              keymap ,listen-mode-lighter-map))

Using this keymap:

   (defvar listen-mode-lighter-map
     (let ((map (make-sparse-keymap)))
       (define-key map [mode-line mouse-1] #'listen-pause)
       (define-key map [tab-bar mouse-1] #'listen-pause)
       (define-key map [tab-bar mouse-2] #'listen-pause)
       (define-key map [tab-bar mouse-3] #'listen-pause)
       (define-key map [tab-bar down-mouse-1] #'listen-pause)
       (define-key map [tab-bar down-mouse-2] #'listen-pause)
       (define-key map [tab-bar down-mouse-3] #'listen-pause)
       map))

When that construct is used in `mode-line-format', it works as expected: 
clicking with mouse-1 calls the command `listen-pause'.

But when that same construct is shown in the tab-bar, mouse-1 and 
mouse-2 clicks have no effect, and mouse-3 shows the tab-bar context 
menu with options for "New tab" and "Reopen closed tab".

Surprisingly, using the sequence "C-h k mouse-1" on the construct in the 
tab-bar shows that the binding appears to be read correctly:

   There were several key-sequences:

     <tab-bar> <down-mouse-1> at that spot runs the command listen-pause
     <tab-bar> <mouse-1> at that spot runs the command listen-pause

   They're all described below.

   <tab-bar> <down-mouse-1> at that spot runs the command listen-pause
   (found in listen-mode-lighter-map), which is an interactive
   native-compiled Lisp function in ‘listen.el’.

   (listen-pause PLAYER)

   Pause/unpause PLAYER.
   Interactively, uses the default player.

   <tab-bar> <mouse-1> at that spot runs the command listen-pause (found
   in listen-mode-lighter-map), which is an interactive native-compiled
   Lisp function in ‘listen.el’.

   (listen-pause PLAYER)

   Pause/unpause PLAYER.
   Interactively, uses the default player.

But when used without "C-h k", it has no effect.

Looking at tab-bar.el, I see that it does some, I suppose, unusual 
things with keymaps and clicks to make them work.  However, if this 
could be fixed to allow these commands to work properly, it would be 
very useful, as the extra space in the tab-bar is a great place to 
display extra information without crowding the mode line.

Thanks,
Adam