From 759efe1b3327a7244c03ecc7b90e0e3c49712d06 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 11 Oct 2021 10:55:30 +0000 Subject: Add -e flag to set environment for popup, from Alexis Hildebrandt in GitHub issue 2924. --- popup.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index d4fc3833..635559fa 100644 --- a/popup.c +++ b/popup.c @@ -590,8 +590,9 @@ popup_job_complete_cb(struct job *job) int popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, - u_int sy, const char *shellcmd, int argc, char **argv, const char *cwd, - struct client *c, struct session *s, popup_close_cb cb, void *arg) + u_int sy, struct environ *env, const char *shellcmd, int argc, char **argv, + const char *cwd, struct client *c, struct session *s, popup_close_cb cb, + void *arg) { struct popup_data *pd; u_int jx, jy; @@ -635,7 +636,7 @@ popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, pd->psx = sx; pd->psy = sy; - pd->job = job_run(shellcmd, argc, argv, s, cwd, + pd->job = job_run(shellcmd, argc, argv, env, s, cwd, popup_job_update_cb, popup_job_complete_cb, NULL, pd, JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE, jx, jy); pd->ictx = input_init(NULL, job_get_event(pd->job), &pd->palette); @@ -725,7 +726,7 @@ popup_editor(struct client *c, const char *buf, size_t len, xasprintf(&cmd, "%s %s", editor, path); if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, NULL, px, py, sx, sy, - cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) { + NULL, cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) { popup_editor_free(pe); free(cmd); return (-1); -- cgit From b8581ec80e5339be5e2c08cfec70a77f21ba06b2 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 11 Oct 2021 13:27:50 +0000 Subject: Make positions hidden by overlays range-based rather than character-based, from Anindya Mukherjee. --- popup.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index 635559fa..106e4ee5 100644 --- a/popup.c +++ b/popup.c @@ -157,18 +157,49 @@ popup_mode_cb(__unused struct client *c, void *data, u_int *cx, u_int *cy) return (&pd->s); } -static int -popup_check_cb(struct client *c, void *data, u_int px, u_int py) +/* Return parts of the input range which are not obstructed by the popup. */ +static void +popup_check_cb(struct client* c, void *data, u_int px, u_int py, u_int nx, + struct overlay_ranges *r) { struct popup_data *pd = data; + struct overlay_ranges or[2]; + u_int i, j, k = 0; - if (pd->md != NULL && menu_check_cb(c, pd->md, px, py) == 0) - return (0); - if (px < pd->px || px > pd->px + pd->sx - 1) - return (1); - if (py < pd->py || py > pd->py + pd->sy - 1) - return (1); - return (0); + if (pd->md != NULL) { + /* Check each returned range for the menu against the popup. */ + menu_check_cb(c, pd->md, px, py, nx, r); + for (i = 0; i < 2; i++) { + server_client_overlay_range(pd->px, pd->py, pd->sx, + pd->sy, r->px[i], py, r->nx[i], &or[i]); + } + + /* + * or has up to OVERLAY_MAX_RANGES non-overlapping ranges, + * ordered from left to right. Collect them in the output. + */ + for (i = 0; i < 2; i++) { + /* Each or[i] only has 2 ranges. */ + for (j = 0; j < 2; j++) { + if (or[i].nx[j] > 0) { + r->px[k] = or[i].px[j]; + r->nx[k] = or[i].nx[j]; + k++; + } + } + } + + /* Zero remaining ranges if any. */ + for (i = k; i < OVERLAY_MAX_RANGES; i++) { + r->px[i] = 0; + r->nx[i] = 0; + } + + return; + } + + server_client_overlay_range(pd->px, pd->py, pd->sx, pd->sy, px, py, nx, + r); } static void -- cgit From 837ca176d1874273f3de615c75b506e1b1787a1b Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 13 Oct 2021 09:28:36 +0000 Subject: Add popup-style and popup-border-style options, from Alexis Hildebrandt in GitHub issue 2927. --- popup.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index 106e4ee5..5eea46ef 100644 --- a/popup.c +++ b/popup.c @@ -212,16 +212,22 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) u_int i, px = pd->px, py = pd->py; struct colour_palette *palette = &pd->palette; struct grid_cell gc; + struct grid_cell bgc; + struct options *o = c->session->curw->window->options; screen_init(&s, pd->sx, pd->sy, 0); screen_write_start(&ctx, &s); screen_write_clearscreen(&ctx, 8); + memcpy(&bgc, &grid_default_cell, sizeof bgc); + style_apply(&bgc, o, "popup-border-style", NULL); + bgc.attr = 0; + if (pd->flags & POPUP_NOBORDER) { screen_write_cursormove(&ctx, 0, 0, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy); } else if (pd->sx > 2 && pd->sy > 2) { - screen_write_box(&ctx, pd->sx, pd->sy); + screen_write_box(&ctx, pd->sx, pd->sy, &bgc); screen_write_cursormove(&ctx, 1, 1, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2, pd->sy - 2); @@ -229,8 +235,10 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) screen_write_stop(&ctx); memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = pd->palette.fg; - gc.bg = pd->palette.bg; + style_apply(&gc, o, "popup-style", NULL); + gc.attr = 0; + palette->fg = gc.fg; + palette->bg = gc.bg; if (pd->md != NULL) { c->overlay_check = menu_check_cb; -- cgit From add20637f256c0118d3c687d5d1446612d14389a Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 14 Oct 2021 13:19:01 +0000 Subject: Add popup-border-lines option to set popup line style, from Alexis Hildebrandt, GitHub issue 2930. --- popup.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index 5eea46ef..328deba6 100644 --- a/popup.c +++ b/popup.c @@ -31,6 +31,7 @@ struct popup_data { struct client *c; struct cmdq_item *item; int flags; + enum box_lines lines; struct screen s; struct colour_palette palette; @@ -117,7 +118,7 @@ popup_set_client_cb(struct tty_ctx *ttyctx, struct client *c) ttyctx->wsx = c->tty.sx; ttyctx->wsy = c->tty.sy; - if (pd->flags & POPUP_NOBORDER) { + if (pd->lines == BOX_LINES_NONE) { ttyctx->xoff = ttyctx->rxoff = pd->px; ttyctx->yoff = ttyctx->ryoff = pd->py; } else { @@ -147,7 +148,7 @@ popup_mode_cb(__unused struct client *c, void *data, u_int *cx, u_int *cy) if (pd->md != NULL) return (menu_mode_cb(c, pd->md, cx, cy)); - if (pd->flags & POPUP_NOBORDER) { + if (pd->lines == BOX_LINES_NONE) { *cx = pd->px + pd->s.cx; *cy = pd->py + pd->s.cy; } else { @@ -220,14 +221,15 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) screen_write_clearscreen(&ctx, 8); memcpy(&bgc, &grid_default_cell, sizeof bgc); + bgc.attr = 0; style_apply(&bgc, o, "popup-border-style", NULL); bgc.attr = 0; - if (pd->flags & POPUP_NOBORDER) { + if (pd->lines == BOX_LINES_NONE) { screen_write_cursormove(&ctx, 0, 0, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy); } else if (pd->sx > 2 && pd->sy > 2) { - screen_write_box(&ctx, pd->sx, pd->sy, &bgc); + screen_write_box(&ctx, pd->sx, pd->sy, pd->lines, &bgc); screen_write_cursormove(&ctx, 1, 1, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2, pd->sy - 2); @@ -318,7 +320,7 @@ popup_resize_cb(__unused struct client *c, void *data) pd->px = pd->ppx; /* Avoid zero size screens. */ - if (pd->flags & POPUP_NOBORDER) { + if (pd->lines == BOX_LINES_NONE) { screen_resize(&pd->s, pd->sx, pd->sy, 0); if (pd->job != NULL) job_resize(pd->job, pd->sx, pd->sy ); @@ -444,7 +446,7 @@ popup_handle_drag(struct client *c, struct popup_data *pd, pd->ppy = py; server_redraw_client(c); } else if (pd->dragging == SIZE) { - if (pd->flags & POPUP_NOBORDER) { + if (pd->lines == BOX_LINES_NONE) { if (m->x < pd->px + 1) return; if (m->y < pd->py + 1) @@ -460,7 +462,7 @@ popup_handle_drag(struct client *c, struct popup_data *pd, pd->psx = pd->sx; pd->psy = pd->sy; - if (pd->flags & POPUP_NOBORDER) { + if (pd->lines == BOX_LINES_NONE) { screen_resize(&pd->s, pd->sx, pd->sy, 0); if (pd->job != NULL) job_resize(pd->job, pd->sx, pd->sy); @@ -508,7 +510,7 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) goto menu; return (0); } - if (~pd->flags & POPUP_NOBORDER) { + if (pd->lines != BOX_LINES_NONE) { if (m->x == pd->px) border = LEFT; else if (m->x == pd->px + pd->sx - 1) @@ -542,7 +544,7 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) if (pd->job != NULL) { if (KEYC_IS_MOUSE(event->key)) { /* Must be inside, checked already. */ - if (pd->flags & POPUP_NOBORDER) { + if (pd->lines == BOX_LINES_NONE) { px = m->x - pd->px; py = m->y - pd->py; } else { @@ -628,15 +630,23 @@ popup_job_complete_cb(struct job *job) } int -popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, - u_int sy, struct environ *env, const char *shellcmd, int argc, char **argv, - const char *cwd, struct client *c, struct session *s, popup_close_cb cb, - void *arg) +popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, + u_int py, u_int sx, u_int sy, struct environ *env, const char *shellcmd, + int argc, char **argv, const char *cwd, struct client *c, struct session *s, + popup_close_cb cb, void *arg) { struct popup_data *pd; u_int jx, jy; + struct options *o; - if (flags & POPUP_NOBORDER) { + if (lines == BOX_LINES_DEFAULT) { + if (s != NULL) + o = s->curw->window->options; + else + o = c->session->curw->window->options; + lines = options_get_number(o, "popup-border-lines"); + } + if (lines == BOX_LINES_NONE) { if (sx < 1 || sy < 1) return (-1); jx = sx; @@ -653,6 +663,7 @@ popup_display(int flags, struct cmdq_item *item, u_int px, u_int py, u_int sx, pd = xcalloc(1, sizeof *pd); pd->item = item; pd->flags = flags; + pd->lines = lines; pd->c = c; pd->c->references++; @@ -764,8 +775,9 @@ popup_editor(struct client *c, const char *buf, size_t len, py = (c->tty.sy / 2) - (sy / 2); xasprintf(&cmd, "%s %s", editor, path); - if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, NULL, px, py, sx, sy, - NULL, cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) { + if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, BOX_LINES_DEFAULT, + NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, c, NULL, + popup_editor_close_cb, pe) != 0) { popup_editor_free(pe); free(cmd); return (-1); -- cgit From acba07629ebf2dc2f0c316f110493e720b30757c Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 20 Oct 2021 09:52:27 +0000 Subject: Remove a TODO comment. --- popup.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index 328deba6..549c26e1 100644 --- a/popup.c +++ b/popup.c @@ -32,6 +32,7 @@ struct popup_data { struct cmdq_item *item; int flags; enum box_lines lines; + char *title; struct screen s; struct colour_palette palette; @@ -229,7 +230,8 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) screen_write_cursormove(&ctx, 0, 0, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy); } 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->lines, &bgc, + pd->title); screen_write_cursormove(&ctx, 1, 1, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2, pd->sy - 2); @@ -287,6 +289,7 @@ popup_free_cb(struct client *c, void *data) screen_free(&pd->s); colour_palette_free(&pd->palette); + free(pd->title); free(pd); } @@ -632,8 +635,8 @@ popup_job_complete_cb(struct job *job) int popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, u_int py, u_int sx, u_int sy, struct environ *env, const char *shellcmd, - int argc, char **argv, const char *cwd, struct client *c, struct session *s, - popup_close_cb cb, void *arg) + int argc, char **argv, const char *cwd, const char *title, struct client *c, + struct session *s, popup_close_cb cb, void *arg) { struct popup_data *pd; u_int jx, jy; @@ -664,6 +667,7 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, pd->item = item; pd->flags = flags; pd->lines = lines; + pd->title = xstrdup(title); pd->c = c; pd->c->references++; @@ -776,7 +780,7 @@ popup_editor(struct client *c, const char *buf, size_t len, xasprintf(&cmd, "%s %s", editor, path); if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, BOX_LINES_DEFAULT, - NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, c, NULL, + NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, NULL, c, NULL, popup_editor_close_cb, pe) != 0) { popup_editor_free(pe); free(cmd); -- cgit From 0cca695d6e75426e295e03668a4ed35ee62afe7c Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 25 Oct 2021 09:22:17 +0000 Subject: 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. --- popup.c | 74 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index 549c26e1..dd83d608 100644 --- a/popup.c +++ b/popup.c @@ -31,11 +31,15 @@ struct popup_data { struct client *c; struct cmdq_item *item; int flags; - enum box_lines lines; char *title; + struct grid_cell border_cell; + enum box_lines border_lines; + struct screen s; + struct grid_cell defaults; struct colour_palette palette; + struct job *job; struct input_ctx *ictx; int status; @@ -119,7 +123,7 @@ popup_set_client_cb(struct tty_ctx *ttyctx, struct client *c) ttyctx->wsx = c->tty.sx; 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->yoff = ttyctx->ryoff = pd->py; } else { @@ -135,6 +139,7 @@ popup_init_ctx_cb(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx) { struct popup_data *pd = ctx->arg; + memcpy(&ttyctx->defaults, &pd->defaults, sizeof ttyctx->defaults); ttyctx->palette = &pd->palette; ttyctx->redraw_cb = popup_redraw_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) 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; *cy = pd->py + pd->s.cy; } else { @@ -213,36 +218,29 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) struct screen_write_ctx ctx; u_int i, px = pd->px, py = pd->py; struct colour_palette *palette = &pd->palette; - struct grid_cell gc; - struct grid_cell bgc; - struct options *o = c->session->curw->window->options; + struct grid_cell defaults; screen_init(&s, pd->sx, pd->sy, 0); screen_write_start(&ctx, &s); screen_write_clearscreen(&ctx, 8); - memcpy(&bgc, &grid_default_cell, sizeof bgc); - bgc.attr = 0; - style_apply(&bgc, o, "popup-border-style", NULL); - bgc.attr = 0; - - if (pd->lines == BOX_LINES_NONE) { + if (pd->border_lines == BOX_LINES_NONE) { screen_write_cursormove(&ctx, 0, 0, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx, pd->sy); } else if (pd->sx > 2 && pd->sy > 2) { - screen_write_box(&ctx, pd->sx, pd->sy, pd->lines, &bgc, - pd->title); + screen_write_box(&ctx, pd->sx, pd->sy, pd->border_lines, + &pd->border_cell, pd->title); screen_write_cursormove(&ctx, 1, 1, 0); screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2, pd->sy - 2); } screen_write_stop(&ctx); - memcpy(&gc, &grid_default_cell, sizeof gc); - style_apply(&gc, o, "popup-style", NULL); - gc.attr = 0; - palette->fg = gc.fg; - palette->bg = gc.bg; + memcpy(&defaults, &pd->defaults, sizeof defaults); + if (COLOUR_DEFAULT(defaults.fg)) + defaults.fg = palette->fg; + if (COLOUR_DEFAULT(defaults.bg)) + defaults.bg = palette->bg; if (pd->md != NULL) { 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_data = NULL; } - for (i = 0; i < pd->sy; i++) - tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &gc, palette); + for (i = 0; i < pd->sy; i++) { + tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &defaults, + palette); + } if (pd->md != NULL) { c->overlay_check = NULL; c->overlay_data = NULL; @@ -323,7 +323,7 @@ popup_resize_cb(__unused struct client *c, void *data) pd->px = pd->ppx; /* 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); if (pd->job != NULL) 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; server_redraw_client(c); } else if (pd->dragging == SIZE) { - if (pd->lines == BOX_LINES_NONE) { + if (pd->border_lines == BOX_LINES_NONE) { if (m->x < pd->px + 1) return; 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->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); if (pd->job != NULL) 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; return (0); } - if (pd->lines != BOX_LINES_NONE) { + if (pd->border_lines != BOX_LINES_NONE) { if (m->x == pd->px) border = LEFT; 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 (KEYC_IS_MOUSE(event->key)) { /* Must be inside, checked already. */ - if (pd->lines == BOX_LINES_NONE) { + if (pd->border_lines == BOX_LINES_NONE) { px = m->x - pd->px; py = m->y - pd->py; } else { @@ -642,13 +642,13 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, u_int jx, jy; struct options *o; - if (lines == BOX_LINES_DEFAULT) { - if (s != NULL) - o = s->curw->window->options; - else - o = c->session->curw->window->options; + if (s != NULL) + o = s->curw->window->options; + else + o = c->session->curw->window->options; + + if (lines == BOX_LINES_DEFAULT) lines = options_get_number(o, "popup-border-lines"); - } if (lines == BOX_LINES_NONE) { if (sx < 1 || sy < 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->item = item; pd->flags = flags; - pd->lines = lines; pd->title = xstrdup(title); 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->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); colour_palette_init(&pd->palette); 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->py = py; pd->sx = sx; -- cgit From ef46eb91a5e0b6e2b023544f45dbc98c8fe1377f Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 25 Oct 2021 09:38:36 +0000 Subject: Add -s and -S to display-popup to set popup and border style, from Alexis Hildebrandt in GitHub issue 2931. --- popup.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index dd83d608..ed6a6bb9 100644 --- a/popup.c +++ b/popup.c @@ -237,9 +237,9 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) screen_write_stop(&ctx); memcpy(&defaults, &pd->defaults, sizeof defaults); - if (COLOUR_DEFAULT(defaults.fg)) + if (defaults.fg == 8) defaults.fg = palette->fg; - if (COLOUR_DEFAULT(defaults.bg)) + if (defaults.bg == 8) defaults.bg = palette->bg; if (pd->md != NULL) { @@ -636,11 +636,13 @@ int popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, u_int py, u_int sx, u_int sy, struct environ *env, const char *shellcmd, int argc, char **argv, const char *cwd, const char *title, struct client *c, - struct session *s, popup_close_cb cb, void *arg) + struct session *s, const char* style, const char* border_style, + popup_close_cb cb, void *arg) { struct popup_data *pd; u_int jx, jy; struct options *o; + struct style sytmp; if (s != NULL) o = s->curw->window->options; @@ -678,6 +680,13 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, 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); + if (border_style != NULL) { + style_set(&sytmp, &grid_default_cell); + if (style_parse(&sytmp, &pd->border_cell, border_style) == 0) { + pd->border_cell.fg = sytmp.gc.fg; + pd->border_cell.bg = sytmp.gc.bg; + } + } pd->border_cell.attr = 0; screen_init(&pd->s, sx - 2, sy - 2, 0); @@ -686,6 +695,13 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, memcpy(&pd->defaults, &grid_default_cell, sizeof pd->defaults); style_apply(&pd->defaults, o, "popup-style", NULL); + if (style != NULL) { + style_set(&sytmp, &grid_default_cell); + if (style_parse(&sytmp, &pd->defaults, style) == 0) { + pd->defaults.fg = sytmp.gc.fg; + pd->defaults.bg = sytmp.gc.bg; + } + } pd->defaults.attr = 0; pd->px = px; @@ -789,7 +805,7 @@ popup_editor(struct client *c, const char *buf, size_t len, xasprintf(&cmd, "%s %s", editor, path); if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, BOX_LINES_DEFAULT, NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, NULL, c, NULL, - popup_editor_close_cb, pe) != 0) { + NULL, NULL, popup_editor_close_cb, pe) != 0) { popup_editor_free(pe); free(cmd); return (-1); -- cgit From a6b361e775e0bf6301284391e75dd9af7af340da Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 17 Jan 2022 10:40:03 +0000 Subject: Do not try to strdup NULL, from seL4 at disroot dot org in GitHub issue 3038. --- popup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index ed6a6bb9..bebc7cc6 100644 --- a/popup.c +++ b/popup.c @@ -668,7 +668,8 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, pd = xcalloc(1, sizeof *pd); pd->item = item; pd->flags = flags; - pd->title = xstrdup(title); + if (title != NULL) + pd->title = xstrdup(title); pd->c = c; pd->c->references++; -- cgit From 97900d0442252aa4b76f89745718038f39717ecd Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 1 Feb 2022 18:12:20 +0000 Subject: A menu must be shown on a client, so always give the client when adding the items. Also fix mode menus. --- popup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index bebc7cc6..4b4c58ca 100644 --- a/popup.c +++ b/popup.c @@ -566,10 +566,10 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) menu: pd->menu = menu_create(""); if (pd->flags & POPUP_INTERNAL) { - menu_add_items(pd->menu, popup_internal_menu_items, NULL, NULL, + menu_add_items(pd->menu, popup_internal_menu_items, NULL, c, NULL); } else - menu_add_items(pd->menu, popup_menu_items, NULL, NULL, NULL); + menu_add_items(pd->menu, popup_menu_items, NULL, c, NULL); if (m->x >= (pd->menu->width + 4) / 2) x = m->x - (pd->menu->width + 4) / 2; else -- cgit From 0027ee13a089efe7d1db1a4cfedb9b801635ded8 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 16 Feb 2022 18:55:05 +0000 Subject: Support more mouse buttons when the terminal sends them, GitHub issue 3055. --- popup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index 4b4c58ca..a3b33dce 100644 --- a/popup.c +++ b/popup.c @@ -509,7 +509,7 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) m->x > pd->px + pd->sx - 1 || m->y < pd->py || m->y > pd->py + pd->sy - 1) { - if (MOUSE_BUTTONS(m->b) == 2) + if (MOUSE_BUTTONS(m->b) == MOUSE_BUTTON_3) goto menu; return (0); } @@ -524,16 +524,16 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) border = BOTTOM; } if ((m->b & MOUSE_MASK_MODIFIERS) == 0 && - MOUSE_BUTTONS(m->b) == 2 && + MOUSE_BUTTONS(m->b) == MOUSE_BUTTON_3 && (border == LEFT || border == TOP)) goto menu; if (((m->b & MOUSE_MASK_MODIFIERS) == MOUSE_MASK_META) || border != NONE) { if (!MOUSE_DRAG(m->b)) goto out; - if (MOUSE_BUTTONS(m->lb) == 0) + if (MOUSE_BUTTONS(m->lb) == MOUSE_BUTTON_1) pd->dragging = MOVE; - else if (MOUSE_BUTTONS(m->lb) == 2) + else if (MOUSE_BUTTONS(m->lb) == MOUSE_BUTTON_3) pd->dragging = SIZE; pd->dx = m->lx - pd->px; pd->dy = m->ly - pd->py; -- cgit From a9b880921dce2836611873a4ec85e9425dc08b40 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 22 Feb 2022 11:01:57 +0000 Subject: Use correct size for screen when popup is created without borders. --- popup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'popup.c') diff --git a/popup.c b/popup.c index a3b33dce..12f31c40 100644 --- a/popup.c +++ b/popup.c @@ -690,7 +690,7 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, } pd->border_cell.attr = 0; - screen_init(&pd->s, sx - 2, sy - 2, 0); + screen_init(&pd->s, jx, jy, 0); colour_palette_init(&pd->palette); colour_palette_from_option(&pd->palette, global_w_options); -- cgit