Sync OpenBSD patchset 896:

When mode-mouse is on (it is off by default), automatically enter copy
mode when the mouse is dragged or the mouse wheel is used. Also exit
copy mode when the mouse wheel is scrolled off the bottom. Discussed
with and written by hsim at gmx dot li.
This commit is contained in:
Tiago Cunha 2011-04-25 20:33:42 +00:00
parent d5150484d1
commit 215ee46106
5 changed files with 52 additions and 27 deletions

View File

@ -1,4 +1,4 @@
/* $Id: input-keys.c,v 1.48 2011-01-07 14:34:45 tcunha Exp $ */ /* $Id: input-keys.c,v 1.49 2011-04-25 20:33:42 tcunha Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -219,5 +219,12 @@ input_mouse(struct window_pane *wp, struct mouse_event *m)
buf[len++] = m->y + 33; buf[len++] = m->y + 33;
} }
bufferevent_write(wp->event, buf, len); bufferevent_write(wp->event, buf, len);
} else if ((m->b & MOUSE_BUTTON) != MOUSE_2) {
if (options_get_number(&wp->window->options, "mode-mouse") &&
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);
}
} }
} }

View File

@ -1,4 +1,4 @@
/* $Id: server-client.c,v 1.56 2011-04-18 21:07:58 nicm Exp $ */ /* $Id: server-client.c,v 1.57 2011-04-25 20:33:42 tcunha Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -313,7 +313,13 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
if (key == KEYC_MOUSE) { if (key == KEYC_MOUSE) {
if (c->flags & CLIENT_READONLY) if (c->flags & CLIENT_READONLY)
return; return;
if (options_get_number(oo, "mouse-select-pane")) { if (options_get_number(oo, "mouse-select-pane") &&
((!(mouse->b & MOUSE_DRAG) && mouse->b != MOUSE_UP) ||
wp->mode != &window_copy_mode)) {
/*
* Allow pane switching in copy mode only by mouse down
* (click).
*/
window_set_active_at(w, mouse->x, mouse->y); window_set_active_at(w, mouse->x, mouse->y);
server_redraw_window_borders(w); server_redraw_window_borders(w);
wp = w->active; wp = w->active;
@ -444,6 +450,7 @@ server_client_reset_state(struct client *c)
struct window_pane *wp = w->active; struct window_pane *wp = w->active;
struct screen *s = wp->screen; struct screen *s = wp->screen;
struct options *oo = &c->session->options; struct options *oo = &c->session->options;
struct options *wo = &w->options;
int status, mode; int status, mode;
tty_region(&c->tty, 0, c->tty.sy - 1); tty_region(&c->tty, 0, c->tty.sy - 1);
@ -459,14 +466,15 @@ server_client_reset_state(struct client *c)
* none. * none.
*/ */
mode = s->mode; mode = s->mode;
if ((mode & ALL_MOUSE_MODES) == 0) {
if (TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry) != NULL && if (TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry) != NULL &&
options_get_number(oo, "mouse-select-pane") && options_get_number(oo, "mouse-select-pane") == 0)
(mode & ALL_MOUSE_MODES) == 0)
mode |= MODE_MOUSE_STANDARD; mode |= MODE_MOUSE_STANDARD;
else if (options_get_number(oo, "mouse-select-window"))
if (options_get_number(oo, "mouse-select-window") &&
(mode & ALL_MOUSE_MODES) == 0)
mode |= MODE_MOUSE_STANDARD; mode |= MODE_MOUSE_STANDARD;
else if (options_get_number(wo, "mode-mouse"))
mode |= MODE_MOUSE_STANDARD;
}
/* /*
* Set UTF-8 mouse input if required. If the terminal is UTF-8, the * Set UTF-8 mouse input if required. If the terminal is UTF-8, the

9
tmux.1
View File

@ -1,4 +1,4 @@
.\" $Id: tmux.1,v 1.308 2011-04-18 21:07:58 nicm Exp $ .\" $Id: tmux.1,v 1.309 2011-04-25 20:33:42 tcunha Exp $
.\" .\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\" .\"
@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: April 18 2011 $ .Dd $Mdocdate: April 19 2011 $
.Dt TMUX 1 .Dt TMUX 1
.Os .Os
.Sh NAME .Sh NAME
@ -2314,8 +2314,9 @@ contains
.Op Ic on | off .Op Ic on | off
.Xc .Xc
Mouse state in modes. Mouse state in modes.
If on, the mouse may be used to copy a selection by dragging in copy mode, or If on, the mouse may be used to enter copy mode and copy a selection by
to select an option in choice mode. dragging, to enter copy mode and scroll with the mouse wheel, or to select an
option in choice mode.
.Pp .Pp
.It Xo Ic monitor-activity .It Xo Ic monitor-activity
.Op Ic on | off .Op Ic on | off

4
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.620 2011-04-18 21:07:58 nicm Exp $ */ /* $Id: tmux.h,v 1.621 2011-04-25 20:33:42 tcunha Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -1077,6 +1077,7 @@ struct mouse_event {
#define MOUSE_3 2 #define MOUSE_3 2
#define MOUSE_UP 3 #define MOUSE_UP 3
#define MOUSE_BUTTON 3 #define MOUSE_BUTTON 3
#define MOUSE_DRAG 32
#define MOUSE_45 64 #define MOUSE_45 64
u_int x; u_int x;
u_int y; u_int y;
@ -1424,6 +1425,7 @@ void tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
void tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *); void tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
void tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *); void tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
void tty_cmd_deleteline(struct tty *, const struct tty_ctx *); void tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
void tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *);
void tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *); void tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
void tty_cmd_insertline(struct tty *, const struct tty_ctx *); void tty_cmd_insertline(struct tty *, const struct tty_ctx *);
void tty_cmd_linefeed(struct tty *, const struct tty_ctx *); void tty_cmd_linefeed(struct tty *, const struct tty_ctx *);

View File

@ -1,4 +1,4 @@
/* $Id: window-copy.c,v 1.128 2011-04-06 22:18:56 nicm Exp $ */ /* $Id: window-copy.c,v 1.129 2011-04-25 20:33:42 tcunha Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -760,11 +760,11 @@ window_copy_key_numeric_prefix(struct window_pane *wp, int key)
/* ARGSUSED */ /* ARGSUSED */
void void
window_copy_mouse( window_copy_mouse(
struct window_pane *wp, unused struct session *sess, struct mouse_event *m) struct window_pane *wp, struct session *sess, struct mouse_event *m)
{ {
struct window_copy_mode_data *data = wp->modedata; struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen; struct screen *s = &data->screen;
u_int i; u_int i, old_cy;
if (m->x >= screen_size_x(s)) if (m->x >= screen_size_x(s))
return; return;
@ -777,8 +777,11 @@ window_copy_mouse(
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
window_copy_cursor_up(wp, 0); window_copy_cursor_up(wp, 0);
} else if ((m->b & MOUSE_BUTTON) == MOUSE_2) { } else if ((m->b & MOUSE_BUTTON) == MOUSE_2) {
old_cy = data->cy;
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
window_copy_cursor_down(wp, 0); window_copy_cursor_down(wp, 0);
if (old_cy == data->cy)
goto reset_mode;
} }
return; return;
} }
@ -792,16 +795,10 @@ window_copy_mouse(
window_copy_update_cursor(wp, m->x, m->y); window_copy_update_cursor(wp, m->x, m->y);
if (window_copy_update_selection(wp)) if (window_copy_update_selection(wp))
window_copy_redraw_screen(wp); window_copy_redraw_screen(wp);
} else {
s->mode &= ~MODE_MOUSE_ANY;
s->mode |= MODE_MOUSE_STANDARD;
if (sess != NULL) {
window_copy_copy_selection(wp);
window_pane_reset_mode(wp);
}
}
return; return;
} }
goto reset_mode;
}
/* Otherwise if other buttons pressed, start selection and motion. */ /* Otherwise if other buttons pressed, start selection and motion. */
if ((m->b & MOUSE_BUTTON) != MOUSE_UP) { if ((m->b & MOUSE_BUTTON) != MOUSE_UP) {
@ -812,6 +809,16 @@ window_copy_mouse(
window_copy_start_selection(wp); window_copy_start_selection(wp);
window_copy_redraw_screen(wp); window_copy_redraw_screen(wp);
} }
return;
reset_mode:
s->mode &= ~MODE_MOUSE_ANY;
s->mode |= MODE_MOUSE_STANDARD;
if (sess != NULL) {
window_copy_copy_selection(wp);
window_pane_reset_mode(wp);
}
} }
void void