Merge branch 'floating_panes' into floating_panes_staging

This commit is contained in:
Nicholas Marriott
2026-05-22 11:01:34 +01:00
4 changed files with 156 additions and 168 deletions

View File

@@ -36,7 +36,6 @@ static int screen_write_overwrite(struct screen_write_ctx *,
struct grid_cell *, u_int);
static int screen_write_combine(struct screen_write_ctx *,
const struct grid_cell *);
static int screen_write_pane_obscured(struct window_pane *);
struct screen_write_citem {
u_int x;
@@ -134,7 +133,7 @@ screen_write_set_client_cb(struct tty_ctx *ttyctx, struct client *c)
{
struct window_pane *wp = ttyctx->arg;
if (ttyctx->allow_invisible_panes) {
if (ttyctx->flags & TTY_CTX_INVISIBLE_PANES) {
if (session_has(c->session, wp->window))
return (1);
return (0);
@@ -158,8 +157,11 @@ screen_write_set_client_cb(struct tty_ctx *ttyctx, struct client *c)
return (-1);
}
ttyctx->bigger = tty_window_offset(&c->tty, &ttyctx->wox, &ttyctx->woy,
&ttyctx->wsx, &ttyctx->wsy);
if (tty_window_offset(&c->tty, &ttyctx->wox, &ttyctx->woy, &ttyctx->wsx,
&ttyctx->wsy))
ttyctx->flags |= TTY_CTX_WINDOW_BIGGER;
else
ttyctx->flags &= ~TTY_CTX_WINDOW_BIGGER;
ttyctx->xoff = ttyctx->rxoff = wp->xoff;
ttyctx->yoff = ttyctx->ryoff = wp->yoff;
@@ -170,10 +172,43 @@ screen_write_set_client_cb(struct tty_ctx *ttyctx, struct client *c)
return (1);
}
/* Return 1 if there is a floating window pane overlapping this pane. */
static int
screen_write_pane_is_obscured(struct screen_write_ctx *ctx)
{
struct window_pane *wp = ctx->wp;
if (ctx->wp == NULL)
return (0);
if (ctx->flags & SCREEN_WRITE_CHECKED_IF_OBSCURED) {
if (ctx->flags & SCREEN_WRITE_OBSCURED)
return (1);
return (0);
}
ctx->flags |= SCREEN_WRITE_CHECKED_IF_OBSCURED;
while ((wp = TAILQ_PREV(wp, window_panes, zentry)) != NULL) {
if ((wp->flags & PANE_FLOATING) &&
((wp->yoff >= ctx->wp->yoff &&
wp->yoff <= ctx->wp->yoff + (int)ctx->wp->sy) ||
(wp->yoff + (int)wp->sy >= ctx->wp->yoff &&
wp->yoff + wp->sy <= ctx->wp->yoff + ctx->wp->sy)) &&
((wp->xoff >= ctx->wp->xoff &&
wp->xoff <= ctx->wp->xoff + (int)ctx->wp->sx) ||
(wp->xoff + (int)wp->sx >= ctx->wp->xoff &&
wp->xoff + wp->sx <= ctx->wp->xoff + ctx->wp->sx))) {
ctx->flags |= SCREEN_WRITE_OBSCURED;
return (1);
}
}
return (0);
}
/* Set up context for TTY command. */
static void
screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
int sync)
int is_sync, int check_obscured)
{
struct screen *s = ctx->s;
@@ -188,6 +223,9 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
ttyctx->orlower = s->rlower;
ttyctx->orupper = s->rupper;
if (check_obscured && screen_write_pane_is_obscured(ctx))
ttyctx->flags |= TTY_CTX_PANE_OBSCURED;
memcpy(&ttyctx->defaults, &grid_default_cell, sizeof ttyctx->defaults);
if (ctx->init_ctx_cb != NULL) {
ctx->init_ctx_cb(ctx, ttyctx);
@@ -214,13 +252,14 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
* move the cursor); for other panes, always use it, since the
* cursor will have to move.
*/
if (ctx->wp != NULL) {
if (ctx->wp != ctx->wp->window->active)
ttyctx->num = 1;
else
ttyctx->num = sync;
} else
ttyctx->num = 0x10|sync;
if (ctx->wp != NULL && ctx->wp != ctx->wp->window->active)
ttyctx->flags |= TTY_CTX_SYNC;
else {
if (ctx->wp == NULL)
ttyctx->flags |= TTY_CTX_OVERLAY_SYNC;
if (is_sync)
ttyctx->flags |= TTY_CTX_SYNC;
}
tty_write(tty_cmd_syncstart, ttyctx);
ctx->flags |= SCREEN_WRITE_SYNC;
}
@@ -573,6 +612,7 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
struct window_pane *wp = ctx->wp;
struct tty_ctx ttyctx;
struct grid *gd = src->grid;
struct grid_line *gl, *sgl;
struct grid_cell gc;
u_int xx, yy, cx = s->cx, cy = s->cy;
int yoff = 0;
@@ -585,28 +625,26 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
if (yy >= gd->hsize + gd->sy)
break;
s->cx = cx;
screen_write_initctx(ctx, &ttyctx, 0);
if (wp != NULL) {
screen_write_initctx(ctx, &ttyctx, 0, 0);
if (wp != NULL)
yoff = wp->yoff;
}
r = screen_redraw_get_visible_ranges(wp, px, s->cy + yoff, nx,
NULL);
for (xx = px; xx < px + nx; xx++) {
if (xx >= grid_get_line(gd, yy)->cellsize &&
s->cx >= grid_get_line(ctx->s->grid,
s->cy)->cellsize)
gl = grid_get_line(gd, yy);
sgl = grid_get_line(ctx->s->grid, s->cy);
if (xx >= gl->cellsize && s->cx >= sgl->cellsize)
break;
grid_get_cell(gd, xx, yy, &gc);
if (xx + gc.data.width > px + nx)
break;
grid_view_set_cell(ctx->s->grid, s->cx, s->cy, &gc);
if (wp != NULL) {
if (! screen_redraw_is_visible(r, px))
break;
ttyctx.cell = &gc;
tty_write(tty_cmd_cell, &ttyctx);
ttyctx.ocx++;
}
if (!screen_redraw_is_visible(r, px))
break;
ttyctx.cell = &gc;
ttyctx.flags &= (TTY_CTX_OVERLAY_SYNC|TTY_CTX_SYNC);
tty_write(tty_cmd_cell, &ttyctx);
ttyctx.ocx++;
s->cx++;
}
s->cy++;
@@ -1097,7 +1135,7 @@ screen_write_alignmenttest(struct screen_write_ctx *ctx)
s->rupper = 0;
s->rlower = screen_size_y(s) - 1;
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
screen_write_collect_clear(ctx, 0, screen_size_y(s) - 1);
tty_write(tty_cmd_alignmenttest, &ttyctx);
@@ -1126,9 +1164,8 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
ctx->wp->flags |= PANE_REDRAW;
#endif
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 1);
ttyctx.bg = bg;
ttyctx.obscured = screen_write_pane_obscured(ctx->wp);
grid_view_insert_cells(s->grid, s->cx, s->cy, nx, bg);
@@ -1160,9 +1197,8 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
ctx->wp->flags |= PANE_REDRAW;
#endif
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 1);
ttyctx.bg = bg;
ttyctx.obscured = screen_write_pane_obscured(ctx->wp);
grid_view_delete_cells(s->grid, s->cx, s->cy, nx, bg);
@@ -1194,7 +1230,7 @@ screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
ctx->wp->flags |= PANE_REDRAW;
#endif
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 0);
ttyctx.bg = bg;
grid_view_clear(s->grid, s->cx, s->cy, nx, 1, bg);
@@ -1230,9 +1266,8 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
if (ny == 0)
return;
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
ttyctx.obscured = screen_write_pane_obscured(ctx->wp);
grid_view_insert_lines(gd, s->cy, ny, bg);
@@ -1247,11 +1282,8 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
if (ny == 0)
return;
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
ttyctx.obscured = screen_write_pane_obscured(ctx->wp);
log_debug("%s: obscured=%d for pane %%%u", __func__,
ttyctx.obscured, ctx->wp != NULL ? ctx->wp->id : 0);
if (s->cy < s->rupper || s->cy > s->rlower)
grid_view_insert_lines(gd, s->cy, ny, bg);
@@ -1287,9 +1319,8 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
if (ny == 0)
return;
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
ttyctx.obscured = screen_write_pane_obscured(ctx->wp);
grid_view_delete_lines(gd, s->cy, ny, bg);
@@ -1304,11 +1335,8 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
if (ny == 0)
return;
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
ttyctx.obscured = screen_write_pane_obscured(ctx->wp);
log_debug("%s: obscured=%d for pane %%%u", __func__,
ttyctx.obscured, ctx->wp != NULL ? ctx->wp->id : 0);
if (s->cy < s->rupper || s->cy > s->rlower)
grid_view_delete_lines(gd, s->cy, ny, bg);
@@ -1467,7 +1495,7 @@ screen_write_reverseindex(struct screen_write_ctx *ctx, u_int bg)
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower, bg);
screen_write_collect_flush(ctx, 0, __func__);
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 0);
ttyctx.bg = bg;
tty_write(tty_cmd_reverseindex, &ttyctx);
@@ -1578,9 +1606,8 @@ screen_write_scrolldown(struct screen_write_ctx *ctx, u_int lines, u_int bg)
struct tty_ctx ttyctx;
u_int i;
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
ttyctx.obscured = screen_write_pane_obscured(ctx->wp);
if (lines == 0)
lines = 1;
@@ -1624,7 +1651,7 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg)
ctx->wp->flags |= PANE_REDRAW;
#endif
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
/* Scroll into history if it is enabled and clearing entire screen. */
@@ -1643,7 +1670,7 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg)
screen_write_collect_clear(ctx, s->cy + 1, sy - (s->cy + 1));
screen_write_collect_flush(ctx, 0, __func__);
if (! screen_write_pane_obscured(ctx->wp)) {
if (~ttyctx.flags & TTY_CTX_PANE_OBSCURED) {
tty_write(tty_cmd_clearendofscreen, &ttyctx);
return;
}
@@ -1706,7 +1733,7 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx, u_int bg)
ctx->wp->flags |= PANE_REDRAW;
#endif
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
if (s->cy > 0)
@@ -1719,7 +1746,7 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx, u_int bg)
screen_write_collect_clear(ctx, 0, s->cy);
screen_write_collect_flush(ctx, 0, __func__);
if (! screen_write_pane_obscured(ctx->wp)) {
if (~ttyctx.flags & TTY_CTX_PANE_OBSCURED) {
tty_write(tty_cmd_clearstartofscreen, &ttyctx);
return;
}
@@ -1780,7 +1807,7 @@ screen_write_clearscreen(struct screen_write_ctx *ctx, u_int bg)
ctx->wp->flags |= PANE_REDRAW;
#endif
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
ttyctx.bg = bg;
/* Scroll into history if it is enabled. */
@@ -1793,7 +1820,7 @@ screen_write_clearscreen(struct screen_write_ctx *ctx, u_int bg)
screen_write_collect_clear(ctx, 0, sy);
if (! screen_write_pane_obscured(ctx->wp)) {
if (~ttyctx.flags & TTY_CTX_PANE_OBSCURED) {
tty_write(tty_cmd_clearscreen, &ttyctx);
return;
}
@@ -1841,7 +1868,7 @@ screen_write_fullredraw(struct screen_write_ctx *ctx)
screen_write_collect_flush(ctx, 0, __func__);
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 0);
if (ttyctx.redraw_cb != NULL)
ttyctx.redraw_cb(&ttyctx);
}
@@ -1978,42 +2005,6 @@ screen_write_collect_scroll(struct screen_write_ctx *ctx, u_int bg)
TAILQ_INSERT_TAIL(&ctx->s->write_list[s->rlower].items, ci, entry);
}
/* Return 1 if there is a floating window pane overlapping this pane. */
static int
screen_write_pane_obscured(struct window_pane *base_wp)
{
struct window_pane *wp;
struct window *w;
int found_self = 0;
if (base_wp == NULL)
return(0);
w = base_wp->window;
TAILQ_FOREACH_REVERSE(wp, &w->z_index, window_panes_zindex, zentry) {
if (wp == base_wp) {
found_self = 1;
continue;
}
if (found_self && wp->flags & PANE_FLOATING &&
((wp->yoff >= base_wp->yoff &&
wp->yoff <= base_wp->yoff + (int)base_wp->sy) ||
(wp->yoff + (int)wp->sy >= base_wp->yoff &&
wp->yoff + wp->sy <= base_wp->yoff + base_wp->sy)) &&
((wp->xoff >= base_wp->xoff &&
wp->xoff <= base_wp->xoff + (int)base_wp->sx) ||
(wp->xoff + (int)wp->sx >= base_wp->xoff &&
wp->xoff + wp->sx <= base_wp->xoff + base_wp->sx))) {
log_debug("%s: base %%%u obscured by %%%u "
"(xoff=%u sx=%u vs base xoff=%u sx=%u)", __func__,
base_wp->id, wp->id,
wp->xoff, wp->sx, base_wp->xoff, base_wp->sx);
return (1);
}
}
return (0);
}
/* Flush collected lines. */
static void
screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
@@ -2049,14 +2040,11 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
if (ctx->scrolled > s->rlower - s->rupper + 1)
ctx->scrolled = s->rlower - s->rupper + 1;
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 1);
if (wp != NULL && wp->yoff + wp->sy > wp->window->sy)
ttyctx.orlower -= (wp->yoff + wp->sy - wp->window->sy);
ttyctx.num = ctx->scrolled;
ttyctx.bg = ctx->bg;
ttyctx.obscured = screen_write_pane_obscured(wp);
log_debug("%s: obscured=%d for pane %%%u", __func__,
ttyctx.obscured, wp != NULL ? wp->id : 0);
tty_write(tty_cmd_scrollup, &ttyctx);
if (wp != NULL)
log_debug("%s: after scrollup, PANE_REDRAW=%d for %%%u",
@@ -2143,15 +2131,16 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only,
continue;
screen_write_set_cursor(ctx, wr_start, y);
if (ci->type == CLEAR) {
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 0);
ttyctx.bg = ci->bg;
ttyctx.num = wr_length;
tty_write(tty_cmd_clearcharacter,
&ttyctx);
} else {
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 0);
ttyctx.cell = &ci->gc;
ttyctx.wrapped = ci->wrapped;
if (ci->wrapped)
ttyctx.flags |= TTY_CTX_WRAPPED;
ttyctx.ptr = cl->data + wr_start;
ttyctx.num = wr_length;
tty_write(tty_cmd_cells, &ttyctx);
@@ -2378,7 +2367,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
/* Sanity check cursor position. */
if (s->cx > sx - width || s->cy > sy - 1)
return;
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 0);
/* Handle overwriting of UTF-8 characters. */
gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
@@ -2469,7 +2458,8 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
} else
memcpy(&tmp_gc, gc, sizeof tmp_gc);
ttyctx.cell = &tmp_gc;
ttyctx.num = redraw ? 2 : 0;
if (redraw)
ttyctx.flags |= TTY_CTX_CELL_DRAW_LINE;
for (i=0, vis=0; i < r->used; i++) vis += r->ranges[i].nx;
if (vis < width) {
/* Wide character or tab partly obscured. Write
@@ -2558,7 +2548,7 @@ screen_write_combine(struct screen_write_ctx *ctx, const struct grid_cell *gc)
if (utf8_should_combine(&last.data, ud))
force_wide = 1;
else if (utf8_should_combine(ud, &last.data))
force_wide = 1;
force_wide = 1;
else if (!utf8_has_zwj(&last.data))
return (0);
break;
@@ -2617,9 +2607,10 @@ screen_write_combine(struct screen_write_ctx *ctx, const struct grid_cell *gc)
* and what it is going to do now.
*/
screen_write_set_cursor(ctx, cx - n, cy);
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 0);
ttyctx.cell = &last;
ttyctx.num = force_wide; /* reset cached cursor position */
if (force_wide)
ttyctx.flags |= TTY_CTX_CELL_INVALIDATE;
tty_write(tty_cmd_cell, &ttyctx);
screen_write_set_cursor(ctx, cx, cy);
@@ -2705,7 +2696,7 @@ screen_write_setselection(struct screen_write_ctx *ctx, const char *clip,
{
struct tty_ctx ttyctx;
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 0);
ttyctx.ptr = str;
ttyctx.ptr2 = (void *)clip;
ttyctx.num = len;
@@ -2720,10 +2711,11 @@ screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len,
{
struct tty_ctx ttyctx;
screen_write_initctx(ctx, &ttyctx, 0);
screen_write_initctx(ctx, &ttyctx, 0, 0);
if (allow_invisible_panes)
ttyctx.flags |= TTY_CTX_INVISIBLE_PANES;
ttyctx.ptr = str;
ttyctx.num = len;
ttyctx.allow_invisible_panes = allow_invisible_panes;
tty_write(tty_cmd_rawstring, &ttyctx);
}
@@ -2807,7 +2799,7 @@ screen_write_alternateon(struct screen_write_ctx *ctx, struct grid_cell *gc,
server_redraw_window_borders(wp->window);
}
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 0);
if (ttyctx.redraw_cb != NULL)
ttyctx.redraw_cb(&ttyctx);
}
@@ -2831,7 +2823,7 @@ screen_write_alternateoff(struct screen_write_ctx *ctx, struct grid_cell *gc,
server_redraw_window_borders(wp->window);
}
screen_write_initctx(ctx, &ttyctx, 1);
screen_write_initctx(ctx, &ttyctx, 1, 0);
if (ttyctx.redraw_cb != NULL)
ttyctx.redraw_cb(&ttyctx);
}