aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2021-04-13 16:40:42 +0300
committerEli Zaretskii2021-04-13 16:40:42 +0300
commit1667253fec963e2ffb2bb36db67564533cf92787 (patch)
treea110b3de13e980b687259875e9ef253462fcdc01
parent6de79542e43ece9a12ebc032c275a6c3fee0b73b (diff)
downloademacs-1667253fec963e2ffb2bb36db67564533cf92787.tar.gz
emacs-1667253fec963e2ffb2bb36db67564533cf92787.zip
Resurrect mouse-highlight of close buttons on tab-bar
* src/w32term.c (w32_draw_image_relief): Support tab-bar drawing with relief as xterm.c does. * src/xdisp.c (handle_tab_bar_click): Access the mouse-highlight info. Call show_mouse_face to show the button in the pressed or the released state, according to value of DOWN_P. (note_tab_bar_highlight): Function added back. (note_mouse_highlight): Call note_tab_bar_highlight when the mouse pointer is in the tab-bar window. (show_mouse_face): Return immediately if mouse_face_window is not set up in HLINFO. This avoids rare assertion violations.
-rw-r--r--src/w32term.c20
-rw-r--r--src/xdisp.c116
2 files changed, 131 insertions, 5 deletions
diff --git a/src/w32term.c b/src/w32term.c
index 0ee805a8526..361cf33c024 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -2031,8 +2031,11 @@ w32_draw_image_relief (struct glyph_string *s)
2031 if (s->hl == DRAW_IMAGE_SUNKEN 2031 if (s->hl == DRAW_IMAGE_SUNKEN
2032 || s->hl == DRAW_IMAGE_RAISED) 2032 || s->hl == DRAW_IMAGE_RAISED)
2033 { 2033 {
2034 thick = tool_bar_button_relief >= 0 ? tool_bar_button_relief 2034 thick = (tab_bar_button_relief < 0
2035 : DEFAULT_TOOL_BAR_BUTTON_RELIEF; 2035 ? DEFAULT_TAB_BAR_BUTTON_RELIEF
2036 : (tool_bar_button_relief < 0
2037 ? DEFAULT_TOOL_BAR_BUTTON_RELIEF
2038 : min (tool_bar_button_relief, 1000000)));
2036 raised_p = s->hl == DRAW_IMAGE_RAISED; 2039 raised_p = s->hl == DRAW_IMAGE_RAISED;
2037 } 2040 }
2038 else 2041 else
@@ -2045,6 +2048,19 @@ w32_draw_image_relief (struct glyph_string *s)
2045 y1 = y + s->slice.height - 1; 2048 y1 = y + s->slice.height - 1;
2046 2049
2047 extra_x = extra_y = 0; 2050 extra_x = extra_y = 0;
2051 if (s->face->id == TAB_BAR_FACE_ID)
2052 {
2053 if (CONSP (Vtab_bar_button_margin)
2054 && FIXNUMP (XCAR (Vtab_bar_button_margin))
2055 && FIXNUMP (XCDR (Vtab_bar_button_margin)))
2056 {
2057 extra_x = XFIXNUM (XCAR (Vtab_bar_button_margin));
2058 extra_y = XFIXNUM (XCDR (Vtab_bar_button_margin));
2059 }
2060 else if (FIXNUMP (Vtab_bar_button_margin))
2061 extra_x = extra_y = XFIXNUM (Vtab_bar_button_margin);
2062 }
2063
2048 if (s->face->id == TOOL_BAR_FACE_ID) 2064 if (s->face->id == TOOL_BAR_FACE_ID)
2049 { 2065 {
2050 if (CONSP (Vtool_bar_button_margin) 2066 if (CONSP (Vtool_bar_button_margin)
diff --git a/src/xdisp.c b/src/xdisp.c
index 50d9040057a..8f7180381b4 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13682,6 +13682,7 @@ void
13682handle_tab_bar_click (struct frame *f, int x, int y, bool down_p, 13682handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
13683 int modifiers) 13683 int modifiers)
13684{ 13684{
13685 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
13685 struct window *w = XWINDOW (f->tab_bar_window); 13686 struct window *w = XWINDOW (f->tab_bar_window);
13686 int hpos, vpos, prop_idx; 13687 int hpos, vpos, prop_idx;
13687 bool close_p; 13688 bool close_p;
@@ -13703,13 +13704,22 @@ handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
13703 return; 13704 return;
13704 13705
13705 if (down_p) 13706 if (down_p)
13706 f->last_tab_bar_item = prop_idx; /* record the pressed tab */ 13707 {
13708 /* Show the clicked button in pressed state. */
13709 if (!NILP (Vmouse_highlight))
13710 show_mouse_face (hlinfo, DRAW_IMAGE_SUNKEN);
13711 f->last_tab_bar_item = prop_idx; /* record the pressed tab */
13712 }
13707 else 13713 else
13708 { 13714 {
13709 Lisp_Object key, frame; 13715 Lisp_Object key, frame;
13710 struct input_event event; 13716 struct input_event event;
13711 EVENT_INIT (event); 13717 EVENT_INIT (event);
13712 13718
13719 /* Show item in released state. */
13720 if (!NILP (Vmouse_highlight))
13721 show_mouse_face (hlinfo, DRAW_IMAGE_RAISED);
13722
13713 key = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_KEY); 13723 key = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_KEY);
13714 13724
13715 XSETFRAME (frame, f); 13725 XSETFRAME (frame, f);
@@ -13722,6 +13732,97 @@ handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
13722 } 13732 }
13723} 13733}
13724 13734
13735
13736/* Possibly highlight a tab-bar item on frame F when mouse moves to
13737 tab-bar window-relative coordinates X/Y. Called from
13738 note_mouse_highlight. */
13739
13740static void
13741note_tab_bar_highlight (struct frame *f, int x, int y)
13742{
13743 Lisp_Object window = f->tab_bar_window;
13744 struct window *w = XWINDOW (window);
13745 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
13746 int hpos, vpos;
13747 struct glyph *glyph;
13748 struct glyph_row *row;
13749 int i;
13750 Lisp_Object enabled_p;
13751 int prop_idx;
13752 bool close_p;
13753 enum draw_glyphs_face draw = DRAW_IMAGE_RAISED;
13754 int rc;
13755
13756 /* Function note_mouse_highlight is called with negative X/Y
13757 values when mouse moves outside of the frame. */
13758 if (x <= 0 || y <= 0)
13759 {
13760 clear_mouse_face (hlinfo);
13761 return;
13762 }
13763
13764 rc = get_tab_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx, &close_p);
13765 if (rc < 0)
13766 {
13767 /* Not on tab-bar item. */
13768 clear_mouse_face (hlinfo);
13769 return;
13770 }
13771 else if (rc == 0)
13772 /* On same tab-bar item as before. */
13773 goto set_help_echo;
13774
13775 clear_mouse_face (hlinfo);
13776
13777 bool mouse_down_p = false;
13778#ifndef HAVE_NS
13779 /* Mouse is down, but on different tab-bar item? */
13780 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
13781 mouse_down_p = (gui_mouse_grabbed (dpyinfo)
13782 && f == dpyinfo->last_mouse_frame);
13783
13784 if (mouse_down_p && f->last_tab_bar_item != prop_idx)
13785 return;
13786#endif
13787 draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED;
13788
13789 /* If tab-bar item is not enabled, don't highlight it. */
13790 enabled_p = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_ENABLED_P);
13791 if (!NILP (enabled_p) && !NILP (Vmouse_highlight))
13792 {
13793 /* Compute the x-position of the glyph. In front and past the
13794 image is a space. We include this in the highlighted area. */
13795 row = MATRIX_ROW (w->current_matrix, vpos);
13796 for (i = x = 0; i < hpos; ++i)
13797 x += row->glyphs[TEXT_AREA][i].pixel_width;
13798
13799 /* Record this as the current active region. */
13800 hlinfo->mouse_face_beg_col = hpos;
13801 hlinfo->mouse_face_beg_row = vpos;
13802 hlinfo->mouse_face_beg_x = x;
13803 hlinfo->mouse_face_past_end = false;
13804
13805 hlinfo->mouse_face_end_col = hpos + 1;
13806 hlinfo->mouse_face_end_row = vpos;
13807 hlinfo->mouse_face_end_x = x + glyph->pixel_width;
13808 hlinfo->mouse_face_window = window;
13809 hlinfo->mouse_face_face_id = TAB_BAR_FACE_ID;
13810
13811 /* Display it as active. */
13812 show_mouse_face (hlinfo, draw);
13813 }
13814
13815 set_help_echo:
13816
13817 /* Set help_echo_string to a help string to display for this tab-bar item.
13818 XTread_socket does the rest. */
13819 help_echo_object = help_echo_window = Qnil;
13820 help_echo_pos = -1;
13821 help_echo_string = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_HELP);
13822 if (NILP (help_echo_string))
13823 help_echo_string = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_CAPTION);
13824}
13825
13725#endif /* HAVE_WINDOW_SYSTEM */ 13826#endif /* HAVE_WINDOW_SYSTEM */
13726 13827
13727/* Find the tab-bar item at X coordinate and return its information. */ 13828/* Find the tab-bar item at X coordinate and return its information. */
@@ -31860,6 +31961,11 @@ draw_row_with_mouse_face (struct window *w, int start_x, struct glyph_row *row,
31860static void 31961static void
31861show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw) 31962show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw)
31862{ 31963{
31964 /* Don't bother doing anything if the mouse-face window is not set
31965 up. */
31966 if (!WINDOWP (hlinfo->mouse_face_window))
31967 return;
31968
31863 struct window *w = XWINDOW (hlinfo->mouse_face_window); 31969 struct window *w = XWINDOW (hlinfo->mouse_face_window);
31864 struct frame *f = XFRAME (WINDOW_FRAME (w)); 31970 struct frame *f = XFRAME (WINDOW_FRAME (w));
31865 31971
@@ -33414,9 +33520,13 @@ note_mouse_highlight (struct frame *f, int x, int y)
33414 frame_to_window_pixel_xy (w, &x, &y); 33520 frame_to_window_pixel_xy (w, &x, &y);
33415 33521
33416#if defined (HAVE_WINDOW_SYSTEM) 33522#if defined (HAVE_WINDOW_SYSTEM)
33417 /* We don't highlight tab-bar buttons. */ 33523 /* Handle tab-bar window differently since it doesn't display a
33524 buffer. */
33418 if (EQ (window, f->tab_bar_window)) 33525 if (EQ (window, f->tab_bar_window))
33419 return; 33526 {
33527 note_tab_bar_highlight (f, x, y);
33528 return;
33529 }
33420#endif 33530#endif
33421 33531
33422#if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) 33532#if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR)