(+ some other changes regarding mouse implementation)
- is u_int for i ok?
- was there a valid reason to use bit shifts for MOUSE_EVENT_*
  constants?
- ...
---
 input-keys.c    | 18 +++++++++++++++++-
 server-fn.c     |  1 +
 tmux.h          | 23 +++++++++++++++++------
 tty-keys.c      | 27 ++++++++++++++++++---------
 window-choose.c | 10 +++++++++-
 window-copy.c   | 12 +++++-------
 6 files changed, 67 insertions(+), 24 deletions(-)

diff --git a/input-keys.c b/input-keys.c
index 7582a63..b76dd6c 100644
--- a/input-keys.c
+++ b/input-keys.c
@@ -204,6 +204,22 @@ input_mouse(struct window_pane *wp, struct session *s, 
struct mouse_event *m)
        char                     buf[40];
        size_t                   len;
        struct paste_buffer     *pb;
+       u_int                    i;
+
+       /*
+        * Mouse wheel used while alternate screen is active and not mouse
+        * aware, or shift is pressed.
+        */
+       if (((wp->saved_grid != NULL && !(wp->screen->mode & ALL_MOUSE_MODES)) 
||
+           m->xb & MOUSE_SHIFT)) {
+               for (i = 0; i < m->scroll; i++) {
+                       if (m->wheel == MOUSE_WHEEL_UP)
+                               input_key(wp, KEYC_UP);
+                       else
+                               input_key(wp, KEYC_DOWN);
+               }
+               return;
+       }
 
        if (wp->screen->mode & ALL_MOUSE_MODES) {
                /*
@@ -244,7 +260,7 @@ input_mouse(struct window_pane *wp, struct session *s, 
struct mouse_event *m)
                        paste_send_pane(pb, wp, "\r",
                            wp->screen->mode & MODE_BRACKETPASTE);
                }
-       } else if ((m->xb & 3) != 1 &&
+       } else if (m->button != 1 &&
            options_get_number(&wp->window->options, "mode-mouse") == 1) {
                if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
                        window_copy_init_from_pane(wp);
diff --git a/server-fn.c b/server-fn.c
index 3062698..47e1cee 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -609,3 +609,4 @@ server_unzoom_window(struct window *w)
        server_redraw_window(w);
        server_status_window(w);
 }
+
diff --git a/tmux.h b/tmux.h
index 23b1b46..41be9f8 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1118,19 +1118,29 @@ struct tty_term {
 };
 LIST_HEAD(tty_terms, tty_term);
 
+/* Mouse event masks. */
+#define MOUSE_MASK_BUTTON 3
+#define MOUSE_MASK_DRAG 32
+#define MOUSE_MASK_WHEEL 64
+
+/* Mouse modifier key states. */
+#define MOUSE_SHIFT 4
+#define MOUSE_META 8
+#define MOUSE_CTRL 16
+
 /* Mouse wheel states. */
 #define MOUSE_WHEEL_UP 0
 #define MOUSE_WHEEL_DOWN 1
 
 /* Mouse events. */
-#define MOUSE_EVENT_DOWN (1 << 0)
-#define MOUSE_EVENT_DRAG (1 << 1)
-#define MOUSE_EVENT_UP (1 << 2)
-#define MOUSE_EVENT_CLICK (1 << 3)
-#define MOUSE_EVENT_WHEEL (1 << 4)
+#define MOUSE_EVENT_DOWN 1
+#define MOUSE_EVENT_DRAG 2
+#define MOUSE_EVENT_UP 4
+#define MOUSE_EVENT_CLICK 8
+#define MOUSE_EVENT_WHEEL 16
 
 /* Mouse flags. */
-#define MOUSE_RESIZE_PANE (1 << 0)
+#define MOUSE_RESIZE_PANE 1
 
 /*
  * Mouse input. When sent by xterm:
@@ -1160,6 +1170,7 @@ struct mouse_event {
 
        u_int   button;
        u_int   clicks;
+       u_int   scroll;
 
        int     wheel;
        int     event;
diff --git a/tty-keys.c b/tty-keys.c
index 7fb91a8..1a5053a 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -748,21 +748,30 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t 
len, size_t *size)
        m->sgr_rel = sgr_rel;
        m->x = x;
        m->y = y;
-       if (b & 64) { /* wheel button */
-               b &= 3;
-               if (b == 0)
-                       m->wheel = MOUSE_WHEEL_UP;
-               else if (b == 1)
-                       m->wheel = MOUSE_WHEEL_DOWN;
+       m->scroll = 0;
+       if (b & MOUSE_MASK_WHEEL) {
                m->event = MOUSE_EVENT_WHEEL;
-       } else if ((b & 3) == 3) {
+               /* Figure out number of lines to scroll, shift is a single
+                * line, meta and ctrl multiply exponentially. */
+               if (b & MOUSE_SHIFT)
+                       m->scroll = 1;
+               else
+                       m->scroll = 3;
+
+               if (b & MOUSE_META)
+                       m->scroll *= 3;
+               if (b & MOUSE_CTRL)
+                       m->scroll *= 3;
+
+               m->wheel = (b & MOUSE_MASK_BUTTON);
+       } else if ((b & MOUSE_MASK_BUTTON) == 3) {
                if (~m->event & MOUSE_EVENT_DRAG && x == m->x && y == m->y) {
                        m->event = MOUSE_EVENT_CLICK;
                } else
                        m->event = MOUSE_EVENT_DRAG;
                m->event |= MOUSE_EVENT_UP;
        } else {
-               if (b & 32) /* drag motion */
+               if (b & MOUSE_MASK_DRAG)
                        m->event = MOUSE_EVENT_DRAG;
                else {
                        if (m->event & MOUSE_EVENT_UP && x == m->x && y == m->y)
@@ -773,7 +782,7 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t 
len, size_t *size)
                        m->sy = y;
                        m->event = MOUSE_EVENT_DOWN;
                }
-               m->button = (b & 3);
+               m->button = (b & MOUSE_MASK_BUTTON);
        }
 
        return (0);
