> server to crash.   :)
uncrashed.
>From 7f588c64242b3c1d8a31d3bc6aaa1b590027b776 Mon Sep 17 00:00:00 2001
From: Marcel Partap <mpar...@gmx.net>
Date: Thu, 21 Jun 2012 12:01:55 +0200
Subject: [PATCH 4/4] Cleaned up implementation of mouse wheel scrolling
 emulation.

---
 trunk/examples/tmux.vim |    2 +-
 trunk/input-keys.c      |   29 ++++++++++++++++++++++-------
 trunk/options-table.c   |    5 +++++
 trunk/tmux.1            |    5 +++++
 4 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/trunk/examples/tmux.vim b/trunk/examples/tmux.vim
index e10fa94..2d62de5 100644
--- a/trunk/examples/tmux.vim
+++ b/trunk/examples/tmux.vim
@@ -63,7 +63,7 @@ syn keyword tmuxOptsSet pane-border-bg pane-border-fg message-[command-]fg
 syn keyword tmuxOptsSet display-panes-active-colour alternate-screen
 syn keyword tmuxOptsSet detach-on-destroy word-separators
 syn keyword tmuxOptsSet destroy-unattached exit-unattached set-clipboard
-syn keyword tmuxOptsSet bell-on-alert mouse-select-window mouse-utf8
+syn keyword tmuxOptsSet bell-on-alert mouse-select-window mouse-utf8 mouse-scroll-lines
 
 syn keyword tmuxOptsSetw monitor-activity aggressive-resize force-width
 syn keyword tmuxOptsSetw force-height remain-on-exit uft8 mode-fg mode-bg
diff --git a/trunk/input-keys.c b/trunk/input-keys.c
index ea1fb92..7330837 100644
--- a/trunk/input-keys.c
+++ b/trunk/input-keys.c
@@ -201,8 +201,10 @@ input_key(struct window_pane *wp, int key)
 void
 input_mouse(struct window_pane *wp, struct mouse_event *m)
 {
-	char	buf[10];
-	size_t	len;
+	struct options	*oo = &wp->window->options;
+	char		 buf[10];
+	size_t		 len;
+	int		 mode, i, lines;
 
 	if (wp->screen->mode & ALL_MOUSE_MODES) {
 		if (wp->screen->mode & MODE_MOUSE_UTF8) {
@@ -221,14 +223,27 @@ input_mouse(struct window_pane *wp, struct mouse_event *m)
 		bufferevent_write(wp->event, buf, len);
 		return;
 	}
-
-	if ((m->b & 3) != 1 &&
-	    options_get_number(&wp->window->options, "mode-mouse") == 1) {
-		if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
+	if ((m->b & MOUSE_BUTTON) != MOUSE_2) {
+		mode = options_get_number(oo, "mode-mouse");
+		if (mode == 1 &&
+		    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;
+	}
+	/* Emulate mouse wheel scrolling. */
+	if (m->b & MOUSE_45) {
+		/*
+		 * Wheel + shift: always scroll 1 line
+		 * Wheel + ctrl:  scroll at triple speed
+		 * */
+		lines = (m->b & MOUSE_SHIFT) ? 1 : options_get_number(oo, "mouse-scroll-lines");
+		if (m->b & MOUSE_CTRL)
+			lines *= 3;
+
+		for (i = 0; i < lines; i++)
+			input_key(wp, (m->b & MOUSE_BUTTON) == MOUSE_1 ? KEYC_UP : KEYC_DOWN);
 	}
 }
diff --git a/trunk/options-table.c b/trunk/options-table.c
index f67f679..1247474 100644
--- a/trunk/options-table.c
+++ b/trunk/options-table.c
@@ -238,6 +238,11 @@ const struct options_table_entry session_options_table[] = {
 	  .default_num = 0
 	},
 
+	{ .name = "mouse-scroll-lines",
+	  .type = OPTIONS_TABLE_FLAG,
+	  .default_num = 3
+	},
+
 	{ .name = "mouse-utf8",
 	  .type = OPTIONS_TABLE_FLAG,
 	  .default_num = 0
diff --git a/trunk/tmux.1 b/trunk/tmux.1
index 0ca4b60..83e1c1e 100644
--- a/trunk/tmux.1
+++ b/trunk/tmux.1
@@ -2147,6 +2147,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-lines Ar number
+How many lines each mouse wheel event will scroll. Like in many terminal
+emulators, fake key up/down sequences are sent to non-mouse aware programs.
+Shift modifier overrides this to 1, Ctrl modifier triples the scrolling speed.
+The default is 3.
 .It Xo Ic mouse-utf8
 .Op Ic on | off
 .Xc
-- 
1.7.10.4

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to