1
0
mirror of https://github.com/tmux/tmux.git synced 2025-03-24 06:48:48 +00:00

Instead of setting the popup default colours in the draw callback, set

it up in popup_display and follow the same routine as panes in the draw
and init_ctx callbacks - use the palette if the option value is default.
Allows application-set fg and bg to work in panes again.
This commit is contained in:
nicm 2021-10-25 09:22:17 +00:00
parent 9b4148b12c
commit 0cca695d6e
3 changed files with 48 additions and 39 deletions

74
popup.c
View File

@ -31,11 +31,15 @@ struct popup_data {
struct client *c; struct client *c;
struct cmdq_item *item; struct cmdq_item *item;
int flags; int flags;
enum box_lines lines;
char *title; char *title;
struct grid_cell border_cell;
enum box_lines border_lines;
struct screen s; struct screen s;
struct grid_cell defaults;
struct colour_palette palette; struct colour_palette palette;
struct job *job; struct job *job;
struct input_ctx *ictx; struct input_ctx *ictx;
int status; int status;
@ -119,7 +123,7 @@ popup_set_client_cb(struct tty_ctx *ttyctx, struct client *c)
ttyctx->wsx = c->tty.sx; ttyctx->wsx = c->tty.sx;
ttyctx->wsy = c->tty.sy; ttyctx->wsy = c->tty.sy;
if (pd->lines == BOX_LINES_NONE) { if (pd->border_lines == BOX_LINES_NONE) {
ttyctx->xoff = ttyctx->rxoff = pd->px; ttyctx->xoff = ttyctx->rxoff = pd->px;
ttyctx->yoff = ttyctx->ryoff = pd->py; ttyctx->yoff = ttyctx->ryoff = pd->py;
} else { } else {
@ -135,6 +139,7 @@ popup_init_ctx_cb(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx)
{ {
struct popup_data *pd = ctx->arg; struct popup_data *pd = ctx->arg;
memcpy(&ttyctx->defaults, &pd->defaults, sizeof ttyctx->defaults);
ttyctx->palette = &pd->palette; ttyctx->palette = &pd->palette;
ttyctx->redraw_cb = popup_redraw_cb; ttyctx->redraw_cb = popup_redraw_cb;
ttyctx->set_client_cb = popup_set_client_cb; ttyctx->set_client_cb = popup_set_client_cb;
@ -149,7 +154,7 @@ popup_mode_cb(__unused struct client *c, void *data, u_int *cx, u_int *cy)
if (pd->md != NULL) if (pd->md != NULL)
return (menu_mode_cb(c, pd->md, cx, cy)); return (menu_mode_cb(c, pd->md, cx, cy));
if (pd->lines == BOX_LINES_NONE) { if (pd->border_lines == BOX_LINES_NONE) {
*cx = pd->px + pd->s.cx; *cx = pd->px + pd->s.cx;
*cy = pd->py + pd->s.cy; *cy = pd->py + pd->s.cy;
} else { } else {
@ -213,36 +218,29 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx)
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
u_int i, px = pd->px, py = pd->py; u_int i, px = pd->px, py = pd->py;
struct colour_palette *palette = &pd->palette; struct colour_palette *palette = &pd->palette;
struct grid_cell gc; struct grid_cell defaults;
struct grid_cell bgc;
struct options *o = c->session->curw->window->options;
screen_init(&s, pd->sx, pd->sy, 0); screen_init(&s, pd->sx, pd->sy, 0);
screen_write_start(&ctx, &s); screen_write_start(&ctx, &s);
screen_write_clearscreen(&ctx, 8); screen_write_clearscreen(&ctx, 8);
memcpy(&bgc, &grid_default_cell, sizeof bgc); if (pd->border_lines == BOX_LINES_NONE) {
bgc.attr = 0;
style_apply(&bgc, o, "popup-border-style", NULL);
bgc.attr = 0;
if (pd->lines == BOX_LINES_NONE) {
screen_write_cursormove(&ctx, 0, 0, 0); screen_write_cursormove(&ctx, 0, 0, 0);
screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy);
} else if (pd->sx > 2 && pd->sy > 2) { } else if (pd->sx > 2 && pd->sy > 2) {
screen_write_box(&ctx, pd->sx, pd->sy, pd->lines, &bgc, screen_write_box(&ctx, pd->sx, pd->sy, pd->border_lines,
pd->title); &pd->border_cell, pd->title);
screen_write_cursormove(&ctx, 1, 1, 0); screen_write_cursormove(&ctx, 1, 1, 0);
screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2, screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2,
pd->sy - 2); pd->sy - 2);
} }
screen_write_stop(&ctx); screen_write_stop(&ctx);
memcpy(&gc, &grid_default_cell, sizeof gc); memcpy(&defaults, &pd->defaults, sizeof defaults);
style_apply(&gc, o, "popup-style", NULL); if (COLOUR_DEFAULT(defaults.fg))
gc.attr = 0; defaults.fg = palette->fg;
palette->fg = gc.fg; if (COLOUR_DEFAULT(defaults.bg))
palette->bg = gc.bg; defaults.bg = palette->bg;
if (pd->md != NULL) { if (pd->md != NULL) {
c->overlay_check = menu_check_cb; c->overlay_check = menu_check_cb;
@ -251,8 +249,10 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx)
c->overlay_check = NULL; c->overlay_check = NULL;
c->overlay_data = NULL; c->overlay_data = NULL;
} }
for (i = 0; i < pd->sy; i++) for (i = 0; i < pd->sy; i++) {
tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &gc, palette); tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &defaults,
palette);
}
if (pd->md != NULL) { if (pd->md != NULL) {
c->overlay_check = NULL; c->overlay_check = NULL;
c->overlay_data = NULL; c->overlay_data = NULL;
@ -323,7 +323,7 @@ popup_resize_cb(__unused struct client *c, void *data)
pd->px = pd->ppx; pd->px = pd->ppx;
/* Avoid zero size screens. */ /* Avoid zero size screens. */
if (pd->lines == BOX_LINES_NONE) { if (pd->border_lines == BOX_LINES_NONE) {
screen_resize(&pd->s, pd->sx, pd->sy, 0); screen_resize(&pd->s, pd->sx, pd->sy, 0);
if (pd->job != NULL) if (pd->job != NULL)
job_resize(pd->job, pd->sx, pd->sy ); job_resize(pd->job, pd->sx, pd->sy );
@ -449,7 +449,7 @@ popup_handle_drag(struct client *c, struct popup_data *pd,
pd->ppy = py; pd->ppy = py;
server_redraw_client(c); server_redraw_client(c);
} else if (pd->dragging == SIZE) { } else if (pd->dragging == SIZE) {
if (pd->lines == BOX_LINES_NONE) { if (pd->border_lines == BOX_LINES_NONE) {
if (m->x < pd->px + 1) if (m->x < pd->px + 1)
return; return;
if (m->y < pd->py + 1) if (m->y < pd->py + 1)
@ -465,7 +465,7 @@ popup_handle_drag(struct client *c, struct popup_data *pd,
pd->psx = pd->sx; pd->psx = pd->sx;
pd->psy = pd->sy; pd->psy = pd->sy;
if (pd->lines == BOX_LINES_NONE) { if (pd->border_lines == BOX_LINES_NONE) {
screen_resize(&pd->s, pd->sx, pd->sy, 0); screen_resize(&pd->s, pd->sx, pd->sy, 0);
if (pd->job != NULL) if (pd->job != NULL)
job_resize(pd->job, pd->sx, pd->sy); job_resize(pd->job, pd->sx, pd->sy);
@ -513,7 +513,7 @@ popup_key_cb(struct client *c, void *data, struct key_event *event)
goto menu; goto menu;
return (0); return (0);
} }
if (pd->lines != BOX_LINES_NONE) { if (pd->border_lines != BOX_LINES_NONE) {
if (m->x == pd->px) if (m->x == pd->px)
border = LEFT; border = LEFT;
else if (m->x == pd->px + pd->sx - 1) else if (m->x == pd->px + pd->sx - 1)
@ -547,7 +547,7 @@ popup_key_cb(struct client *c, void *data, struct key_event *event)
if (pd->job != NULL) { if (pd->job != NULL) {
if (KEYC_IS_MOUSE(event->key)) { if (KEYC_IS_MOUSE(event->key)) {
/* Must be inside, checked already. */ /* Must be inside, checked already. */
if (pd->lines == BOX_LINES_NONE) { if (pd->border_lines == BOX_LINES_NONE) {
px = m->x - pd->px; px = m->x - pd->px;
py = m->y - pd->py; py = m->y - pd->py;
} else { } else {
@ -642,13 +642,13 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px,
u_int jx, jy; u_int jx, jy;
struct options *o; struct options *o;
if (lines == BOX_LINES_DEFAULT) { if (s != NULL)
if (s != NULL) o = s->curw->window->options;
o = s->curw->window->options; else
else o = c->session->curw->window->options;
o = c->session->curw->window->options;
if (lines == BOX_LINES_DEFAULT)
lines = options_get_number(o, "popup-border-lines"); lines = options_get_number(o, "popup-border-lines");
}
if (lines == BOX_LINES_NONE) { if (lines == BOX_LINES_NONE) {
if (sx < 1 || sy < 1) if (sx < 1 || sy < 1)
return (-1); return (-1);
@ -666,7 +666,6 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px,
pd = xcalloc(1, sizeof *pd); pd = xcalloc(1, sizeof *pd);
pd->item = item; pd->item = item;
pd->flags = flags; pd->flags = flags;
pd->lines = lines;
pd->title = xstrdup(title); pd->title = xstrdup(title);
pd->c = c; pd->c = c;
@ -676,10 +675,19 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px,
pd->arg = arg; pd->arg = arg;
pd->status = 128 + SIGHUP; pd->status = 128 + SIGHUP;
pd->border_lines = lines;
memcpy(&pd->border_cell, &grid_default_cell, sizeof pd->border_cell);
style_apply(&pd->border_cell, o, "popup-border-style", NULL);
pd->border_cell.attr = 0;
screen_init(&pd->s, sx - 2, sy - 2, 0); screen_init(&pd->s, sx - 2, sy - 2, 0);
colour_palette_init(&pd->palette); colour_palette_init(&pd->palette);
colour_palette_from_option(&pd->palette, global_w_options); colour_palette_from_option(&pd->palette, global_w_options);
memcpy(&pd->defaults, &grid_default_cell, sizeof pd->defaults);
style_apply(&pd->defaults, o, "popup-style", NULL);
pd->defaults.attr = 0;
pd->px = px; pd->px = px;
pd->py = py; pd->py = py;
pd->sx = sx; pd->sx = sx;

View File

@ -184,8 +184,10 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
if (ctx->init_ctx_cb != NULL) { if (ctx->init_ctx_cb != NULL) {
ctx->init_ctx_cb(ctx, ttyctx); ctx->init_ctx_cb(ctx, ttyctx);
if (ttyctx->palette != NULL) { if (ttyctx->palette != NULL) {
ttyctx->defaults.fg = ttyctx->palette->fg; if (COLOUR_DEFAULT(ttyctx->defaults.fg))
ttyctx->defaults.bg = ttyctx->palette->bg; ttyctx->defaults.fg = ttyctx->palette->fg;
if (COLOUR_DEFAULT(ttyctx->defaults.bg))
ttyctx->defaults.bg = ttyctx->palette->bg;
} }
} else { } else {
ttyctx->redraw_cb = screen_write_redraw_cb; ttyctx->redraw_cb = screen_write_redraw_cb;

7
tty.c
View File

@ -1972,10 +1972,9 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
for (i = 0; i < OVERLAY_MAX_RANGES; i++) for (i = 0; i < OVERLAY_MAX_RANGES; i++)
vis += r.nx[i]; vis += r.nx[i];
if (vis < gcp->data.width) { if (vis < gcp->data.width) {
tty_draw_line(tty, s, s->cx, s->cy, tty_draw_line(tty, s, s->cx, s->cy, gcp->data.width,
gcp->data.width, px, py, &ctx->defaults, px, py, &ctx->defaults, ctx->palette);
ctx->palette); return;
return;
} }
} }