summaryrefslogtreecommitdiffstats
path: root/popup.c
diff options
context:
space:
mode:
authornicm <nicm>2021-10-14 13:19:01 +0000
committernicm <nicm>2021-10-14 13:19:01 +0000
commitadd20637f256c0118d3c687d5d1446612d14389a (patch)
treecf546997fdd9cb96e0ace7dd385eb127d67aa448 /popup.c
parentd0ab1a837a0ab3e26fe7195f14672f6feb43c4c4 (diff)
Add popup-border-lines option to set popup line style, from Alexis
Hildebrandt, GitHub issue 2930.
Diffstat (limited to 'popup.c')
-rw-r--r--popup.c44
1 files changed, 28 insertions, 16 deletions
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);