Merge branch 'floating_panes' into floating_panes_staging

This commit is contained in:
Nicholas Marriott
2026-05-28 08:25:31 +01:00

View File

@@ -2094,36 +2094,22 @@ screen_write_collect_scroll(struct screen_write_ctx *ctx, u_int bg)
TAILQ_INSERT_TAIL(&ctx->s->write_list[s->rlower].items, ci, entry); TAILQ_INSERT_TAIL(&ctx->s->write_list[s->rlower].items, ci, entry);
} }
/* Flush collected lines. */ /* Flush collected scrolling. */
static void static int
screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only, screen_write_collect_flush_scrolled(struct screen_write_ctx *ctx)
const char *from)
{ {
struct window_pane *wp = ctx->wp; struct window_pane *wp = ctx->wp;
struct screen *s = ctx->s; struct screen *s = ctx->s;
struct screen_write_citem *ci, *tmp;
struct screen_write_cline *cl;
u_int y, cx, cy, last, items = 0, i;
u_int wr_start, wr_end, wr_length, wsx, wsy;
int written;
int r_start, r_end, ci_start, ci_end;
int xoff, yoff;
struct tty_ctx ttyctx; struct tty_ctx ttyctx;
struct visible_ranges *r;
struct visible_range *ri;
if (s->mode & MODE_SYNC)
goto discard;
if (ctx->scrolled != 0) {
screen_write_initctx(ctx, &ttyctx, 1, 1); screen_write_initctx(ctx, &ttyctx, 1, 1);
if (ttyctx.flags & TTY_CTX_PANE_OBSCURED && wp != NULL) { if (ttyctx.flags & TTY_CTX_PANE_OBSCURED && wp != NULL) {
screen_write_redraw_pane(ctx, &ttyctx); screen_write_redraw_pane(ctx, &ttyctx);
goto discard; return 0;
} }
log_debug("%s: scrolled %u (region %u-%u)", __func__, log_debug("%s: scrolled %u (region %u-%u)", __func__, ctx->scrolled,
ctx->scrolled, s->rupper, s->rlower); s->rupper, s->rlower);
if (ctx->scrolled > s->rlower - s->rupper + 1) if (ctx->scrolled > s->rlower - s->rupper + 1)
ctx->scrolled = s->rlower - s->rupper + 1; ctx->scrolled = s->rlower - s->rupper + 1;
@@ -2135,17 +2121,25 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
if (wp != NULL) if (wp != NULL)
wp->flags |= PANE_REDRAWSCROLLBAR; wp->flags |= PANE_REDRAWSCROLLBAR;
return 1;
} }
ctx->scrolled = 0;
ctx->bg = 8;
if (scroll_only) /* Flush a collected line. */
return; static u_int
screen_write_collect_flush_line(struct screen_write_ctx *ctx, u_int y)
{
struct window_pane *wp = ctx->wp;
struct screen *s = ctx->s;
struct screen_write_citem *ci, *tmp;
struct screen_write_cline *cl = &s->write_list[y];
u_int last = UINT_MAX, items = 0, wsx, wsy;
u_int w_start, w_end, w_length, i;
int xoff, yoff, written;
int r_start, r_end, c_start, c_end;
struct tty_ctx ttyctx;
struct visible_ranges *r;
struct visible_range *ri;
cx = s->cx; cy = s->cy;
/* The xoff and width of window pane relative to the window we
* are writing to relative to the visible_ranges array. */
if (wp != NULL) { if (wp != NULL) {
wsx = wp->window->sx; wsx = wp->window->sx;
wsy = wp->window->sy; wsy = wp->window->sy;
@@ -2157,66 +2151,55 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
xoff = 0; xoff = 0;
yoff = 0; yoff = 0;
} }
for (y = 0; y < screen_size_y(s); y++) {
if (y + yoff >= wsy) if (y + yoff >= wsy)
continue; return (0);
cl = &ctx->s->write_list[y];
r = screen_redraw_get_visible_ranges(wp, 0, y + yoff, wsx, r = screen_redraw_get_visible_ranges(wp, 0, y + yoff, wsx, NULL);
NULL);
last = UINT_MAX;
TAILQ_FOREACH_SAFE(ci, &cl->items, entry, tmp) { TAILQ_FOREACH_SAFE(ci, &cl->items, entry, tmp) {
log_debug("collect list: x=%u (last %u), y=%u, used=%u", log_debug("collect list: x=%u (last %u), y=%u, used=%u", ci->x,
ci->x, last, y, ci->used); last, y, ci->used);
if (last != UINT_MAX && ci->x <= last) { if (last != UINT_MAX && ci->x <= last)
fatalx("collect list not in order: %u <= %u", fatalx("collect list bad order: %u <= %u", ci->x, last);
ci->x, last);
} w_length = 0;
wr_length = 0;
written = 0; written = 0;
for (i = 0; i < r->used; i++) { for (i = 0; i < r->used; i++) {
ri = &r->ranges[i]; ri = &r->ranges[i];
if (ri->nx == 0) if (ri->nx == 0)
continue; continue;
r_start = ri->px; r_start = ri->px;
r_end = ri->px + ri->nx; r_end = ri->px + ri->nx;
ci_start = ci->x; c_start = ci->x;
ci_end = ci->x + ci->used; c_end = ci->x + ci->used;
if (ci_start + xoff > r_end || if (c_start + xoff > r_end || c_end + xoff < r_start)
ci_end + xoff < r_start) continue;
if (r_start > c_start + xoff)
w_start = c_start + (r_start - c_start + xoff);
else
w_start = c_start;
if (c_end + xoff > r_end)
w_end = c_end - (c_end + xoff - r_end);
else
w_end = c_end;
w_length = w_end - w_start;
if (w_length <= 0)
continue; continue;
if (r_start > ci_start + xoff) screen_write_set_cursor(ctx, w_start, y);
wr_start = ci_start +
(r_start - (ci_start + xoff));
else
wr_start = ci_start;
if (ci_end + xoff > r_end)
wr_end = ci_end -
((ci_end + xoff) - r_end);
else
wr_end = ci_end;
wr_length = wr_end - wr_start;
if (wr_length <= 0)
continue;
screen_write_set_cursor(ctx, wr_start, y);
if (ci->type == CLEAR) { if (ci->type == CLEAR) {
screen_write_initctx(ctx, &ttyctx, 1, 0); screen_write_initctx(ctx, &ttyctx, 1, 0);
ttyctx.bg = ci->bg; ttyctx.bg = ci->bg;
ttyctx.n = wr_length; ttyctx.n = w_length;
tty_write(tty_cmd_clearcharacter, tty_write(tty_cmd_clearcharacter, &ttyctx);
&ttyctx);
} else { } else {
screen_write_initctx(ctx, &ttyctx, 0, 0); screen_write_initctx(ctx, &ttyctx, 0, 0);
ttyctx.cell = &ci->gc; ttyctx.cell = &ci->gc;
if (ci->wrapped) if (ci->wrapped)
ttyctx.flags |= TTY_CTX_WRAPPED; ttyctx.flags |= TTY_CTX_WRAPPED;
ttyctx.data.data = cl->data + wr_start; ttyctx.data.data = cl->data + w_start;
ttyctx.data.size = wr_length; ttyctx.data.size = w_length;
tty_write(tty_cmd_cells, &ttyctx); tty_write(tty_cmd_cells, &ttyctx);
} }
items++; items++;
@@ -2228,8 +2211,35 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
screen_write_free_citem(ci); screen_write_free_citem(ci);
} }
} }
return (items);
} }
/* Flush collected lines. */
static void
screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
const char *from)
{
struct screen *s = ctx->s;
u_int y, cx, cy, items = 0;
struct screen_write_citem *ci, *tmp;
struct screen_write_cline *cl;
if (s->mode & MODE_SYNC)
goto discard;
if (ctx->scrolled != 0) {
if (!screen_write_collect_flush_scrolled(ctx))
goto discard;
ctx->scrolled = 0;
}
ctx->bg = 8;
if (scroll_only)
return;
cx = s->cx; cy = s->cy;
for (y = 0; y < screen_size_y(s); y++)
items += screen_write_collect_flush_line(ctx, y);
s->cx = cx; s->cy = cy; s->cx = cx; s->cy = cy;
log_debug("%s: flushed %u items (%s)", __func__, items, from); log_debug("%s: flushed %u items (%s)", __func__, items, from);
@@ -2237,7 +2247,7 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
discard: discard:
for (y = 0; y < screen_size_y(s); y++) { for (y = 0; y < screen_size_y(s); y++) {
cl = &ctx->s->write_list[y]; cl = &s->write_list[y];
TAILQ_FOREACH_SAFE(ci, &cl->items, entry, tmp) { TAILQ_FOREACH_SAFE(ci, &cl->items, entry, tmp) {
TAILQ_REMOVE(&cl->items, ci, entry); TAILQ_REMOVE(&cl->items, ci, entry);
screen_write_free_citem(ci); screen_write_free_citem(ci);