Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2026-06-06 19:00:06 +01:00
4 changed files with 103 additions and 62 deletions

View File

@@ -104,7 +104,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
flags |= SPAWN_EMPTY; flags |= SPAWN_EMPTY;
if (is_floating) if (is_floating)
lc = layout_get_floating_cell(item, args, w, wp, lc, &cause); lc = layout_get_floating_cell(item, args, w, wp, &cause);
else else
lc = layout_get_tiled_cell(item, args, w, wp, flags, &cause); lc = layout_get_tiled_cell(item, args, w, wp, flags, &cause);
if (cause != NULL) { if (cause != NULL) {

141
layout.c
View File

@@ -46,8 +46,6 @@ static int layout_set_size_check(struct window *, struct layout_cell *,
enum layout_type, int); enum layout_type, int);
static void layout_resize_child_cells(struct window *, static void layout_resize_child_cells(struct window *,
struct layout_cell *); struct layout_cell *);
void layout_redistribute_cells(struct window *, struct layout_cell *,
enum layout_type);
/* Create a new layout cell. */ /* Create a new layout cell. */
struct layout_cell * struct layout_cell *
@@ -252,6 +250,8 @@ layout_fix_offsets1(struct layout_cell *lc)
if (lc->type == LAYOUT_LEFTRIGHT) { if (lc->type == LAYOUT_LEFTRIGHT) {
xoff = lc->xoff; xoff = lc->xoff;
TAILQ_FOREACH(lcchild, &lc->cells, entry) { TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
lcchild->xoff = xoff; lcchild->xoff = xoff;
lcchild->yoff = lc->yoff; lcchild->yoff = lc->yoff;
if (lcchild->type != LAYOUT_WINDOWPANE) if (lcchild->type != LAYOUT_WINDOWPANE)
@@ -261,6 +261,8 @@ layout_fix_offsets1(struct layout_cell *lc)
} else { } else {
yoff = lc->yoff; yoff = lc->yoff;
TAILQ_FOREACH(lcchild, &lc->cells, entry) { TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
lcchild->xoff = lc->xoff; lcchild->xoff = lc->xoff;
lcchild->yoff = yoff; lcchild->yoff = yoff;
if (lcchild->type != LAYOUT_WINDOWPANE) if (lcchild->type != LAYOUT_WINDOWPANE)
@@ -276,6 +278,10 @@ layout_fix_offsets(struct window *w)
{ {
struct layout_cell *lc = w->layout_root; struct layout_cell *lc = w->layout_root;
/* Root consists of a single floating cell */
if (lc->flags & LAYOUT_CELL_FLOATING)
return;
lc->xoff = 0; lc->xoff = 0;
lc->yoff = 0; lc->yoff = 0;
@@ -484,8 +490,11 @@ layout_resize_adjust(struct window *w, struct layout_cell *lc,
/* Child cell runs in a different direction. */ /* Child cell runs in a different direction. */
if (lc->type != type) { if (lc->type != type) {
TAILQ_FOREACH(lcchild, &lc->cells, entry) TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
layout_resize_adjust(w, lcchild, type, change); layout_resize_adjust(w, lcchild, type, change);
}
return; return;
} }
@@ -497,6 +506,8 @@ layout_resize_adjust(struct window *w, struct layout_cell *lc,
TAILQ_FOREACH(lcchild, &lc->cells, entry) { TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (change == 0) if (change == 0)
break; break;
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
if (change > 0) { if (change > 0) {
layout_resize_adjust(w, lcchild, type, 1); layout_resize_adjust(w, lcchild, type, 1);
change--; change--;
@@ -515,30 +526,33 @@ void
layout_destroy_cell(struct window *w, struct layout_cell *lc, layout_destroy_cell(struct window *w, struct layout_cell *lc,
struct layout_cell **lcroot) struct layout_cell **lcroot)
{ {
struct layout_cell *lcother, *lcparent; struct layout_cell *lcother = NULL, *lcparent;
/* /* If no parent, this is the last pane in a window. */
* If no parent, this is either a floating pane or the last
* pane so window close is imminent and there is no need to
* resize anything.
*/
lcparent = lc->parent; lcparent = lc->parent;
if (lcparent == NULL) { if (lcparent == NULL) {
if (lc->wp != NULL && !window_pane_is_floating(lc->wp)) if (lc->wp != NULL)
*lcroot = NULL; *lcroot = NULL;
layout_free_cell(lc); layout_free_cell(lc);
return; return;
} }
/* Merge the space into the previous or next cell. */ if (~lc->flags & LAYOUT_CELL_FLOATING) {
if (lc == TAILQ_FIRST(&lcparent->cells)) /* Merge the space into the previous or next cell. */
lcother = TAILQ_NEXT(lc, entry); if (lc == TAILQ_FIRST(&lcparent->cells))
else lcother = TAILQ_NEXT(lc, entry);
lcother = TAILQ_PREV(lc, layout_cells, entry); else
if (lcother != NULL && lcparent->type == LAYOUT_LEFTRIGHT) lcother = TAILQ_PREV(lc, layout_cells, entry);
layout_resize_adjust(w, lcother, lcparent->type, lc->sx + 1); }
else if (lcother != NULL) if (lcother != NULL && (~lcother->flags & LAYOUT_CELL_FLOATING)) {
layout_resize_adjust(w, lcother, lcparent->type, lc->sy + 1); if (lcparent->type == LAYOUT_LEFTRIGHT) {
layout_resize_adjust(w, lcother, lcparent->type,
lc->sx + 1);
} else {
layout_resize_adjust(w, lcother, lcparent->type,
lc->sy + 1);
}
}
/* Remove this from the parent's list. */ /* Remove this from the parent's list. */
TAILQ_REMOVE(&lcparent->cells, lc, entry); TAILQ_REMOVE(&lcparent->cells, lc, entry);
@@ -554,8 +568,10 @@ layout_destroy_cell(struct window *w, struct layout_cell *lc,
lc->parent = lcparent->parent; lc->parent = lcparent->parent;
if (lc->parent == NULL) { if (lc->parent == NULL) {
lc->xoff = 0; if (~lc->flags & LAYOUT_CELL_FLOATING) {
lc->yoff = 0; lc->xoff = 0;
lc->yoff = 0;
}
*lcroot = lc; *lcroot = lc;
} else } else
TAILQ_REPLACE(&lc->parent->cells, lcparent, lc, entry); TAILQ_REPLACE(&lc->parent->cells, lcparent, lc, entry);
@@ -603,6 +619,8 @@ layout_resize(struct window *w, u_int sx, u_int sy)
* out proportionately - this should leave the layout fitting the new * out proportionately - this should leave the layout fitting the new
* window size. * window size.
*/ */
if (lc->type == LAYOUT_WINDOWPANE && (lc->flags & LAYOUT_CELL_FLOATING))
return;
xchange = sx - lc->sx; xchange = sx - lc->sx;
xlimit = layout_resize_check(w, lc, LAYOUT_LEFTRIGHT); xlimit = layout_resize_check(w, lc, LAYOUT_LEFTRIGHT);
if (xchange < 0 && xchange < -xlimit) if (xchange < 0 && xchange < -xlimit)
@@ -915,6 +933,8 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
count = 0; count = 0;
previous = 0; previous = 0;
TAILQ_FOREACH(lcchild, &lc->cells, entry) { TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
count++; count++;
if (lc->type == LAYOUT_LEFTRIGHT) if (lc->type == LAYOUT_LEFTRIGHT)
previous += lcchild->sx; previous += lcchild->sx;
@@ -933,6 +953,8 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
/* Resize children into the new size. */ /* Resize children into the new size. */
idx = 0; idx = 0;
TAILQ_FOREACH(lcchild, &lc->cells, entry) { TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
if (lc->type == LAYOUT_TOPBOTTOM) { if (lc->type == LAYOUT_TOPBOTTOM) {
lcchild->sx = lc->sx; lcchild->sx = lc->sx;
lcchild->xoff = lc->xoff; lcchild->xoff = lc->xoff;
@@ -941,9 +963,10 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
lc->type, lc->sx, count - idx, available); lc->type, lc->sx, count - idx, available);
available -= (lcchild->sx + 1); available -= (lcchild->sx + 1);
} }
if (lc->type == LAYOUT_LEFTRIGHT) if (lc->type == LAYOUT_LEFTRIGHT) {
lcchild->sy = lc->sy; lcchild->sy = lc->sy;
else { lcchild->yoff = lc->yoff;
} else {
lcchild->sy = layout_new_pane_size(w, previous, lcchild, lcchild->sy = layout_new_pane_size(w, previous, lcchild,
lc->type, lc->sy, count - idx, available); lc->type, lc->sy, count - idx, available);
available -= (lcchild->sy + 1); available -= (lcchild->sy + 1);
@@ -1132,6 +1155,39 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
return (lcnew); return (lcnew);
} }
/*
* Creates a cell for a new floating pane. This must be followed by
* layout_assign_pane before much else happens!
*/
struct layout_cell *
layout_floating_pane(struct window *w, u_int sx, u_int sy, int ox, int oy)
{
struct layout_cell *lc = w->layout_root, *lcnew, *lcparent;
if (lc->type == LAYOUT_WINDOWPANE) {
/*
* Adding a pane to a root that doesn't have a container. Must
* create and insert a new root.
*/
lcparent = layout_create_cell(NULL);
layout_make_node(lcparent, LAYOUT_TOPBOTTOM);
layout_set_size(lcparent, w->sx, w->sy, 0, 0);
w->layout_root = lcparent;
/* Insert the old cell. */
lc->parent = lcparent;
TAILQ_INSERT_HEAD(&lcparent->cells, lc, entry);
} else
lcparent = w->layout_root;
lcnew = layout_create_cell(lcparent);
TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry);
lcnew->flags |= LAYOUT_CELL_FLOATING;
layout_set_size(lcnew, sx, sy, ox, oy);
return (lcnew);
}
/* Destroy the cell associated with a pane. */ /* Destroy the cell associated with a pane. */
void void
layout_close_pane(struct window_pane *wp) layout_close_pane(struct window_pane *wp)
@@ -1143,6 +1199,7 @@ layout_close_pane(struct window_pane *wp)
/* Remove the cell. */ /* Remove the cell. */
layout_destroy_cell(w, wp->layout_cell, &w->layout_root); layout_destroy_cell(w, wp->layout_cell, &w->layout_root);
wp->layout_cell = NULL;
/* Fix pane offsets and sizes. */ /* Fix pane offsets and sizes. */
if (w->layout_root != NULL) { if (w->layout_root != NULL) {
@@ -1299,49 +1356,37 @@ layout_get_tiled_cell(struct cmdq_item *item, struct args *args,
/* Get a new floating cell. */ /* Get a new floating cell. */
struct layout_cell * struct layout_cell *
layout_get_floating_cell(struct cmdq_item *item, struct args *args, layout_get_floating_cell(struct cmdq_item *item, struct args *args,
struct window *w, __unused struct window_pane *wp, struct layout_cell *lc, struct window *w, __unused struct window_pane *wp, char **cause)
char **cause)
{ {
u_int sx, sy, ox, oy; struct layout_cell *lcnew;
int new = 0; u_int sx = w->sx / 2, sy = w->sy / 4;
int ox = INT_MAX, oy = INT_MAX;
if (lc == NULL) {
lc = layout_create_cell(NULL);
new = 1;
}
sx = lc->sx; sy = lc->sy;
ox = lc->xoff; oy = lc->yoff;
if (args_has(args, 'x')) { if (args_has(args, 'x')) {
sx = args_percentage_and_expand(args, 'x', 0, USHRT_MAX, w->sx, sx = args_percentage_and_expand(args, 'x', 0, USHRT_MAX, w->sx,
item, cause); item, cause);
if (*cause != NULL) if (*cause != NULL)
goto error; return (NULL);
} }
if (args_has(args, 'y')) { if (args_has(args, 'y')) {
sy = args_percentage_and_expand(args, 'y', 0, USHRT_MAX, w->sy, sy = args_percentage_and_expand(args, 'y', 0, USHRT_MAX, w->sy,
item, cause); item, cause);
if (*cause != NULL) if (*cause != NULL)
goto error; return (NULL);
} }
if (args_has(args, 'X')) { if (args_has(args, 'X')) {
ox = args_percentage_and_expand(args, 'X', 0, USHRT_MAX, w->sx, ox = args_percentage_and_expand(args, 'X', 0, USHRT_MAX, w->sx,
item, cause); item, cause);
if (*cause != NULL) if (*cause != NULL)
goto error; return (NULL);
} }
if (args_has(args, 'Y')) { if (args_has(args, 'Y')) {
oy = args_percentage_and_expand(args, 'Y', 0, USHRT_MAX, w->sy, oy = args_percentage_and_expand(args, 'Y', 0, USHRT_MAX, w->sy,
item, cause); item, cause);
if (*cause != NULL) if (*cause != NULL)
goto error; return (NULL);
} }
if (sx == UINT_MAX)
sx = w->sx / 2;
if (sy == UINT_MAX)
sy = w->sy / 4;
if (ox == INT_MAX) { if (ox == INT_MAX) {
if (w->last_new_pane_x == 0) if (w->last_new_pane_x == 0)
ox = 4; ox = 4;
@@ -1362,13 +1407,7 @@ layout_get_floating_cell(struct cmdq_item *item, struct args *args,
} }
w->last_new_pane_y = oy; w->last_new_pane_y = oy;
} }
layout_set_size(lc, sx, sy, ox, oy);
lc->flags |= LAYOUT_CELL_FLOATING;
return (lc); lcnew = layout_floating_pane(w, sx, sy, ox, oy);
return (lcnew);
error:
if (new)
layout_destroy_cell(w, lc, &w->layout_root);
return (NULL);
} }

View File

@@ -624,21 +624,23 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
struct grid_line *gl, *sgl; struct grid_line *gl, *sgl;
struct grid_cell gc; struct grid_cell gc;
u_int xx, yy, cx = s->cx, cy = s->cy; u_int xx, yy, cx = s->cx, cy = s->cy;
int yoff = 0; int xoff = 0, yoff = 0;
struct visible_ranges *r; struct visible_ranges *r;
if (nx == 0 || ny == 0) if (nx == 0 || ny == 0)
return; return;
if (wp != NULL) if (wp != NULL) {
xoff = wp->xoff;
yoff = wp->yoff; yoff = wp->yoff;
}
for (yy = py; yy < py + ny; yy++) { for (yy = py; yy < py + ny; yy++) {
if (yy >= gd->hsize + gd->sy) if (yy >= gd->hsize + gd->sy)
break; break;
s->cx = cx; s->cx = cx;
screen_write_initctx(ctx, &ttyctx, 0, 0); screen_write_initctx(ctx, &ttyctx, 0, 0);
r = screen_redraw_get_visible_ranges(wp, px, s->cy + yoff, nx, r = screen_redraw_get_visible_ranges(wp, xoff + s->cx,
NULL); s->cy + yoff, nx, NULL);
for (xx = px; xx < px + nx; xx++) { for (xx = px; xx < px + nx; xx++) {
gl = grid_get_line(gd, yy); gl = grid_get_line(gd, yy);
sgl = grid_get_line(s->grid, s->cy); sgl = grid_get_line(s->grid, s->cy);
@@ -650,7 +652,7 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
break; break;
grid_view_set_cell(s->grid, s->cx, s->cy, &gc); grid_view_set_cell(s->grid, s->cx, s->cy, &gc);
if (!screen_redraw_is_visible(r, px)) if (!screen_redraw_is_visible(r, xoff + s->cx))
break; break;
ttyctx.cell = &gc; ttyctx.cell = &gc;
ttyctx.flags &= (TTY_CTX_OVERLAY_SYNC|TTY_CTX_SYNC); ttyctx.flags &= (TTY_CTX_OVERLAY_SYNC|TTY_CTX_SYNC);

10
tmux.h
View File

@@ -1269,7 +1269,7 @@ struct window_pane {
#define PANE_FOCUSED 0x4 #define PANE_FOCUSED 0x4
#define PANE_VISITED 0x8 #define PANE_VISITED 0x8
#define PANE_ZOOMED 0x10 #define PANE_ZOOMED 0x10
/* unused 0x20 */ /* 0x20 unused */
#define PANE_INPUTOFF 0x40 #define PANE_INPUTOFF 0x40
#define PANE_CHANGED 0x80 #define PANE_CHANGED 0x80
#define PANE_EXITED 0x100 #define PANE_EXITED 0x100
@@ -1473,8 +1473,7 @@ TAILQ_HEAD(layout_cells, layout_cell);
struct layout_cell { struct layout_cell {
enum layout_type type; enum layout_type type;
/* unused 0x1 */ #define LAYOUT_CELL_FLOATING 0x1
#define LAYOUT_CELL_FLOATING 0x2
int flags; int flags;
struct layout_cell *parent; struct layout_cell *parent;
@@ -3534,12 +3533,13 @@ void layout_assign_pane(struct layout_cell *, struct window_pane *,
int); int);
struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type, struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
int, int); int, int);
struct layout_cell *layout_floating_pane(struct window *, u_int, u_int, int,
int);
void layout_close_pane(struct window_pane *); void layout_close_pane(struct window_pane *);
int layout_spread_cell(struct window *, struct layout_cell *); int layout_spread_cell(struct window *, struct layout_cell *);
void layout_spread_out(struct window_pane *); void layout_spread_out(struct window_pane *);
struct layout_cell *layout_get_floating_cell(struct cmdq_item *, struct args *, struct layout_cell *layout_get_floating_cell(struct cmdq_item *, struct args *,
struct window *, struct window_pane *, struct layout_cell *, struct window *, struct window_pane *, char **);
char **);
struct layout_cell *layout_get_tiled_cell(struct cmdq_item *, struct args *, struct layout_cell *layout_get_tiled_cell(struct cmdq_item *, struct args *,
struct window *, struct window_pane *, int, char **); struct window *, struct window_pane *, int, char **);