Subject: bug#51298: 29.0.50; Tab bar buttons won't highlight after the mouse is released outside the tab bar

From: Po Lu <[email-masked]>
Date: Wed, 20 Oct 2021 15:59:36 +0800

BTW, I'm attaching another patch that makes the tab bar behave closer to
other programs.  I've explained the behaviour in the commit message.

WDYT?

>From 69b4f84bdcd76bccee1e2af5b334b03ace918f9f Mon Sep 17 00:00:00 2001
From: Po Lu <[email-masked]>
Date: Wed, 20 Oct 2021 15:55:10 +0800
Subject: [PATCH] Display a tab bar item as sunken when appropriate

When the mouse pointer is pressed on the tab bar, moved out of the tab
bar, and moved back in, it would be more appropriate to behave like
other programs by displaying the item as sunken.

* src/xdisp.c (note_tab_bar_highlight): Display item as sunken if the
mouse pointer returns to the tab bar down.
---
 src/xdisp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index c6b8ca636e..72b359789d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13866,12 +13866,17 @@ note_tab_bar_highlight (struct frame *f, int x, int y)
   clear_mouse_face (hlinfo);
 
   bool mouse_down_p = false;
-  /* Mouse is down, but on different tab-bar item?  */
+  /* Mouse is down, but on different tab-bar item?  Or alternatively,
+     the mouse might've been pressed somewhere we don't know about,
+     and then have moved onto the tab bar.  In this case,
+     last_tab_bar_item is -1, so we DTRT and behave like other
+     programs by displaying the item as sunken. */
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
   mouse_down_p = (gui_mouse_grabbed (dpyinfo)
 		  && f == dpyinfo->last_mouse_frame);
 
-  if (mouse_down_p && f->last_tab_bar_item != prop_idx)
+  if (mouse_down_p && f->last_tab_bar_item != prop_idx
+      && f->last_tab_bar_item != -1)
     return;
   draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED;
 
-- 
2.31.1