Scrolling mouse wheel while shift modifier key is held generates
fake cursor key events. With ctrl modifier added, speed is multi-
plied by the value of "mouse-scroll-speedup" variable (default 3).
---
 examples/tmux.vim |    2 +-
 input-keys.c      |   18 ++++++++++++++++--
 options-table.c   |    7 +++++++
 tmux.1            |   15 +++++++++++++++
 4 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/examples/tmux.vim b/examples/tmux.vim
index 8a66c00..6040a55 100644
--- a/examples/tmux.vim
+++ b/examples/tmux.vim
@@ -51,7 +51,7 @@ syn keyword tmuxOptsSet
        \ display-panes-[active-]colour display-[panes-]time history-limit
        \ lock-after-time lock-command lock-server message-[command-]attr
        \ message-[command-]bg message-[command-]fg message-limit
-       \ mouse-resize-pane mouse-select-pane mouse-select-window mouse-utf8
+       \ mouse-resize-pane mouse-select-pane mouse-select-window 
mouse-scroll-speedup mouse-utf8
        \ pane-[active-]border-bg pane-[active-]border-fg prefix prefix2
        \ renumber-windows repeat-time set-remain-on-exit set-titles
        \ set-titles-string status status-attr status-bg status-fg
diff --git a/input-keys.c b/input-keys.c
index 2b8533d..ca740fe 100644
--- a/input-keys.c
+++ b/input-keys.c
@@ -203,6 +203,20 @@ input_mouse(struct window_pane *wp, struct mouse_event *m)
 {
        char    buf[10];
        size_t  len;
+       int     i, lines, speedup;
+
+       /* Shift + mouse wheel scrolling: fake cursor key press events. */
+       if (m->b & MOUSE_45 && m->b & MOUSE_SHIFT) {
+               speedup = options_get_number(&global_s_options, 
"mouse-scroll-speedup");
+               /* + ctrl modifier: scroll at high speed. */
+               lines = (m->b & MOUSE_CTRL) ? speedup : 1;
+               /* + meta modifier (alt): scroll at high^2 speed. */
+               if (m->b & MOUSE_ESCAPE)
+                       lines *= speedup;
+               for (i = 0; i < lines; i++)
+                       input_key(wp, (m->b & MOUSE_BUTTON) == MOUSE_1 ? 
KEYC_UP : KEYC_DOWN);
+               return;
+       }
 
        if (wp->screen->mode & ALL_MOUSE_MODES) {
                if (wp->screen->mode & MODE_MOUSE_UTF8) {
@@ -222,13 +236,13 @@ input_mouse(struct window_pane *wp, struct mouse_event *m)
                return;
        }
 
-       if ((m->b & 3) != 1 &&
+       if ((m->b & MOUSE_BUTTON) != MOUSE_2 &&
            options_get_number(&wp->window->options, "mouse-copy-mode") == 1) {
                if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
                        window_copy_init_from_pane(wp);
                        if (wp->mode->mouse != NULL)
                                wp->mode->mouse(wp, NULL, m);
+                       return;
                }
-               return;
        }
 }
diff --git a/options-table.c b/options-table.c
index 2762f8f..4e20e96 100644
--- a/options-table.c
+++ b/options-table.c
@@ -238,6 +238,13 @@ const struct options_table_entry session_options_table[] = 
{
          .default_num = 0
        },
 
+       { .name = "mouse-scroll-speedup",
+         .type = OPTIONS_TABLE_NUMBER,
+         .minimum = 0,
+         .maximum = INT_MAX,
+         .default_num = 3
+       },
+
        { .name = "mouse-utf8",
          .type = OPTIONS_TABLE_FLAG,
          .default_num = 0
diff --git a/tmux.1 b/tmux.1
index 15702c6..1b4c5fa 100644
--- a/tmux.1
+++ b/tmux.1
@@ -335,6 +335,16 @@ Key bindings may be changed with the
 and
 .Ic unbind-key
 commands.
+.Sh MOUSE INPUT
+If
+.Nm
+is run within a terminal emulator that generates xterm-compatible control 
sequences, various aspects may be controlled by mouse (see
+.Ic mouse-*
+options for reference). Regardless of these settings, mouse input is always 
passed through as-is to mouse-capable programs. Notable exception is the 
Shift-modifier in combination with the mouse scroll wheel; this makes
+.Nm
+generate fake key up/down presses to effectively enable wheel scrolling even 
in programs which do not natively support it. Wheel scrolling speed can be 
increased by holding Ctrl and/or Alt (meta) modifiers, each multiplying speed 
by the value of the
+.Ic mouse-scroll-speedup
+option.
 .Sh COMMANDS
 This section contains a list of the commands supported by
 .Nm .
@@ -2235,6 +2245,11 @@ The mouse click is also passed through to the 
application as normal.
 .Xc
 If on, clicking the mouse on a window name in the status line will select that
 window.
+.It Ic mouse-scroll-speedup Ar number
+Multiplication factor applied to mouse scrolling speed if Ctrl or Alt (meta)
+modifiers are held. The increase is cumulative, i.e. pressing both modifiers
+squares the speedup.
+The default is 3.
 .It Xo Ic mouse-utf8
 .Op Ic on | off
 .Xc
-- 
1.7.10.4


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to