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.
This commit is contained in:
nicm
2018-06-08 20:54:22 +00:00
parent ff45b2d343
commit f6bad7efd7
3 changed files with 85 additions and 58 deletions

View File

@ -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);
}