emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tab-bar-events ad9c57f 3/3: Mouse wheel scrolling on the tab bar


From: Juri Linkov
Subject: feature/tab-bar-events ad9c57f 3/3: Mouse wheel scrolling on the tab bar
Date: Wed, 18 Aug 2021 14:08:33 -0400 (EDT)

branch: feature/tab-bar-events
commit ad9c57f54ae3eea9e5b2fe9264e9edb8b2ed1857
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    Mouse wheel scrolling on the tab bar
    
    * lisp/tab-bar.el (tab-bar-map): Bind mouse-4/wheel-up/wheel-left
    to tab-previous and mouse-5/wheel-down/wheel-right to tab-next.
    Bind S-mouse-4/wheel-up/wheel-left to tab-bar-move-tab-backward
    and S-mouse-5/wheel-down/wheel-right to tab-bar-move-tab.
    (tab-bar-move-tab-backward): New command.
    (tab-bar-move-repeat-map): Use tab-bar-move-tab-backward
    instead of lambda.
    
    * src/xterm.c (handle_one_xevent): Remove restriction
    to allow clicking mouse-4 and mouse-5.
---
 etc/NEWS        |  4 +++-
 lisp/tab-bar.el | 27 ++++++++++++++++++++++-----
 src/xterm.c     |  2 +-
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index fb553e8..c48e110 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -751,7 +751,9 @@ of the next command to be displayed in a new frame.
 *** The tab bar now supports more mouse commands.
 Clicking 'mouse-2' closes the tab, 'mouse-3' displays the context menu
 with items that operate on the clicked tab.  Dragging the tab with
-'mouse-1' moves it to another position on the tab bar.
+'mouse-1' moves it to another position on the tab bar.  Mouse wheel
+scrolling switches to the previous/next tab, and holding the Shift key
+during scrolling moves the tab to the left/right.
 
 *** The key prefix 'C-x t t' displays next command buffer in a new tab.
 It's bound to the command 'other-tab-prefix' that requests the buffer
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 68de770..ef7babb 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -327,6 +327,20 @@ new frame when the global `tab-bar-mode' is enabled, by 
using
     (define-key map [mouse-2] 'ignore)
     (define-key map [down-mouse-3] 'tab-bar-mouse-context-menu)
 
+    (define-key map [mouse-4]     'tab-previous)
+    (define-key map [mouse-5]     'tab-next)
+    (define-key map [wheel-up]    'tab-previous)
+    (define-key map [wheel-down]  'tab-next)
+    (define-key map [wheel-left]  'tab-previous)
+    (define-key map [wheel-right] 'tab-next)
+
+    (define-key map [S-mouse-4]     'tab-bar-move-tab-backward)
+    (define-key map [S-mouse-5]     'tab-bar-move-tab)
+    (define-key map [S-wheel-up]    'tab-bar-move-tab-backward)
+    (define-key map [S-wheel-down]  'tab-bar-move-tab)
+    (define-key map [S-wheel-left]  'tab-bar-move-tab-backward)
+    (define-key map [S-wheel-right] 'tab-bar-move-tab)
+
     map)
   "Keymap for the commands used on the tab bar.")
 
@@ -1055,6 +1069,12 @@ where argument addressing is absolute."
          (to-index (mod (+ from-index arg) (length tabs))))
     (tab-bar-move-tab-to (1+ to-index) (1+ from-index))))
 
+(defun tab-bar-move-tab-backward (&optional arg)
+  "Move the current tab ARG positions to the left.
+Like `tab-bar-move-tab', but moves in the opposite direction."
+  (interactive "p")
+  (tab-bar-move-tab (- (or arg 1))))
+
 (defun tab-bar-move-tab-to-frame (arg &optional from-frame from-index to-frame 
to-index)
   "Move tab from FROM-INDEX position to new position at TO-INDEX.
 FROM-INDEX defaults to the current tab index.
@@ -2118,11 +2138,8 @@ Used in `repeat-mode'.")
 
 (defvar tab-bar-move-repeat-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "m" 'tab-move)
-    (define-key map "M" (lambda ()
-                          (interactive)
-                          (setq repeat-map 'tab-bar-move-repeat-map)
-                          (tab-move -1)))
+    (define-key map "m" 'tab-bar-move-tab)
+    (define-key map "M" 'tab-bar-move-tab-backward)
     map)
   "Keymap to repeat tab move key sequences `C-x t m m M'.
 Used in `repeat-mode'.")
diff --git a/src/xterm.c b/src/xterm.c
index 80fa747..57229d3 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -9215,7 +9215,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                 window = window_from_coordinates (f, x, y, 0, true, true);
                 tab_bar_p = EQ (window, f->tab_bar_window);
 
-                if (tab_bar_p && event->xbutton.button < 4)
+                if (tab_bar_p)
                  tab_bar_key = handle_tab_bar_click
                    (f, x, y, event->xbutton.type == ButtonPress,
                     x_x_to_emacs_modifiers (dpyinfo, event->xbutton.state));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]