diff options
| author | Eli Zaretskii | 2021-04-11 12:12:45 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2021-04-11 12:12:45 +0300 |
| commit | 3cf9e2a6e33599bb12a949a3b5bd1847f39ab948 (patch) | |
| tree | c84328d8003838cec65669872dcad95a42a57d71 /src | |
| parent | 0f494760d3344201f0c01723c246ba0ad2d15d90 (diff) | |
| download | emacs-3cf9e2a6e33599bb12a949a3b5bd1847f39ab948.tar.gz emacs-3cf9e2a6e33599bb12a949a3b5bd1847f39ab948.zip | |
Fix handling of mouse clicks on tab-bar buttons
* src/xdisp.c (note_mouse_highlight): Don't attempt to highlight
tab-bar buttons.
(note_tab_bar_highlight): Function deleted: it had no effect on
display of tab-bar buttons.
(tab_bar_item_info): Mention all arguments in the commentary.
(get_tab_bar_item): Don't pay attention to mouse-highlight
information; instead, compare the button's index with the one
recorded in f->last_tab_bar_item.
(handle_tab_bar_click): Don't attempt to show tab-bar buttons in
pressed or released state: that isn't supported. Determine
whether to generate a tab-bar button click based on DOWN_P
argument, not on mouse-highlight, which has no effect on tab-bar
display. (Bug#47581)
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 147 |
1 files changed, 10 insertions, 137 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index a405d51f803..50d9040057a 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -13607,8 +13607,9 @@ redisplay_tab_bar (struct frame *f) | |||
| 13607 | 13607 | ||
| 13608 | /* Get information about the tab-bar item which is displayed in GLYPH | 13608 | /* Get information about the tab-bar item which is displayed in GLYPH |
| 13609 | on frame F. Return in *PROP_IDX the index where tab-bar item | 13609 | on frame F. Return in *PROP_IDX the index where tab-bar item |
| 13610 | properties start in F->tab_bar_items. Value is false if | 13610 | properties start in F->tab_bar_items. Return in CLOSE_P an |
| 13611 | GLYPH doesn't display a tab-bar item. */ | 13611 | indication whether the click was on the close-tab icon of the tab. |
| 13612 | Value is false if GLYPH doesn't display a tab-bar item. */ | ||
| 13612 | 13613 | ||
| 13613 | static bool | 13614 | static bool |
| 13614 | tab_bar_item_info (struct frame *f, struct glyph *glyph, | 13615 | tab_bar_item_info (struct frame *f, struct glyph *glyph, |
| @@ -13654,7 +13655,6 @@ static int | |||
| 13654 | get_tab_bar_item (struct frame *f, int x, int y, struct glyph **glyph, | 13655 | get_tab_bar_item (struct frame *f, int x, int y, struct glyph **glyph, |
| 13655 | int *hpos, int *vpos, int *prop_idx, bool *close_p) | 13656 | int *hpos, int *vpos, int *prop_idx, bool *close_p) |
| 13656 | { | 13657 | { |
| 13657 | Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); | ||
| 13658 | struct window *w = XWINDOW (f->tab_bar_window); | 13658 | struct window *w = XWINDOW (f->tab_bar_window); |
| 13659 | int area; | 13659 | int area; |
| 13660 | 13660 | ||
| @@ -13668,18 +13668,7 @@ get_tab_bar_item (struct frame *f, int x, int y, struct glyph **glyph, | |||
| 13668 | if (!tab_bar_item_info (f, *glyph, prop_idx, close_p)) | 13668 | if (!tab_bar_item_info (f, *glyph, prop_idx, close_p)) |
| 13669 | return -1; | 13669 | return -1; |
| 13670 | 13670 | ||
| 13671 | /* Is mouse on the highlighted item? */ | 13671 | return *prop_idx == f->last_tab_bar_item ? 0 : 1; |
| 13672 | if (EQ (f->tab_bar_window, hlinfo->mouse_face_window) | ||
| 13673 | && *vpos >= hlinfo->mouse_face_beg_row | ||
| 13674 | && *vpos <= hlinfo->mouse_face_end_row | ||
| 13675 | && (*vpos > hlinfo->mouse_face_beg_row | ||
| 13676 | || *hpos >= hlinfo->mouse_face_beg_col) | ||
| 13677 | && (*vpos < hlinfo->mouse_face_end_row | ||
| 13678 | || *hpos < hlinfo->mouse_face_end_col | ||
| 13679 | || hlinfo->mouse_face_past_end)) | ||
| 13680 | return 0; | ||
| 13681 | |||
| 13682 | return 1; | ||
| 13683 | } | 13672 | } |
| 13684 | 13673 | ||
| 13685 | 13674 | ||
| @@ -13693,7 +13682,6 @@ void | |||
| 13693 | handle_tab_bar_click (struct frame *f, int x, int y, bool down_p, | 13682 | handle_tab_bar_click (struct frame *f, int x, int y, bool down_p, |
| 13694 | int modifiers) | 13683 | int modifiers) |
| 13695 | { | 13684 | { |
| 13696 | Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); | ||
| 13697 | struct window *w = XWINDOW (f->tab_bar_window); | 13685 | struct window *w = XWINDOW (f->tab_bar_window); |
| 13698 | int hpos, vpos, prop_idx; | 13686 | int hpos, vpos, prop_idx; |
| 13699 | bool close_p; | 13687 | bool close_p; |
| @@ -13701,47 +13689,27 @@ handle_tab_bar_click (struct frame *f, int x, int y, bool down_p, | |||
| 13701 | Lisp_Object enabled_p; | 13689 | Lisp_Object enabled_p; |
| 13702 | int ts; | 13690 | int ts; |
| 13703 | 13691 | ||
| 13704 | /* If not on the highlighted tab-bar item, and mouse-highlight is | ||
| 13705 | non-nil, return. This is so we generate the tab-bar button | ||
| 13706 | click only when the mouse button is released on the same item as | ||
| 13707 | where it was pressed. However, when mouse-highlight is disabled, | ||
| 13708 | generate the click when the button is released regardless of the | ||
| 13709 | highlight, since tab-bar items are not highlighted in that | ||
| 13710 | case. */ | ||
| 13711 | frame_to_window_pixel_xy (w, &x, &y); | 13692 | frame_to_window_pixel_xy (w, &x, &y); |
| 13712 | ts = get_tab_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx, &close_p); | 13693 | ts = get_tab_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx, &close_p); |
| 13713 | if (ts == -1 | 13694 | if (ts == -1 |
| 13714 | || (ts != 0 && !NILP (Vmouse_highlight))) | 13695 | /* If the button is released on a tab other than the one where |
| 13696 | it was pressed, don't generate the tab-bar button click event. */ | ||
| 13697 | || (ts != 0 && !down_p)) | ||
| 13715 | return; | 13698 | return; |
| 13716 | 13699 | ||
| 13717 | /* When mouse-highlight is off, generate the click for the item | ||
| 13718 | where the button was pressed, disregarding where it was | ||
| 13719 | released. */ | ||
| 13720 | if (NILP (Vmouse_highlight) && !down_p) | ||
| 13721 | prop_idx = f->last_tab_bar_item; | ||
| 13722 | |||
| 13723 | /* If item is disabled, do nothing. */ | 13700 | /* If item is disabled, do nothing. */ |
| 13724 | enabled_p = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_ENABLED_P); | 13701 | enabled_p = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_ENABLED_P); |
| 13725 | if (NILP (enabled_p)) | 13702 | if (NILP (enabled_p)) |
| 13726 | return; | 13703 | return; |
| 13727 | 13704 | ||
| 13728 | if (down_p) | 13705 | if (down_p) |
| 13729 | { | 13706 | f->last_tab_bar_item = prop_idx; /* record the pressed tab */ |
| 13730 | /* Show item in pressed state. */ | ||
| 13731 | if (!NILP (Vmouse_highlight)) | ||
| 13732 | show_mouse_face (hlinfo, DRAW_IMAGE_SUNKEN); | ||
| 13733 | f->last_tab_bar_item = prop_idx; | ||
| 13734 | } | ||
| 13735 | else | 13707 | else |
| 13736 | { | 13708 | { |
| 13737 | Lisp_Object key, frame; | 13709 | Lisp_Object key, frame; |
| 13738 | struct input_event event; | 13710 | struct input_event event; |
| 13739 | EVENT_INIT (event); | 13711 | EVENT_INIT (event); |
| 13740 | 13712 | ||
| 13741 | /* Show item in released state. */ | ||
| 13742 | if (!NILP (Vmouse_highlight)) | ||
| 13743 | show_mouse_face (hlinfo, DRAW_IMAGE_RAISED); | ||
| 13744 | |||
| 13745 | key = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_KEY); | 13713 | key = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_KEY); |
| 13746 | 13714 | ||
| 13747 | XSETFRAME (frame, f); | 13715 | XSETFRAME (frame, f); |
| @@ -13754,97 +13722,6 @@ handle_tab_bar_click (struct frame *f, int x, int y, bool down_p, | |||
| 13754 | } | 13722 | } |
| 13755 | } | 13723 | } |
| 13756 | 13724 | ||
| 13757 | |||
| 13758 | /* Possibly highlight a tab-bar item on frame F when mouse moves to | ||
| 13759 | tab-bar window-relative coordinates X/Y. Called from | ||
| 13760 | note_mouse_highlight. */ | ||
| 13761 | |||
| 13762 | static void | ||
| 13763 | note_tab_bar_highlight (struct frame *f, int x, int y) | ||
| 13764 | { | ||
| 13765 | Lisp_Object window = f->tab_bar_window; | ||
| 13766 | struct window *w = XWINDOW (window); | ||
| 13767 | Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); | ||
| 13768 | int hpos, vpos; | ||
| 13769 | struct glyph *glyph; | ||
| 13770 | struct glyph_row *row; | ||
| 13771 | int i; | ||
| 13772 | Lisp_Object enabled_p; | ||
| 13773 | int prop_idx; | ||
| 13774 | bool close_p; | ||
| 13775 | enum draw_glyphs_face draw = DRAW_IMAGE_RAISED; | ||
| 13776 | int rc; | ||
| 13777 | |||
| 13778 | /* Function note_mouse_highlight is called with negative X/Y | ||
| 13779 | values when mouse moves outside of the frame. */ | ||
| 13780 | if (x <= 0 || y <= 0) | ||
| 13781 | { | ||
| 13782 | clear_mouse_face (hlinfo); | ||
| 13783 | return; | ||
| 13784 | } | ||
| 13785 | |||
| 13786 | rc = get_tab_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx, &close_p); | ||
| 13787 | if (rc < 0) | ||
| 13788 | { | ||
| 13789 | /* Not on tab-bar item. */ | ||
| 13790 | clear_mouse_face (hlinfo); | ||
| 13791 | return; | ||
| 13792 | } | ||
| 13793 | else if (rc == 0) | ||
| 13794 | /* On same tab-bar item as before. */ | ||
| 13795 | goto set_help_echo; | ||
| 13796 | |||
| 13797 | clear_mouse_face (hlinfo); | ||
| 13798 | |||
| 13799 | bool mouse_down_p = false; | ||
| 13800 | #ifndef HAVE_NS | ||
| 13801 | /* Mouse is down, but on different tab-bar item? */ | ||
| 13802 | Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f); | ||
| 13803 | mouse_down_p = (gui_mouse_grabbed (dpyinfo) | ||
| 13804 | && f == dpyinfo->last_mouse_frame); | ||
| 13805 | |||
| 13806 | if (mouse_down_p && f->last_tab_bar_item != prop_idx) | ||
| 13807 | return; | ||
| 13808 | #endif | ||
| 13809 | draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED; | ||
| 13810 | |||
| 13811 | /* If tab-bar item is not enabled, don't highlight it. */ | ||
| 13812 | enabled_p = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_ENABLED_P); | ||
| 13813 | if (!NILP (enabled_p) && !NILP (Vmouse_highlight)) | ||
| 13814 | { | ||
| 13815 | /* Compute the x-position of the glyph. In front and past the | ||
| 13816 | image is a space. We include this in the highlighted area. */ | ||
| 13817 | row = MATRIX_ROW (w->current_matrix, vpos); | ||
| 13818 | for (i = x = 0; i < hpos; ++i) | ||
| 13819 | x += row->glyphs[TEXT_AREA][i].pixel_width; | ||
| 13820 | |||
| 13821 | /* Record this as the current active region. */ | ||
| 13822 | hlinfo->mouse_face_beg_col = hpos; | ||
| 13823 | hlinfo->mouse_face_beg_row = vpos; | ||
| 13824 | hlinfo->mouse_face_beg_x = x; | ||
| 13825 | hlinfo->mouse_face_past_end = false; | ||
| 13826 | |||
| 13827 | hlinfo->mouse_face_end_col = hpos + 1; | ||
| 13828 | hlinfo->mouse_face_end_row = vpos; | ||
| 13829 | hlinfo->mouse_face_end_x = x + glyph->pixel_width; | ||
| 13830 | hlinfo->mouse_face_window = window; | ||
| 13831 | hlinfo->mouse_face_face_id = TAB_BAR_FACE_ID; | ||
| 13832 | |||
| 13833 | /* Display it as active. */ | ||
| 13834 | show_mouse_face (hlinfo, draw); | ||
| 13835 | } | ||
| 13836 | |||
| 13837 | set_help_echo: | ||
| 13838 | |||
| 13839 | /* Set help_echo_string to a help string to display for this tab-bar item. | ||
| 13840 | XTread_socket does the rest. */ | ||
| 13841 | help_echo_object = help_echo_window = Qnil; | ||
| 13842 | help_echo_pos = -1; | ||
| 13843 | help_echo_string = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_HELP); | ||
| 13844 | if (NILP (help_echo_string)) | ||
| 13845 | help_echo_string = AREF (f->tab_bar_items, prop_idx + TAB_BAR_ITEM_CAPTION); | ||
| 13846 | } | ||
| 13847 | |||
| 13848 | #endif /* HAVE_WINDOW_SYSTEM */ | 13725 | #endif /* HAVE_WINDOW_SYSTEM */ |
| 13849 | 13726 | ||
| 13850 | /* Find the tab-bar item at X coordinate and return its information. */ | 13727 | /* Find the tab-bar item at X coordinate and return its information. */ |
| @@ -33537,13 +33414,9 @@ note_mouse_highlight (struct frame *f, int x, int y) | |||
| 33537 | frame_to_window_pixel_xy (w, &x, &y); | 33414 | frame_to_window_pixel_xy (w, &x, &y); |
| 33538 | 33415 | ||
| 33539 | #if defined (HAVE_WINDOW_SYSTEM) | 33416 | #if defined (HAVE_WINDOW_SYSTEM) |
| 33540 | /* Handle tab-bar window differently since it doesn't display a | 33417 | /* We don't highlight tab-bar buttons. */ |
| 33541 | buffer. */ | ||
| 33542 | if (EQ (window, f->tab_bar_window)) | 33418 | if (EQ (window, f->tab_bar_window)) |
| 33543 | { | 33419 | return; |
| 33544 | note_tab_bar_highlight (f, x, y); | ||
| 33545 | return; | ||
| 33546 | } | ||
| 33547 | #endif | 33420 | #endif |
| 33548 | 33421 | ||
| 33549 | #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) | 33422 | #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) |