From f6bad7efd76109de122bb3b670d0e18f86ec38bb Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 8 Jun 2018 20:54:22 +0000 Subject: Instead of working out which pane to resize with the mouse by walking the panes list, look through the layout cells for the nearest border and resize that cell. From Dan Aloni in GitHub issue 1374. --- cmd-resize-pane.c | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) (limited to 'cmd-resize-pane.c') diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index bbb78de7..cfde83b3 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -129,14 +129,16 @@ static void cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m) { struct winlink *wl; - struct window_pane *loop, *wp_x, *wp_y; - u_int y, ly, x, lx, sx, sy, ex, ey; + struct window *w; + u_int y, ly, x, lx; + struct layout_cell *lc; wl = cmd_mouse_window(m, NULL); if (wl == NULL) { c->tty.mouse_drag_update = NULL; return; } + w = wl->window; y = m->y; x = m->x; if (m->statusat == 0 && y > 0) @@ -149,37 +151,16 @@ 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; - wp_x = wp_y = NULL; - TAILQ_FOREACH(loop, &wl->window->panes, entry) { - if (!window_pane_visible(loop)) - continue; - - sx = loop->xoff; - if (sx != 0) - sx--; - ex = loop->xoff + loop->sx; - - sy = loop->yoff; - if (sy != 0) - sy--; - ey = loop->yoff + loop->sy; - - if ((lx == sx || lx == ex) && - (ly >= sy && ly <= ey) && - (wp_x == NULL || loop->sy > wp_x->sy)) - wp_x = loop; - if ((ly == sy || ly == ey) && - (lx >= sx && lx <= ex) && - (wp_y == NULL || loop->sx > wp_y->sx)) - wp_y = loop; - } - if (wp_x == NULL && wp_y == NULL) { - c->tty.mouse_drag_update = NULL; + lc = layout_search_by_border(w->layout_root, lx, ly); + if (lc == NULL) return; - } - if (wp_x != NULL) - layout_resize_pane(wp_x, LAYOUT_LEFTRIGHT, x - lx, 0); - if (wp_y != NULL) - layout_resize_pane(wp_y, LAYOUT_TOPBOTTOM, y - ly, 0); - server_redraw_window(wl->window); + + 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 + return; + + server_redraw_window(w); } -- cgit v1.2.3