summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2021-09-05 20:16:33 +0300
committerJuri Linkov <juri@linkov.net>2021-09-05 20:16:33 +0300
commit794fdce55d097f2b58ce37818edffb2deef7b9de (patch)
tree42c14ae6326ae151f3e943d264074a2671ccda98 /src
parentad9c57f54ae3eea9e5b2fe9264e9edb8b2ed1857 (diff)
Improve tab-bar event handling (bug#41343)
* lisp/tab-bar.el (tab-bar--key-to-number): Rename from tab--key-to-number. (tab-bar--event-to-item): New function from tab-bar-handle-mouse. (tab-bar-mouse-select-tab, tab-bar-mouse-close-tab) (tab-bar-mouse-context-menu, tab-bar-mouse-move-tab): Use tab-bar--event-to-item. * src/menu.c (x_popup_menu_1): Handle Qtab_bar in the second list element. * src/xdisp.c (tty_get_tab_bar_item): Change arg 'end' to bool 'close_p'. (tty_get_tab_bar_item): Detect if the close button was clicked. (tty_handle_tab_bar_click): Return a list with caption that has text properties.
Diffstat (limited to 'src')
-rw-r--r--src/menu.c9
-rw-r--r--src/w32term.c10
-rw-r--r--src/xdisp.c44
-rw-r--r--src/xterm.c10
4 files changed, 38 insertions, 35 deletions
diff --git a/src/menu.c b/src/menu.c
index 3b1d7402571..990a74b92e3 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1127,9 +1127,12 @@ x_popup_menu_1 (Lisp_Object position, Lisp_Object menu)
/* Decode the first argument: find the window and the coordinates. */
if (EQ (position, Qt)
- || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
- || EQ (XCAR (position), Qtab_bar)
- || EQ (XCAR (position), Qtool_bar))))
+ || (CONSP (position)
+ && (EQ (XCAR (position), Qmenu_bar)
+ || EQ (XCAR (position), Qtab_bar)
+ || (CONSP (XCDR (position))
+ && EQ (XCAR (XCDR (position)), Qtab_bar))
+ || EQ (XCAR (position), Qtool_bar))))
{
get_current_pos_p = 1;
}
diff --git a/src/w32term.c b/src/w32term.c
index c9570b0c670..aca4739a2e3 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -5186,7 +5186,7 @@ w32_read_socket (struct terminal *terminal,
{
/* If we decide we want to generate an event to be seen
by the rest of Emacs, we put it here. */
- Lisp_Object tab_bar_key = Qnil;
+ Lisp_Object tab_bar_arg = Qnil;
bool tab_bar_p = 0;
bool tool_bar_p = 0;
int button = 0;
@@ -5209,12 +5209,12 @@ w32_read_socket (struct terminal *terminal,
if (EQ (window, f->tab_bar_window))
{
- tab_bar_key = w32_handle_tab_bar_click (f, &inev);
+ tab_bar_arg = w32_handle_tab_bar_click (f, &inev);
tab_bar_p = 1;
}
}
- if ((tab_bar_p && NILP (tab_bar_key))
+ if ((tab_bar_p && NILP (tab_bar_arg))
|| (dpyinfo->w32_focus_frame
&& f != dpyinfo->w32_focus_frame
/* This does not help when the click happens in
@@ -5222,8 +5222,8 @@ w32_read_socket (struct terminal *terminal,
&& !frame_ancestor_p (f, dpyinfo->w32_focus_frame)))
inev.kind = NO_EVENT;
- if (!NILP (tab_bar_key))
- inev.arg = tab_bar_key;
+ if (!NILP (tab_bar_arg))
+ inev.arg = tab_bar_arg;
/* Is this in the tool-bar? */
if (WINDOWP (f->tool_bar_window)
diff --git a/src/xdisp.c b/src/xdisp.c
index 4a5ab172cc1..91f9bb98e6f 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13891,7 +13891,7 @@ note_tab_bar_highlight (struct frame *f, int x, int y)
/* Find the tab-bar item at X coordinate and return its information. */
static Lisp_Object
-tty_get_tab_bar_item (struct frame *f, int x, int *idx, ptrdiff_t *end)
+tty_get_tab_bar_item (struct frame *f, int x, int *prop_idx, bool *close_p)
{
ptrdiff_t clen = 0;
@@ -13904,8 +13904,11 @@ tty_get_tab_bar_item (struct frame *f, int x, int *idx, ptrdiff_t *end)
clen += SCHARS (caption);
if (x < clen)
{
- *idx = i;
- *end = clen;
+ *prop_idx = i;
+ *close_p = !NILP (Fget_text_property (make_fixnum (SCHARS (caption)
+ - (clen - x)),
+ Qclose_tab,
+ caption));
return caption;
}
}
@@ -13928,8 +13931,8 @@ tty_handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
/* Find the tab-bar item where the X,Y coordinates belong. */
int prop_idx;
- ptrdiff_t clen;
- Lisp_Object caption = tty_get_tab_bar_item (f, x, &prop_idx, &clen);
+ bool close_p;
+ Lisp_Object caption = tty_get_tab_bar_item (f, x, &prop_idx, &close_p);
if (NILP (caption))
return Qnil;
@@ -13941,24 +13944,21 @@ tty_handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
if (down_p)
f->last_tab_bar_item = prop_idx;
else
- {
- f->last_tab_bar_item = -1;
- }
+ f->last_tab_bar_item = -1;
- /* Generate a TAB_BAR_EVENT event. */
- Lisp_Object key = AREF (f->tab_bar_items,
- prop_idx * TAB_BAR_ITEM_NSLOTS
- + TAB_BAR_ITEM_KEY);
- /* Kludge alert: we assume the last two characters of a tab
- label are " x", and treat clicks on those 2 characters as a
- Close Tab command. */
- eassert (STRINGP (caption));
- int lastc = SSDATA (caption)[SCHARS (caption) - 1];
- bool close_p = false;
- if ((x == clen - 1 || (clen > 1 && x == clen - 2)) && lastc == 'x')
- close_p = true;
+ caption = Fcopy_sequence (caption);
- return list3 (Qtab_bar, key, close_p ? Qt : Qnil);
+ AUTO_LIST2 (props, Qmenu_item,
+ list3 (AREF (f->tab_bar_items, prop_idx * TAB_BAR_ITEM_NSLOTS
+ + TAB_BAR_ITEM_KEY),
+ AREF (f->tab_bar_items, prop_idx * TAB_BAR_ITEM_NSLOTS
+ + TAB_BAR_ITEM_BINDING),
+ close_p ? Qt : Qnil));
+
+ Fadd_text_properties (make_fixnum (0), make_fixnum (SCHARS (caption)),
+ props, caption);
+
+ return Fcons (Qtab_bar, Fcons (caption, make_fixnum (0)));
}
@@ -33524,7 +33524,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
&& y < FRAME_MENU_BAR_LINES (f) + FRAME_TAB_BAR_LINES (f)))
{
int prop_idx;
- ptrdiff_t ignore;
+ bool ignore;
Lisp_Object caption = tty_get_tab_bar_item (f, x, &prop_idx, &ignore);
if (!NILP (caption))
diff --git a/src/xterm.c b/src/xterm.c
index 57229d3d616..846b67b069f 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -9166,7 +9166,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
{
/* If we decide we want to generate an event to be seen
by the rest of Emacs, we put it here. */
- Lisp_Object tab_bar_key = Qnil;
+ Lisp_Object tab_bar_arg = Qnil;
bool tab_bar_p = false;
bool tool_bar_p = false;
@@ -9216,7 +9216,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
tab_bar_p = EQ (window, f->tab_bar_window);
if (tab_bar_p)
- tab_bar_key = handle_tab_bar_click
+ tab_bar_arg = handle_tab_bar_click
(f, x, y, event->xbutton.type == ButtonPress,
x_x_to_emacs_modifiers (dpyinfo, event->xbutton.state));
}
@@ -9240,7 +9240,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
}
#endif /* !USE_GTK */
- if (!(tab_bar_p && NILP (tab_bar_key)) && !tool_bar_p)
+ if (!(tab_bar_p && NILP (tab_bar_arg)) && !tool_bar_p)
#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
if (! popup_activated ())
#endif
@@ -9259,8 +9259,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
else
x_construct_mouse_click (&inev.ie, &event->xbutton, f);
- if (!NILP (tab_bar_key))
- inev.ie.arg = tab_bar_key;
+ if (!NILP (tab_bar_arg))
+ inev.ie.arg = tab_bar_arg;
}
if (FRAME_X_EMBEDDED_P (f))
xembed_send_message (f, event->xbutton.time,