mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-23 05:33:57 -04:00
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.
This commit is contained in:
parent
9cd22dc398
commit
b15032d223
3 changed files with 59 additions and 34 deletions
35
osc.c
35
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue