summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2014-04-03 08:20:30 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2014-04-03 08:20:30 +0000
commit0dbbe52b63ffab48f521b6d2ba15c468441effd1 (patch)
tree0db0f8d9e2f49e96199f7baf94817153cec43011 /usr.bin/tmux
parent6e7110783a3e8ba561122d06549267f5bae0f7db (diff)
Work out mouse scroll wheel effect when the mouse is first detected and
store it in struct mouse_event, reduce the scroll size the 3 but allow shift to reduce it to 1 and meta and ctrl to multiply by 3 if the terminal supports them, also support wheel in choose mode. From Marcel Partap.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/tmux.h3
-rw-r--r--usr.bin/tmux/tty-keys.c11
-rw-r--r--usr.bin/tmux/window-choose.c14
-rw-r--r--usr.bin/tmux/window-copy.c23
4 files changed, 36 insertions, 15 deletions
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index ac9edd4aab3..e8131556819 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.447 2014/04/02 18:12:18 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.448 2014/04/03 08:20:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1168,6 +1168,7 @@ struct mouse_event {
u_int button;
u_int clicks;
+ u_int scroll;
int wheel;
int event;
diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c
index dcc48c1a8c5..53b3bf0c0e5 100644
--- a/usr.bin/tmux/tty-keys.c
+++ b/usr.bin/tmux/tty-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty-keys.c,v 1.64 2014/04/03 08:15:17 nicm Exp $ */
+/* $OpenBSD: tty-keys.c,v 1.65 2014/04/03 08:20:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -749,6 +749,15 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
m->x = x;
m->y = y;
if (b & MOUSE_MASK_WHEEL) {
+ if (b & MOUSE_MASK_SHIFT)
+ m->scroll = 1;
+ else
+ m->scroll = 3;
+ if (b & MOUSE_MASK_META)
+ m->scroll *= 3;
+ if (b & MOUSE_MASK_CTRL)
+ m->scroll *= 3;
+
b &= MOUSE_MASK_BUTTONS;
if (b == 0)
m->wheel = MOUSE_WHEEL_UP;
diff --git a/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c
index 1ca7124554a..5b5e2a2bc27 100644
--- a/usr.bin/tmux/window-choose.c
+++ b/usr.bin/tmux/window-choose.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-choose.c,v 1.51 2014/03/31 21:36:43 nicm Exp $ */
+/* $OpenBSD: window-choose.c,v 1.52 2014/04/03 08:20:29 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -721,7 +721,17 @@ 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;
+
+ if (m->event == MOUSE_EVENT_WHEEL) {
+ 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/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index f75ba492364..7e04b713666 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.103 2014/03/31 21:39:31 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.104 2014/04/03 08:20:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -871,18 +871,19 @@ window_copy_mouse(
/* 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++)
+ for (i = 0; i < m->scroll; i++) {
+ if (m->wheel == MOUSE_WHEEL_UP)
window_copy_cursor_up(wp, 1);
- } else if (m->wheel == MOUSE_WHEEL_DOWN) {
- for (i = 0; i < 5; i++)
+ else {
window_copy_cursor_down(wp, 1);
- /*
- * We reached the bottom, leave copy mode,
- * but only if no selection is in progress.
- */
- if (data->oy == 0 && !s->sel.flag)
- goto reset_mode;
+
+ /*
+ * We reached the bottom, leave copy mode, but
+ * only if no selection is in progress.
+ */
+ if (data->oy == 0 && !s->sel.flag)
+ goto reset_mode;
+ }
}
return;
}