summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2011-05-08 20:34:12 +0000
committernicm <nicm@openbsd.org>2011-05-08 20:34:12 +0000
commit50c0e56e3cb00f3e34089eeb7aee4c75c00d8fb5 (patch)
treed07438f737a6fe3d0a50bab3a06cf88c81b49dea
parentUse the tsl and fsl terminfo(5) capabilities to update terminal title (diff)
downloadwireguard-openbsd-50c0e56e3cb00f3e34089eeb7aee4c75c00d8fb5.tar.xz
wireguard-openbsd-50c0e56e3cb00f3e34089eeb7aee4c75c00d8fb5.zip
Add a new option, mouse-resize-pane. When on, panes may be resized by
dragging their borders. From hsim at gmx.li.
-rw-r--r--usr.bin/tmux/layout.c49
-rw-r--r--usr.bin/tmux/options-table.c7
-rw-r--r--usr.bin/tmux/server-client.c20
-rw-r--r--usr.bin/tmux/tmux.18
-rw-r--r--usr.bin/tmux/tmux.h7
5 files changed, 85 insertions, 6 deletions
diff --git a/usr.bin/tmux/layout.c b/usr.bin/tmux/layout.c
index 703d1ff97c7..ff49811aff9 100644
--- a/usr.bin/tmux/layout.c
+++ b/usr.bin/tmux/layout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: layout.c,v 1.6 2010/06/29 03:30:14 nicm Exp $ */
+/* $OpenBSD: layout.c,v 1.7 2011/05/08 20:34:12 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -485,6 +485,53 @@ layout_resize_pane(struct window_pane *wp, enum layout_type type, int change)
layout_fix_panes(wp->window, wp->window->sx, wp->window->sy);
}
+void
+layout_resize_pane_mouse(struct client *c, struct mouse_event *mouse)
+{
+ struct window *w;
+ struct window_pane *wp;
+ int pane_border;
+
+ w = c->session->curw->window;
+
+ pane_border = 0;
+ if ((c->last_mouse.b & MOUSE_BUTTON) != MOUSE_UP &&
+ (c->last_mouse.b & MOUSE_RESIZE_PANE)) {
+ TAILQ_FOREACH(wp, &w->panes, entry) {
+ if (wp->xoff + wp->sx == c->last_mouse.x &&
+ wp->yoff <= 1 + c->last_mouse.y &&
+ wp->yoff + wp->sy >= c->last_mouse.y) {
+ layout_resize_pane(wp, LAYOUT_LEFTRIGHT,
+ mouse->x - c->last_mouse.x);
+ pane_border = 1;
+ }
+ if (wp->yoff + wp->sy == c->last_mouse.y &&
+ wp->xoff <= 1 + c->last_mouse.x &&
+ wp->xoff + wp->sx >= c->last_mouse.x) {
+ layout_resize_pane(wp, LAYOUT_TOPBOTTOM,
+ mouse->y - c->last_mouse.y);
+ pane_border = 1;
+ }
+ }
+ if (pane_border)
+ server_redraw_window(w);
+ } else if (mouse->b != MOUSE_UP &&
+ mouse->b == (mouse->b & MOUSE_BUTTON)) {
+ TAILQ_FOREACH(wp, &w->panes, entry) {
+ if ((wp->xoff + wp->sx == mouse->x &&
+ wp->yoff <= 1 + mouse->y &&
+ wp->yoff + wp->sy >= mouse->y) ||
+ (wp->yoff + wp->sy == mouse->y &&
+ wp->xoff <= 1 + mouse->x &&
+ wp->xoff + wp->sx >= mouse->x)) {
+ pane_border = 1;
+ }
+ }
+ }
+ if (pane_border)
+ mouse->b |= MOUSE_RESIZE_PANE;
+}
+
int
layout_resize_pane_grow(
struct layout_cell *lc, enum layout_type type, int needed)
diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c
index 98af34420fd..ee2d927c91f 100644
--- a/usr.bin/tmux/options-table.c
+++ b/usr.bin/tmux/options-table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options-table.c,v 1.6 2011/05/08 19:53:06 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.7 2011/05/08 20:34:12 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -193,6 +193,11 @@ const struct options_table_entry session_options_table[] = {
.default_num = 20
},
+ { .name = "mouse-resize-pane",
+ .type = OPTIONS_TABLE_FLAG,
+ .default_num = 0
+ },
+
{ .name = "mouse-select-pane",
.type = OPTIONS_TABLE_FLAG,
.default_num = 0
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 4ceafd136c2..94ab0f74b09 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.56 2011/05/04 18:10:28 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.57 2011/05/08 20:34:12 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -89,6 +89,9 @@ server_client_create(int fd)
c->prompt_buffer = NULL;
c->prompt_index = 0;
+ c->last_mouse.b = MOUSE_UP;
+ c->last_mouse.x = c->last_mouse.y = -1;
+
evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
@@ -344,6 +347,9 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
return;
}
}
+ if (options_get_number(oo, "mouse-resize-pane"))
+ layout_resize_pane_mouse(c, mouse);
+ memcpy(&c->last_mouse, mouse, sizeof c->last_mouse);
window_pane_mouse(wp, c->session, mouse);
return;
}
@@ -476,14 +482,24 @@ server_client_reset_state(struct client *c)
tty_cursor(&c->tty, wp->xoff + s->cx, wp->yoff + s->cy);
/*
+ * Resizing panes with the mouse requires at least button mode to give
+ * a smooth appearance.
+ */
+ mode = s->mode;
+ if ((c->last_mouse.b & MOUSE_RESIZE_PANE) &&
+ !(mode & (MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)))
+ mode |= MODE_MOUSE_BUTTON;
+
+ /*
* Any mode will do for mouse-select-pane, but set standard mode if
* none.
*/
- mode = s->mode;
if ((mode & ALL_MOUSE_MODES) == 0) {
if (TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry) != NULL &&
options_get_number(oo, "mouse-select-pane"))
mode |= MODE_MOUSE_STANDARD;
+ else if (options_get_number(oo, "mouse-resize-pane"))
+ mode |= MODE_MOUSE_STANDARD;
else if (options_get_number(oo, "mouse-select-window"))
mode |= MODE_MOUSE_STANDARD;
else if (options_get_number(wo, "mode-mouse"))
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 2f7763273ed..7d0120a28b4 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.225 2011/05/08 19:53:06 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.226 2011/05/08 20:34:12 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -1888,6 +1888,12 @@ Set status line message foreground colour.
Set the number of error or information messages to save in the message log for
each client.
The default is 20.
+.It Xo Ic mouse-resize-pane
+.Op Ic on | off
+.Xc
+If on,
+.Nm
+captures the mouse and allows panes to be resized by dragging on their borders.
.It Xo Ic mouse-select-pane
.Op Ic on | off
.Xc
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 4ee800443d9..9db4977b952 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.283 2011/05/08 19:53:07 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.284 2011/05/08 20:34:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1086,6 +1086,7 @@ struct mouse_event {
#define MOUSE_BUTTON 3
#define MOUSE_DRAG 32
#define MOUSE_45 64
+#define MOUSE_RESIZE_PANE 128 /* marker for resizing */
u_int x;
u_int y;
};
@@ -1177,6 +1178,8 @@ struct client {
struct session *session;
struct session *last_session;
+ struct mouse_event last_mouse;
+
int references;
};
ARRAY_DECL(clients, struct client *);
@@ -1925,6 +1928,8 @@ void layout_free(struct window *);
void layout_resize(struct window *, u_int, u_int);
void layout_resize_pane(
struct window_pane *, enum layout_type, int);
+void layout_resize_pane_mouse(
+ struct client *c, struct mouse_event *mouse);
void layout_assign_pane(struct layout_cell *, struct window_pane *);
struct layout_cell *layout_split_pane(
struct window_pane *, enum layout_type, int);