summaryrefslogtreecommitdiffstats
path: root/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'input.c')
-rw-r--r--input.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/input.c b/input.c
index c9f67394..c67c9e41 100644
--- a/input.c
+++ b/input.c
@@ -2235,17 +2235,20 @@ input_enter_dcs(struct input_ctx *ictx)
static int
input_dcs_dispatch(struct input_ctx *ictx)
{
+ struct window_pane *wp = ictx->wp;
struct screen_write_ctx *sctx = &ictx->ctx;
u_char *buf = ictx->input_buf, *pbuf = ictx->param_buf;
size_t len = ictx->input_len, plen = ictx->param_len;
const char prefix[] = "tmux;";
const u_int prefixlen = (sizeof prefix) - 1;
+ if (wp == NULL)
+ return (0);
if (ictx->flags & INPUT_DISCARD)
return (0);
-
- log_debug("%s: \"%s\" \"%s\" \"%s\"", __func__, buf, ictx->interm_buf,
- ictx->param_buf);
+ if (!options_get_number(ictx->wp->options, "allow-passthrough"))
+ return (0);
+ log_debug("%s: \"%s\"", __func__, buf);
if (len >= prefixlen && strncmp(buf, prefix, prefixlen) == 0)
screen_write_rawstring(sctx, buf + prefixlen, len - prefixlen);
@@ -2686,8 +2689,8 @@ input_osc_52(struct input_ctx *ictx, const char *p)
{
struct window_pane *wp = ictx->wp;
char *end;
- const char *buf;
- size_t len;
+ const char *buf = NULL;
+ size_t len = 0;
u_char *out;
int outlen, state;
struct screen_write_ctx ctx;
@@ -2707,26 +2710,12 @@ input_osc_52(struct input_ctx *ictx, const char *p)
log_debug("%s: %s", __func__, end);
if (strcmp(end, "?") == 0) {
- if ((pb = paste_get_top(NULL)) != NULL) {
+ if ((pb = paste_get_top(NULL)) != NULL)
buf = paste_buffer_data(pb, &len);
- outlen = 4 * ((len + 2) / 3) + 1;
- out = xmalloc(outlen);
- if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
- free(out);
- return;
- }
- } else {
- outlen = 0;
- out = NULL;
- }
- bufferevent_write(ictx->event, "\033]52;;", 6);
- if (outlen != 0)
- bufferevent_write(ictx->event, out, outlen);
if (ictx->input_end == INPUT_END_BEL)
- bufferevent_write(ictx->event, "\007", 1);
+ input_reply_clipboard(ictx->event, buf, len, "\007");
else
- bufferevent_write(ictx->event, "\033\\", 2);
- free(out);
+ input_reply_clipboard(ictx->event, buf, len, "\033\\");
return;
}
@@ -2784,3 +2773,26 @@ input_osc_104(struct input_ctx *ictx, const char *p)
screen_write_fullredraw(&ictx->ctx);
free(copy);
}
+
+void
+input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
+ const char *end)
+{
+ char *out = NULL;
+ size_t outlen = 0;
+
+ if (buf != NULL && len != 0) {
+ outlen = 4 * ((len + 2) / 3) + 1;
+ out = xmalloc(outlen);
+ if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
+ free(out);
+ return;
+ }
+ }
+
+ bufferevent_write(bev, "\033]52;;", 6);
+ if (outlen != 0)
+ bufferevent_write(bev, out, outlen);
+ bufferevent_write(bev, end, strlen(end));
+ free(out);
+}