From: Juri Linkov <juri@linkov.net>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: 41343@debbugs.gnu.org
Subject: bug#41343: tab-bar-mode: Close tab on mouse-2 click
Date: Wed, 04 Aug 2021 01:33:45 +0300 [thread overview]
Message-ID: <87wnp2cg52.fsf@linkov.net> (raw)
In-Reply-To: <CADwFkm=PmGvudes9RjDaB4VRK5ju+7o3xZb4qCscAmVeRtQb1Q@mail.gmail.com> (Stefan Kangas's message of "Sat, 16 May 2020 21:05:35 -0700")
[-- Attachment #1: Type: text/plain, Size: 183 bytes --]
> Please consider adding a binding to close a tab in tab-bar-mode by
> clicking on it using the middle mouse button (mouse-2).
Here's the patch that implements mouse-2 tab closing:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: tab-close-mouse-2.patch --]
[-- Type: text/x-diff, Size: 4596 bytes --]
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 7660b217d2..ce4d18a0fa 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -229,7 +229,8 @@ tab-bar-handle-mouse
This command is used when you click the mouse in the tab bar
on a console which has no window system but does have a mouse."
(interactive "e")
- (let* ((x-position (car (posn-x-y (event-start event))))
+ (let* ((button (event-basic-type event))
+ (x-position (car (posn-x-y (event-start event))))
(keymap (lookup-key (cons 'keymap (nreverse (current-active-maps))) [tab-bar]))
(column 0))
(when x-position
@@ -238,7 +239,9 @@ tab-bar-handle-mouse
(lambda (key binding)
(when (eq (car-safe binding) 'menu-item)
(when (> (+ column (length (nth 1 binding))) x-position)
- (if (get-text-property (- x-position column) 'close-tab (nth 1 binding))
+ (if (or (eq button 'mouse-2)
+ (get-text-property
+ (- x-position column) 'close-tab (nth 1 binding)))
(let* ((close-key (vector (intern (format "C-%s" key))))
(close-def (lookup-key keymap close-key)))
(when close-def
@@ -768,7 +771,8 @@ tab-bar-format-list
(defun tab-bar-make-keymap-1 ()
"Generate an actual keymap from `tab-bar-map', without caching."
(append
- '(keymap (mouse-1 . tab-bar-handle-mouse))
+ '(keymap (mouse-1 . tab-bar-handle-mouse)
+ (mouse-2 . tab-bar-handle-mouse))
(tab-bar-format-list tab-bar-format)))
\f
diff --git a/src/dispextern.h b/src/dispextern.h
index 33fcaa4c07..26112de0a9 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3416,7 +3416,7 @@ #define TTY_CAP_STRIKE_THROUGH 0x20
extern Lisp_Object find_hot_spot (Lisp_Object, int, int);
extern void handle_tab_bar_click (struct frame *,
- int, int, bool, int);
+ int, int, bool, int, int);
extern void handle_tool_bar_click (struct frame *,
int, int, bool, int);
diff --git a/src/w32term.c b/src/w32term.c
index ad4d1a3282..f53114a857 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -3691,10 +3691,11 @@ w32_handle_tab_bar_click (struct frame *f, struct input_event *button_event)
int y = XFIXNAT (button_event->y);
if (button_event->modifiers & down_modifier)
- handle_tab_bar_click (f, x, y, 1, 0);
+ handle_tab_bar_click (f, x, y, 1, 0, button_event->code + 1);
else
handle_tab_bar_click (f, x, y, 0,
- button_event->modifiers & ~up_modifier);
+ button_event->modifiers & ~up_modifier,
+ button_event->code + 1);
}
diff --git a/src/xdisp.c b/src/xdisp.c
index 70d15aee68..9ca6234264 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13747,7 +13747,7 @@ get_tab_bar_item (struct frame *f, int x, int y, struct glyph **glyph,
void
handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
- int modifiers)
+ int modifiers, int button)
{
Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
struct window *w = XWINDOW (f->tab_bar_window);
@@ -13793,7 +13793,7 @@ handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
event.kind = TAB_BAR_EVENT;
event.frame_or_window = frame;
event.arg = key;
- event.modifiers = close_p ? ctrl_modifier | modifiers : modifiers;
+ event.modifiers = (close_p || button == 2) ? ctrl_modifier | modifiers : modifiers;
kbd_buffer_store_event (&event);
f->last_tab_bar_item = -1;
}
@@ -13962,6 +13962,8 @@ tty_handle_tab_bar_click (struct frame *f, int x, int y, bool down_p,
bool close_p = false;
if ((x == clen - 1 || (clen > 1 && x == clen - 2)) && lastc == 'x')
close_p = true;
+ if (event->code == 1) /* mouse-2 */
+ close_p = true;
event->code = 0;
XSETFRAME (frame, f);
diff --git a/src/xterm.c b/src/xterm.c
index 1887c3255d..5a22bc31d4 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -9217,7 +9217,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
if (tab_bar_p && event->xbutton.button < 4)
handle_tab_bar_click
(f, x, y, event->xbutton.type == ButtonPress,
- x_x_to_emacs_modifiers (dpyinfo, event->xbutton.state));
+ x_x_to_emacs_modifiers (dpyinfo, event->xbutton.state),
+ event->xbutton.button);
}
#if ! defined (USE_GTK)
next prev parent reply other threads:[~2021-08-03 22:33 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-17 4:05 bug#41343: tab-bar-mode: Close tab on mouse-2 click Stefan Kangas
2020-05-17 22:12 ` Juri Linkov
2020-05-17 22:23 ` Stefan Kangas
2020-05-18 2:32 ` Eli Zaretskii
2020-05-19 21:54 ` Juri Linkov
2020-05-20 15:59 ` Eli Zaretskii
2021-08-03 22:33 ` Juri Linkov [this message]
2021-08-04 11:32 ` Eli Zaretskii
2021-08-04 20:13 ` Juri Linkov
2021-08-05 5:43 ` Eli Zaretskii
2021-08-06 0:41 ` Juri Linkov
2021-08-06 6:26 ` Eli Zaretskii
2021-08-06 8:20 ` Juri Linkov
2021-08-06 12:38 ` Eli Zaretskii
2021-08-09 7:03 ` Juri Linkov
2021-08-10 12:38 ` Eli Zaretskii
2021-08-11 7:01 ` Juri Linkov
2021-08-11 11:56 ` Eli Zaretskii
2021-08-12 8:09 ` Juri Linkov
2021-08-12 8:43 ` Eli Zaretskii
2021-08-13 7:24 ` Juri Linkov
2021-08-18 18:11 ` Juri Linkov
2021-08-24 14:37 ` Stefan Kangas
2021-09-05 17:18 ` Juri Linkov
2021-09-06 19:40 ` Stefan Kangas
2021-09-08 19:28 ` Juri Linkov
2021-09-08 21:18 ` Stefan Kangas
2021-09-14 6:43 ` Juri Linkov
2021-09-05 17:17 ` Juri Linkov
2021-08-06 16:21 ` bug#41343: [External] : " Drew Adams
2021-08-09 7:06 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wnp2cg52.fsf@linkov.net \
--to=juri@linkov.net \
--cc=41343@debbugs.gnu.org \
--cc=stefankangas@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).