> Hmm was working for me.
Nah I meant the revised version I sent in reply.. here's the latest. It
fails to compile however (help?).
>From 2e3633271798d9052953d23e5317812bdc32c015 Mon Sep 17 00:00:00 2001
From: Nicholas Marriott <nicholas.marri...@gmail.com>
Date: Wed, 26 Feb 2014 23:04:23 +0000
Subject: [PATCH] Implement simple mouse wheel emulation, 4th.
---
input-keys.c | 16 ++++++++++++++++
server-fn.c | 1 +
tmux.h | 6 ++++++
tty-keys.c | 17 ++++++++++++++++-
window-choose.c | 10 +++++++++-
window-copy.c | 16 +++++++---------
6 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/input-keys.c b/input-keys.c
index 7582a63..98c6b6f 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->lines; 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) {
/*
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..1bb458b 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1129,6 +1129,11 @@ LIST_HEAD(tty_terms, tty_term);
#define MOUSE_EVENT_CLICK (1 << 3)
#define MOUSE_EVENT_WHEEL (1 << 4)
+/* Mouse modifier key states. */
+#define MOUSE_SHIFT 4
+#define MOUSE_META 8
+#define MOUSE_CTRL 16
+
/* Mouse flags. */
#define MOUSE_RESIZE_PANE (1 << 0)
@@ -1160,6 +1165,7 @@ struct mouse_event {
u_int button;
u_int clicks;
+ u_int lines;
int wheel;
int event;
diff --git a/tty-keys.c b/tty-keys.c
index 7fb91a8..2f8e874 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -748,13 +748,28 @@ 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;
+ m->lines = 0;
if (b & 64) { /* wheel button */
+ m->event = MOUSE_EVENT_WHEEL;
+ /*
+ * figure out number of lines to scroll, shift is a single
+ * line, meta and ctrl multiply exponentially.
+ */
+ if (b & MOUSE_SHIFT)
+ m->lines = 1;
+ else
+ m->lines = 3;
+
+ if (b & MOUSE_META)
+ m->lines *= 3;
+ if (b & MOUSE_CTRL)
+ m->lines *= 3;
+
b &= 3;
if (b == 0)
m->wheel = MOUSE_WHEEL_UP;
else if (b == 1)
m->wheel = MOUSE_WHEEL_DOWN;
- m->event = MOUSE_EVENT_WHEEL;
} else if ((b & 3) == 3) {
if (~m->event & MOUSE_EVENT_DRAG && x == m->x && y == m->y) {
m->event = MOUSE_EVENT_CLICK;
diff --git a/window-choose.c b/window-choose.c
index 7b2b32b..d479cad 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->lines; 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..b5da081 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -862,16 +862,14 @@ 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->lines; 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.
+ * 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;
--
1.9.0
------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users