summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-resize-pane.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2018-06-09 17:05:53 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2018-06-09 17:05:53 +0000
commit553f236eb5289308ffde7e12e938136e489b896b (patch)
tree4e910d454b162d4d435b54200f3144700088f09a /usr.bin/tmux/cmd-resize-pane.c
parent76736bdd7e7ccc4da58425ce57672f1b31b28370 (diff)
Make it possible to resize multiple panes by dragging corners, from Dan
Aloni in GitHub issue 1376.
Diffstat (limited to 'usr.bin/tmux/cmd-resize-pane.c')
-rw-r--r--usr.bin/tmux/cmd-resize-pane.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c
index c0508183953..43b3db61c4c 100644
--- a/usr.bin/tmux/cmd-resize-pane.c
+++ b/usr.bin/tmux/cmd-resize-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-resize-pane.c,v 1.32 2018/06/08 20:54:22 nicm Exp $ */
+/* $OpenBSD: cmd-resize-pane.c,v 1.33 2018/06/09 17:05:52 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -131,7 +131,12 @@ cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
struct winlink *wl;
struct window *w;
u_int y, ly, x, lx;
- struct layout_cell *lc;
+ struct layout_cell *cells[5], *lc;
+ u_int ncells = 0, i, j, resizes = 0;
+ enum layout_type type;
+ static const int offsets[nitems(cells)][2] = {
+ { 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
+ };
wl = cmd_mouse_window(m, NULL);
if (wl == NULL) {
@@ -151,16 +156,37 @@ cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
ly = m->statusat - 1;
- lc = layout_search_by_border(w->layout_root, lx, ly);
- if (lc == NULL)
- return;
+ for (i = 0; i < nitems(cells); i++) {
+ lc = layout_search_by_border(w->layout_root, lx + offsets[i][0],
+ ly + offsets[i][1]);
+ if (lc == NULL)
+ continue;
+
+ for (j = 0; j < ncells; j++) {
+ if (cells[j] == lc) {
+ lc = NULL;
+ break;
+ }
+ }
+ if (lc == NULL)
+ continue;
- if (y != ly && lc->parent->type == LAYOUT_TOPBOTTOM)
- layout_resize_layout(w, lc, LAYOUT_TOPBOTTOM, y - ly, 0);
- else if (x != lx && lc->parent->type == LAYOUT_LEFTRIGHT)
- layout_resize_layout(w, lc, LAYOUT_LEFTRIGHT, x - lx, 0);
- else
+ cells[ncells] = lc;
+ ncells++;
+ }
+ if (ncells == 0)
return;
- server_redraw_window(w);
+ for (i = 0; i < ncells; i++) {
+ type = cells[i]->parent->type;
+ if (y != ly && type == LAYOUT_TOPBOTTOM) {
+ layout_resize_layout(w, cells[i], type, y - ly, 0);
+ resizes++;
+ } else if (x != lx && type == LAYOUT_LEFTRIGHT) {
+ layout_resize_layout(w, cells[i], type, x - lx, 0);
+ resizes++;
+ }
+ }
+ if (resizes != 0)
+ server_redraw_window(w);
}