summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-05-31 19:51:30 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-05-31 19:51:30 +0000
commitb3e4b0ced111eaaf5bd0bd2dcbba8ab2135fe329 (patch)
treedbe40ed3e544d3d9aa15561ab83dd0be544cd8d3 /usr.bin
parentc72aa480d21cfe8c7de6772a263b0baa5119e814 (diff)
When the mode-mouse option is on, support dragging to make a selection
in copy mode. Also support the scroll wheel, although xterm strangely does not ignore it in application mouse mode, causing redraw artifacts when scrolling up (other terminals appear to be better behaved).
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/tmux.110
-rw-r--r--usr.bin/tmux/tmux.h7
-rw-r--r--usr.bin/tmux/tty-keys.c5
-rw-r--r--usr.bin/tmux/tty.c19
-rw-r--r--usr.bin/tmux/window-copy.c54
5 files changed, 73 insertions, 22 deletions
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index f1e8d1787d5..933cb536ad6 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.172 2010/05/30 19:19:42 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.173 2010/05/31 19:51:29 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 30 2010 $
+.Dd $Mdocdate: May 31 2010 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -2078,10 +2078,8 @@ Key bindings default to emacs.
.Op Ic on | off
.Xc
Mouse state in modes.
-If on,
-.Nm
-will respond to mouse clicks by moving the cursor in copy mode or selecting an
-option in choice mode.
+If on, the mouse may be used to copy a selection by dragging in copy mode, or
+to select an option in choice mode.
.Pp
.It Xo Ic monitor-activity
.Op Ic on | off
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 5c810fdbe97..a367166da40 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.222 2010/05/26 16:44:32 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.223 2010/05/31 19:51:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -541,7 +541,8 @@ struct mode_key_table {
#define MODE_KCURSOR 0x4
#define MODE_KKEYPAD 0x8 /* set = application, clear = number */
#define MODE_MOUSE 0x10
-#define MODE_WRAP 0x20 /* whether lines wrap */
+#define MODE_MOUSEMOTION 0x20
+#define MODE_WRAP 0x40 /* whether lines wrap */
/*
* A single UTF-8 character.
@@ -1086,7 +1087,7 @@ struct client {
#define CLIENT_TERMINAL 0x1
#define CLIENT_PREFIX 0x2
-#define CLIENT_MOUSE 0x4
+/* 0x4 unused */
#define CLIENT_REDRAW 0x8
#define CLIENT_STATUS 0x10
#define CLIENT_REPEAT 0x20 /* allow command to repeat within repeat time */
diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c
index 2e12e42dc69..0e0cbc9e92a 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.30 2010/03/22 19:03:52 nicm Exp $ */
+/* $OpenBSD: tty-keys.c,v 1.31 2010/05/31 19:51:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -612,7 +612,8 @@ tty_keys_mouse(const char *buf, size_t len, size_t *size, struct mouse_event *m)
return (1);
*size = 6;
- log_debug("mouse input is: %.6s", buf);
+ log_debug(
+ "mouse input: %.6s (%hhu,%hhu/%hhu)", buf, buf[4], buf[5], buf[3]);
m->b = buf[3];
m->x = buf[4];
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index 68446c635a7..f972cfa41fb 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.85 2010/03/01 22:44:31 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.86 2010/05/31 19:51:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -402,11 +402,18 @@ tty_update_mode(struct tty *tty, int mode)
else
tty_putcode(tty, TTYC_CIVIS);
}
- if (changed & MODE_MOUSE) {
- if (mode & MODE_MOUSE)
- tty_puts(tty, "\033[?1000h");
- else
- tty_puts(tty, "\033[?1000l");
+ if (changed & (MODE_MOUSE|MODE_MOUSEMOTION)) {
+ if (mode & MODE_MOUSE) {
+ if (mode & MODE_MOUSEMOTION)
+ tty_puts(tty, "\033[?1003h");
+ else
+ tty_puts(tty, "\033[?1000h");
+ } else {
+ if (mode & MODE_MOUSEMOTION)
+ tty_puts(tty, "\033[?1003l");
+ else
+ tty_puts(tty, "\033[?1000l");
+ }
}
if (changed & MODE_KKEYPAD) {
if (mode & MODE_KKEYPAD)
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index cbcddbd1b41..91718bdf243 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.56 2010/05/23 19:42:19 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.57 2010/05/31 19:51:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -760,17 +760,61 @@ window_copy_mouse(
{
struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen;
+ u_int i;
+
+ /*
+ * xterm mouse mode is fairly silly. Buttons are in the bottom two
+ * bits: 0 button 1; 1 button 2; 2 button 3; 3 buttons released.
+ *
+ * Bit 3 is shift; bit 4 is meta; bit 5 control.
+ *
+ * Bit 6 is added for mouse buttons 4 and 5.
+ */
- if ((m->b & 3) == 3)
- return;
if (m->x >= screen_size_x(s))
return;
if (m->y >= screen_size_y(s))
return;
- window_copy_update_cursor(wp, m->x, m->y);
- if (window_copy_update_selection(wp))
+ /* If mouse wheel (buttons 4 and 5), scroll. */
+ if ((m->b & 64) == 64) {
+ if ((m->b & 3) == 0) {
+ for (i = 0; i < 5; i++)
+ window_copy_cursor_up(wp, 0);
+ } else if ((m->b & 3) == 1) {
+ for (i = 0; i < 5; i++)
+ window_copy_cursor_down(wp, 0);
+ }
+ return;
+ }
+
+ /*
+ * If already reading motion, move the cursor while buttons are still
+ * pressed, or stop the selection on their release.
+ */
+ if (s->mode & MODE_MOUSEMOTION) {
+ if ((m->b & 3) != 3) {
+ window_copy_update_cursor(wp, m->x, m->y);
+ if (window_copy_update_selection(wp))
+ window_copy_redraw_screen(wp);
+ } else {
+ s->mode &= ~MODE_MOUSEMOTION;
+ if (sess != NULL) {
+ window_copy_copy_selection(wp, sess);
+ window_pane_reset_mode(wp);
+ }
+ }
+ return;
+ }
+
+ /* Otherwise i other buttons pressed, start selection and motion. */
+ if ((m->b & 3) != 3) {
+ s->mode |= MODE_MOUSEMOTION;
+
+ window_copy_update_cursor(wp, m->x, m->y);
+ window_copy_start_selection(wp);
window_copy_redraw_screen(wp);
+ }
}
void