Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2026-02-23 08:11:38 +00:00
6 changed files with 52 additions and 36 deletions

16
grid.c
View File

@@ -209,12 +209,14 @@ grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
int had_extd = (gce->flags & GRID_FLAG_EXTENDED); int had_extd = (gce->flags & GRID_FLAG_EXTENDED);
memcpy(gce, &grid_cleared_entry, sizeof *gce); memcpy(gce, &grid_cleared_entry, sizeof *gce);
if (bg != 8) {
if (bg & COLOUR_FLAG_RGB) {
if (had_extd && old_offset < gl->extdsize) { if (had_extd && old_offset < gl->extdsize) {
gce->flags |= GRID_FLAG_EXTENDED; gce->flags |= GRID_FLAG_EXTENDED;
gce->offset = old_offset; gce->offset = old_offset;
} else gee = grid_extended_cell(gl, gce, &grid_cleared_cell);
if (bg != 8)
gee->bg = bg;
} else if (bg != 8) {
if (bg & COLOUR_FLAG_RGB) {
grid_get_extended_cell(gl, gce, gce->flags); grid_get_extended_cell(gl, gce, gce->flags);
gee = grid_extended_cell(gl, gce, &grid_cleared_cell); gee = grid_extended_cell(gl, gce, &grid_cleared_cell);
gee->bg = bg; gee->bg = bg;
@@ -493,7 +495,7 @@ static void
grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg) grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg)
{ {
struct grid_line *gl; struct grid_line *gl;
u_int xx; u_int xx, old_cellsize;
gl = &gd->linedata[py]; gl = &gd->linedata[py];
if (sx <= gl->cellsize) if (sx <= gl->cellsize)
@@ -506,8 +508,10 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg)
else if (gd->sx > sx) else if (gd->sx > sx)
sx = gd->sx; sx = gd->sx;
gl->celldata = xreallocarray(gl->celldata, sx, sizeof *gl->celldata); old_cellsize = gl->cellsize;
for (xx = gl->cellsize; xx < sx; xx++) gl->celldata = xrecallocarray(gl->celldata, old_cellsize, sx,
sizeof *gl->celldata);
for (xx = old_cellsize; xx < sx; xx++)
grid_clear_cell(gd, xx, py, bg); grid_clear_cell(gd, xx, py, bg);
gl->cellsize = sx; gl->cellsize = sx;
} }

43
input.c
View File

@@ -1139,11 +1139,9 @@ input_get(struct input_ctx *ictx, u_int validx, int minval, int defval)
static void static void
input_send_reply(struct input_ctx *ictx, const char *reply) input_send_reply(struct input_ctx *ictx, const char *reply)
{ {
struct bufferevent *bev = ictx->event; if (ictx->event != NULL) {
if (bev != NULL) {
log_debug("%s: %s", __func__, reply); log_debug("%s: %s", __func__, reply);
bufferevent_write(bev, reply, strlen(reply)); bufferevent_write(ictx->event, reply, strlen(reply));
} }
} }
@@ -3089,8 +3087,9 @@ input_osc_133(struct input_ctx *ictx, const char *p)
/* Handle OSC 52 reply. */ /* Handle OSC 52 reply. */
static void static void
input_osc_52_reply(struct input_ctx *ictx) input_osc_52_reply(struct input_ctx *ictx, char clip)
{ {
struct bufferevent *ev = ictx->event;
struct paste_buffer *pb; struct paste_buffer *pb;
int state; int state;
const char *buf; const char *buf;
@@ -3104,9 +3103,9 @@ input_osc_52_reply(struct input_ctx *ictx)
return; return;
buf = paste_buffer_data(pb, &len); buf = paste_buffer_data(pb, &len);
if (ictx->input_end == INPUT_END_BEL) if (ictx->input_end == INPUT_END_BEL)
input_reply_clipboard(ictx->event, buf, len, "\007"); input_reply_clipboard(ev, buf, len, "\007", clip);
else else
input_reply_clipboard(ictx->event, buf, len, "\033\\"); input_reply_clipboard(ev, buf, len, "\033\\", clip);
return; return;
} }
input_add_request(ictx, INPUT_REQUEST_CLIPBOARD, ictx->input_end); input_add_request(ictx, INPUT_REQUEST_CLIPBOARD, ictx->input_end);
@@ -3119,7 +3118,7 @@ input_osc_52_reply(struct input_ctx *ictx)
*/ */
static int static int
input_osc_52_parse(struct input_ctx *ictx, const char *p, u_char **out, input_osc_52_parse(struct input_ctx *ictx, const char *p, u_char **out,
int *outlen, char *flags) int *outlen, char *clip)
{ {
char *end; char *end;
size_t len; size_t len;
@@ -3137,13 +3136,13 @@ input_osc_52_parse(struct input_ctx *ictx, const char *p, u_char **out,
log_debug("%s: %s", __func__, end); log_debug("%s: %s", __func__, end);
for (i = 0; p + i != end; i++) { for (i = 0; p + i != end; i++) {
if (strchr(allow, p[i]) != NULL && strchr(flags, p[i]) == NULL) if (strchr(allow, p[i]) != NULL && strchr(clip, p[i]) == NULL)
flags[j++] = p[i]; clip[j++] = p[i];
} }
log_debug("%s: %.*s %s", __func__, (int)(end - p - 1), p, flags); log_debug("%s: %.*s %s", __func__, (int)(end - p - 1), p, clip);
if (strcmp(end, "?") == 0) { if (strcmp(end, "?") == 0) {
input_osc_52_reply(ictx); input_osc_52_reply(ictx, *clip);
return (0); return (0);
} }
@@ -3169,9 +3168,9 @@ input_osc_52(struct input_ctx *ictx, const char *p)
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
u_char *out; u_char *out;
int outlen; int outlen;
char flags[sizeof "cpqs01234567"] = ""; char clip[sizeof "cpqs01234567"] = "";
if (!input_osc_52_parse(ictx, p, &out, &outlen, flags)) if (!input_osc_52_parse(ictx, p, &out, &outlen, clip))
return; return;
if (wp == NULL) { if (wp == NULL) {
@@ -3180,12 +3179,12 @@ input_osc_52(struct input_ctx *ictx, const char *p)
free(out); free(out);
return; return;
} }
tty_set_selection(&ictx->c->tty, flags, out, outlen); tty_set_selection(&ictx->c->tty, clip, out, outlen);
paste_add(NULL, out, outlen); paste_add(NULL, out, outlen);
} else { } else {
/* Normal window. */ /* Normal window. */
screen_write_start_pane(&ctx, wp, NULL); screen_write_start_pane(&ctx, wp, NULL);
screen_write_setselection(&ctx, flags, out, outlen); screen_write_setselection(&ctx, clip, out, outlen);
screen_write_stop(&ctx); screen_write_stop(&ctx);
notify_pane("pane-set-clipboard", wp); notify_pane("pane-set-clipboard", wp);
paste_add(NULL, out, outlen); paste_add(NULL, out, outlen);
@@ -3233,7 +3232,7 @@ input_osc_104(struct input_ctx *ictx, const char *p)
/* Send a clipboard reply. */ /* Send a clipboard reply. */
void void
input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len, input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
const char *end) const char *end, char clip)
{ {
char *out = NULL; char *out = NULL;
int outlen = 0; int outlen = 0;
@@ -3249,7 +3248,10 @@ input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
} }
} }
bufferevent_write(bev, "\033]52;;", 6); bufferevent_write(bev, "\033]52;", 5);
if (clip != 0)
bufferevent_write(bev, &clip, 1);
bufferevent_write(bev, ";", 1);
if (outlen != 0) if (outlen != 0)
bufferevent_write(bev, out, outlen); bufferevent_write(bev, out, outlen);
bufferevent_write(bev, end, strlen(end)); bufferevent_write(bev, end, strlen(end));
@@ -3391,6 +3393,7 @@ static void
input_request_clipboard_reply(struct input_request *ir, void *data) input_request_clipboard_reply(struct input_request *ir, void *data)
{ {
struct input_ctx *ictx = ir->ictx; struct input_ctx *ictx = ir->ictx;
struct bufferevent *ev = ictx->event;
struct input_request_clipboard_data *cd = data; struct input_request_clipboard_data *cd = data;
int state; int state;
char *copy; char *copy;
@@ -3405,9 +3408,9 @@ input_request_clipboard_reply(struct input_request *ir, void *data)
} }
if (ir->idx == INPUT_END_BEL) if (ir->idx == INPUT_END_BEL)
input_reply_clipboard(ictx->event, cd->buf, cd->len, "\007"); input_reply_clipboard(ev, cd->buf, cd->len, "\007", cd->clip);
else else
input_reply_clipboard(ictx->event, cd->buf, cd->len, "\033\\"); input_reply_clipboard(ev, cd->buf, cd->len, "\033\\", cd->clip);
} }
/* Handle a reply to a request. */ /* Handle a reply to a request. */

