From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#41343: tab-bar-mode: Close tab on mouse-2 click Date: Wed, 04 Aug 2021 01:33:45 +0300 Message-ID: <87wnp2cg52.fsf@linkov.net> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12109"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: 41343@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 04 00:37:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mB327-00030c-MW for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 04 Aug 2021 00:37:11 +0200 Original-Received: from localhost ([::1]:40612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mB325-0003yB-My for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 Aug 2021 18:37:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mB31y-0003xt-MA for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2021 18:37:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58408) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mB31y-0004Uj-FY for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2021 18:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mB31y-0008NV-Ak for bug-gnu-emacs@gnu.org; Tue, 03 Aug 2021 18:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 03 Aug 2021 22:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41343 X-GNU-PR-Package: emacs Original-Received: via spool by 41343-submit@debbugs.gnu.org id=B41343.162803016232122 (code B ref 41343); Tue, 03 Aug 2021 22:37:02 +0000 Original-Received: (at 41343) by debbugs.gnu.org; 3 Aug 2021 22:36:02 +0000 Original-Received: from localhost ([127.0.0.1]:41721 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mB30z-0008Lu-Vs for submit@debbugs.gnu.org; Tue, 03 Aug 2021 18:36:02 -0400 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:35345) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mB30w-0008LY-Tk for 41343@debbugs.gnu.org; Tue, 03 Aug 2021 18:36:00 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 4A1A9100003; Tue, 3 Aug 2021 22:35:50 +0000 (UTC) In-Reply-To: (Stefan Kangas's message of "Sat, 16 May 2020 21:05:35 -0700") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:211104 Archived-At: --=-=-= Content-Type: text/plain > 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tab-close-mouse-2.patch 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))) 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) --=-=-=--