From b15032d223115ad0f65a182804ba914bf0fcc51b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 5 Nov 2019 08:49:32 +0100 Subject: 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. --- osc.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'osc.c') diff --git a/osc.c b/osc.c index 6b86be03..20bc06b4 100644 --- a/osc.c +++ b/osc.c @@ -102,6 +102,22 @@ from_clipboard_cb(const char *text, size_t size, void *user) free(chunk); } +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) { @@ -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 -- cgit v1.3