View File

@@ -2370,14 +2370,14 @@ screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc,
/* Set external clipboard. */ /* Set external clipboard. */
void void
screen_write_setselection(struct screen_write_ctx *ctx, const char *flags, screen_write_setselection(struct screen_write_ctx *ctx, const char *clip,
u_char *str, u_int len) u_char *str, u_int len)
{ {
struct tty_ctx ttyctx; struct tty_ctx ttyctx;
screen_write_initctx(ctx, &ttyctx, 0); screen_write_initctx(ctx, &ttyctx, 0);
ttyctx.ptr = str; ttyctx.ptr = str;
ttyctx.ptr2 = (void *)flags; ttyctx.ptr2 = (void *)clip;
ttyctx.num = len; ttyctx.num = len;
tty_write(tty_cmd_setselection, &ttyctx); tty_write(tty_cmd_setselection, &ttyctx);

3
tmux.h
View File

@@ -1146,6 +1146,7 @@ struct input_request_palette_data {
struct input_request_clipboard_data { struct input_request_clipboard_data {
char *buf; char *buf;
size_t len; size_t len;
char clip;
}; };
/* Request sent to client on behalf of pane. */ /* Request sent to client on behalf of pane. */
@@ -3066,7 +3067,7 @@ void input_parse_buffer(struct window_pane *, u_char *, size_t);
void input_parse_screen(struct input_ctx *, struct screen *, void input_parse_screen(struct input_ctx *, struct screen *,
screen_write_init_ctx_cb, void *, u_char *, size_t); screen_write_init_ctx_cb, void *, u_char *, size_t);
void input_reply_clipboard(struct bufferevent *, const char *, size_t, void input_reply_clipboard(struct bufferevent *, const char *, size_t,
const char *); const char *, char);
void input_set_buffer_size(size_t); void input_set_buffer_size(size_t);
void input_request_reply(struct client *, enum input_request_type, void *); void input_request_reply(struct client *, enum input_request_type, void *);
void input_cancel_requests(struct client *); void input_cancel_requests(struct client *);

View File

@@ -1310,7 +1310,7 @@ tty_keys_clipboard(struct tty *tty, const char *buf, size_t len, size_t *size)
{ {
struct client *c = tty->client; struct client *c = tty->client;
size_t end, terminator = 0, needed; size_t end, terminator = 0, needed;
char *copy, *out; char *copy, *out, clip = 0;
int outlen; int outlen;
struct input_request_clipboard_data cd; struct input_request_clipboard_data cd;
@@ -1360,7 +1360,14 @@ tty_keys_clipboard(struct tty *tty, const char *buf, size_t len, size_t *size)
/* Adjust end so that it points to the start of the terminator. */ /* Adjust end so that it points to the start of the terminator. */
end -= terminator - 1; end -= terminator - 1;
/* Get the second argument. */ /*
* Save which clipboard was used from the second argument. If more than
* one is specified (should not happen), ignore the argument.
*/
if (end >= 2 && buf[0] != ';' && buf[1] == ';')
clip = buf[0];
/* Skip the second argument. */
while (end != 0 && *buf != ';') { while (end != 0 && *buf != ';') {
buf++; buf++;
end--; end--;
@@ -1393,6 +1400,7 @@ tty_keys_clipboard(struct tty *tty, const char *buf, size_t len, size_t *size)
/* Set reply if any. */ /* Set reply if any. */
cd.buf = out; cd.buf = out;
cd.len = outlen; cd.len = outlen;
cd.clip = clip;
input_request_reply(c, INPUT_REQUEST_CLIPBOARD, &cd); input_request_reply(c, INPUT_REQUEST_CLIPBOARD, &cd);
/* Create a buffer if requested. */ /* Create a buffer if requested. */

4
tty.c
View File

@@ -2063,7 +2063,7 @@ tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx)
} }
void void
tty_set_selection(struct tty *tty, const char *flags, const char *buf, tty_set_selection(struct tty *tty, const char *clip, const char *buf,
size_t len) size_t len)
{ {
char *encoded; char *encoded;
@@ -2079,7 +2079,7 @@ tty_set_selection(struct tty *tty, const char *flags, const char *buf,
b64_ntop(buf, len, encoded, size); b64_ntop(buf, len, encoded, size);
tty->flags |= TTY_NOBLOCK; tty->flags |= TTY_NOBLOCK;
tty_putcode_ss(tty, TTYC_MS, flags, encoded); tty_putcode_ss(tty, TTYC_MS, clip, encoded);
free(encoded); free(encoded);
} }