-/* $OpenBSD: cmd-display-menu.c,v 1.26 2021/07/21 08:09:43 nicm Exp $ */
+/* $OpenBSD: cmd-display-menu.c,v 1.27 2021/08/13 17:03:29 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
.name = "display-popup",
.alias = "popup",
- .args = { "Cc:d:Eh:t:w:x:y:", 0, -1 },
- .usage = "[-CE] [-c target-client] [-d start-directory] [-h height] "
+ .args = { "BCc:d:Eh:t:w:x:y:", 0, -1 },
+ .usage = "[-BCE] [-c target-client] [-d start-directory] [-h height] "
CMD_TARGET_PANE_USAGE " [-w width] "
"[-x position] [-y position] [command]",
flags |= POPUP_CLOSEEXITZERO;
else if (args_has(args, 'E'))
flags |= POPUP_CLOSEEXIT;
+ if (args_has(args, 'B'))
+ flags |= POPUP_NOBORDER;
if (popup_display(flags, item, px, py, w, h, shellcmd, argc, argv, cwd,
tc, s, NULL, NULL) != 0)
return (CMD_RETURN_NORMAL);
-/* $OpenBSD: popup.c,v 1.25 2021/08/11 20:49:55 nicm Exp $ */
+/* $OpenBSD: popup.c,v 1.26 2021/08/13 17:03:29 nicm Exp $ */
/*
* Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com>
ttyctx->wsx = c->tty.sx;
ttyctx->wsy = c->tty.sy;
- ttyctx->xoff = ttyctx->rxoff = pd->px + 1;
- ttyctx->yoff = ttyctx->ryoff = pd->py + 1;
+ if (pd->flags & POPUP_NOBORDER) {
+ ttyctx->xoff = ttyctx->rxoff = pd->px;
+ ttyctx->yoff = ttyctx->ryoff = pd->py;
+ } else {
+ ttyctx->xoff = ttyctx->rxoff = pd->px + 1;
+ ttyctx->yoff = ttyctx->ryoff = pd->py + 1;
+ }
return (1);
}
{
struct popup_data *pd = c->overlay_data;
- *cx = pd->px + 1 + pd->s.cx;
- *cy = pd->py + 1 + pd->s.cy;
+ if (pd->flags & POPUP_NOBORDER) {
+ *cx = pd->px + pd->s.cx;
+ *cy = pd->py + pd->s.cy;
+ } else {
+ *cx = pd->px + 1 + pd->s.cx;
+ *cy = pd->py + 1 + pd->s.cy;
+ }
return (&pd->s);
}
screen_write_start(&ctx, &s);
screen_write_clearscreen(&ctx, 8);
- /* Skip drawing popup if the terminal is too small. */
- if (pd->sx > 2 && pd->sy > 2) {
+ 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_cursormove(&ctx, 1, 1, 0);
screen_write_fast_copy(&ctx, &pd->s, 0, 0, pd->sx - 2,
pd->px = pd->ppx;
/* Avoid zero size screens. */
- if (pd->sx > 2 && pd->sy > 2) {
+ if (pd->flags & POPUP_NOBORDER) {
+ screen_resize(&pd->s, pd->sx, pd->sy, 0);
+ if (pd->job != NULL)
+ job_resize(pd->job, pd->sx, pd->sy );
+ } else if (pd->sx > 2 && pd->sy > 2) {
screen_resize(&pd->s, pd->sx - 2, pd->sy - 2, 0);
if (pd->job != NULL)
job_resize(pd->job, pd->sx - 2, pd->sy - 2);
pd->ppy = py;
server_redraw_client(c);
} else if (pd->dragging == SIZE) {
- if (m->x < pd->px + 3)
- return;
- if (m->y < pd->py + 3)
- return;
+ if (pd->flags & POPUP_NOBORDER) {
+ if (m->x < pd->px + 1)
+ return;
+ if (m->y < pd->py + 1)
+ return;
+ } else {
+ if (m->x < pd->px + 3)
+ return;
+ if (m->y < pd->py + 3)
+ return;
+ }
pd->sx = m->x - pd->px;
pd->sy = m->y - pd->py;
pd->psx = pd->sx;
pd->psy = pd->sy;
- screen_resize(&pd->s, pd->sx - 2, pd->sy - 2, 0);
- if (pd->job != NULL)
- job_resize(pd->job, pd->sx - 2, pd->sy - 2);
+ if (pd->flags & POPUP_NOBORDER) {
+ screen_resize(&pd->s, pd->sx, pd->sy, 0);
+ if (pd->job != NULL)
+ job_resize(pd->job, pd->sx, pd->sy);
+ } else {
+ screen_resize(&pd->s, pd->sx - 2, pd->sy - 2, 0);
+ if (pd->job != NULL)
+ job_resize(pd->job, pd->sx - 2, pd->sy - 2);
+ }
server_redraw_client(c);
}
}
struct mouse_event *m = &event->m;
const char *buf;
size_t len;
+ u_int px, py;
if (KEYC_IS_MOUSE(event->key)) {
if (pd->dragging != OFF) {
return (0);
}
if ((m->b & MOUSE_MASK_META) ||
- m->x == pd->px ||
+ ((~pd->flags & POPUP_NOBORDER) &&
+ (m->x == pd->px ||
m->x == pd->px + pd->sx - 1 ||
m->y == pd->py ||
- m->y == pd->py + pd->sy - 1) {
+ m->y == pd->py + pd->sy - 1))) {
if (!MOUSE_DRAG(m->b))
goto out;
if (MOUSE_BUTTONS(m->lb) == 0)
if (pd->job != NULL) {
if (KEYC_IS_MOUSE(event->key)) {
/* Must be inside, checked already. */
- if (!input_key_get_mouse(&pd->s, m, m->x - pd->px - 1,
- m->y - pd->py - 1, &buf, &len))
+ if (pd->flags & POPUP_NOBORDER) {
+ px = m->x - pd->px;
+ py = m->y - pd->py;
+ } else {
+ px = m->x - pd->px - 1;
+ py = m->y - pd->py - 1;
+ }
+ if (!input_key_get_mouse(&pd->s, m, px, py, &buf, &len))
return (0);
bufferevent_write(job_get_event(pd->job), buf, len);
return (0);
struct client *c, struct session *s, popup_close_cb cb, void *arg)
{
struct popup_data *pd;
-
- if (sx < 3 || sy < 3)
- return (-1);
+ u_int jx, jy;
+
+ if (flags & POPUP_NOBORDER) {
+ if (sx < 1 || sy < 1)
+ return (-1);
+ jx = sx;
+ jy = sy;
+ } else {
+ if (sx < 3 || sy < 3)
+ return (-1);
+ jx = sx - 2;
+ jy = sy - 2;
+ }
if (c->tty.sx < sx || c->tty.sy < sy)
return (-1);
pd->job = job_run(shellcmd, argc, argv, s, cwd,
popup_job_update_cb, popup_job_complete_cb, NULL, pd,
- JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE, pd->sx - 2, pd->sy - 2);
+ JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE, jx, jy);
pd->ictx = input_init(NULL, job_get_event(pd->job), &pd->palette);
server_client_set_overlay(c, 0, popup_check_cb, popup_mode_cb,