diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-11-05 07:49:32 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-11-05 07:49:32 +0000 |
| commit | b15032d223115ad0f65a182804ba914bf0fcc51b (patch) | |
| tree | 0cb05b53dc25fe42024f82fe81db4cf5184a015f /osc.c | |
| parent | selection: async send: handle POLLHUP (diff) | |
selection: text_from_{clipboard,primary}: add 'done' callback
This callback is *always* called, including when there has been an
error.
This is in preparation for making text_from_{clipboard,primary}
asynchronous.
Diffstat (limited to 'osc.c')
| -rw-r--r-- | osc.c | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -103,6 +103,22 @@ from_clipboard_cb(const char *text, size_t size, void *user) } static void +from_clipboard_done(void *user) +{ + struct clip_context *ctx = user; + struct terminal *term = ctx->term; + + if (ctx->idx > 0) { + char res[4]; + base64_encode_final(ctx->buf, ctx->idx, res); + term_to_slave(term, res, 4); + } + + term_to_slave(term, "\033\\", 2); + free(ctx); +} + +static void osc_from_clipboard(struct terminal *term, const char *source) { char src = 0; @@ -124,27 +140,20 @@ osc_from_clipboard(struct terminal *term, const char *source) term_to_slave(term, &src, 1); term_to_slave(term, ";", 1); - struct clip_context ctx = { - .term = term, - }; + struct clip_context *ctx = malloc(sizeof(*ctx)); + *ctx = (struct clip_context) {.term = term}; switch (src) { case 'c': - text_from_clipboard(term, term->wl->input_serial, &from_clipboard_cb, &ctx); + text_from_clipboard( + term, term->wl->input_serial, + &from_clipboard_cb, &from_clipboard_done, ctx); break; case 'p': - text_from_primary(term, &from_clipboard_cb, &ctx); + text_from_primary(term, &from_clipboard_cb, &from_clipboard_done, ctx); break; } - - if (ctx.idx > 0) { - char res[4]; - base64_encode_final(ctx.buf, ctx.idx, res); - term_to_slave(term, res, 4); - } - - term_to_slave(term, "\033\\", 2); } static void |