diff --git a/window-choose.c b/window-choose.c
index 7b2b32b..9d91994 100644
--- a/window-choose.c
+++ b/window-choose.c
@@ -698,7 +698,15 @@ window_choose_mouse(
        struct window_choose_mode_data  *data = wp->modedata;
        struct screen                   *s = &data->screen;
        struct window_choose_mode_item  *item;
-       u_int                            idx;
+       u_int                            i, idx;
+
+       for (i = 0; i < m->scroll; i++) {
+               if (m->wheel == MOUSE_WHEEL_UP)
+                       window_choose_key(wp, sess, KEYC_UP);
+               else
+                       window_choose_key(wp, sess, KEYC_DOWN);
+               return;
+       }
 
        if (~m->event & MOUSE_EVENT_CLICK)
                return;
diff --git a/window-copy.c b/window-copy.c
index 527c95c..7471ef2 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -862,13 +862,11 @@ window_copy_mouse(
                return;
 
        /* If mouse wheel (buttons 4 and 5), scroll. */
-       if (m->event == MOUSE_EVENT_WHEEL) {
-               if (m->wheel == MOUSE_WHEEL_UP) {
-                       for (i = 0; i < 5; i++)
-                               window_copy_cursor_up(wp, 1);
-               } else if (m->wheel == MOUSE_WHEEL_DOWN) {
-                       for (i = 0; i < 5; i++)
-                               window_copy_cursor_down(wp, 1);
+       for (i = 0; i < m->scroll; i++) {
+               if (m->wheel == MOUSE_WHEEL_UP)
+                       window_copy_cursor_up(wp, 1);
+               else {
+                       window_copy_cursor_down(wp, 1);
                        /*
                         * We reached the bottom, leave copy mode,
                         * but only if no selection is in progress.
-- 
1.9.0


------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to