Subject: bug#51794: 29.0.50; invalid input events generated from a mouse click for the tab bar

From: martin rudalics <[email-masked]>
Date: Fri, 19 Nov 2021 10:26:52 +0100

>> bug fix #50993 is the bug.  it made make_lispy_position skip setting
 >> posn to the tab_bar if track_mouse is non-nil.  why track_mouse is nil
 >> for some frames and not for others i didn't look into.
 >> thoughts/comments?
 >
 > Please do look into that last part, because we need to understand the
 > situations in which this happens well enough to devise a solution.  We
 > don't want to revert that fix because it will re-introduce a larger
 > problem.  Specifically, why does this happen to you only under those
 > customizations and not in "emacs -Q"?
 >
 > Martin, any suggestions?

Maybe the attached patch helps.

martin
diff --git a/lisp/mouse-drag.el b/lisp/mouse-drag.el
index ecfb359b36..98e18a5c86 100644
--- a/lisp/mouse-drag.el
+++ b/lisp/mouse-drag.el
@@ -282,6 +282,7 @@ mouse-drag-drag
     (setq window-last-row (- (window-height) 2)
 	  window-last-col (- (window-width) 2))
     (track-mouse
+      (setq track-mouse 'drag-dragging)
       (while (progn
 	       (setq event (read--potential-mouse-event)
 		     end (event-end event)
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 7bac6dd07b..c94862d01b 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -1615,7 +1615,7 @@ mouse-drag-track
       (goto-char (nth 1 range)))

     (setf (terminal-parameter nil 'mouse-drag-start) start-event)
-    (setq track-mouse t)
+    (setq track-mouse 'drag-tracking)
     (setq auto-hscroll-mode nil)

     (set-transient-map
diff --git a/src/keyboard.c b/src/keyboard.c
index a99d14cb4c..abd9635a92 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -5136,7 +5136,7 @@ make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,

 	 This issue should be properly handled by 'mouse-drag-track' and
 	 friends, so the below is only a temporary workaround.  */
-      if (NILP (track_mouse))
+      if (NILP (track_mouse) || EQ (track_mouse, Qt))
 	posn = EQ (window_or_frame, f->tab_bar_window) ? Qtab_bar : Qtool_bar;
       /* Kludge alert: for mouse events on the tab bar and tool bar,
 	 keyboard.c wants the frame, not the special-purpose window