mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-27 01:40:16 -05:00
selection: add a ‘finish’ function, called at the end of receiving clipboard data
This is necessary to decode the final URI in a text/uri-list offer if it hasn’t been newline terminated.
This commit is contained in:
parent
7f5e259566
commit
4303401f69
1 changed files with 24 additions and 0 deletions
24
selection.c
24
selection.c
|
|
@ -1145,6 +1145,7 @@ struct clipboard_receive {
|
||||||
struct itimerspec timeout;
|
struct itimerspec timeout;
|
||||||
|
|
||||||
void (*decoder)(struct clipboard_receive *ctx, char *data, size_t size);
|
void (*decoder)(struct clipboard_receive *ctx, char *data, size_t size);
|
||||||
|
void (*finish)(struct clipboard_receive *ctx);
|
||||||
|
|
||||||
/* URI state */
|
/* URI state */
|
||||||
bool add_space;
|
bool add_space;
|
||||||
|
|
@ -1202,6 +1203,11 @@ fdm_receive_decoder_plain(struct clipboard_receive *ctx, char *data, size_t size
|
||||||
ctx->cb(data, size, ctx->user);
|
ctx->cb(data, size, ctx->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fdm_receive_finish_plain(struct clipboard_receive *ctx)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
decode_one_uri(struct clipboard_receive *ctx, char *uri, size_t len)
|
decode_one_uri(struct clipboard_receive *ctx, char *uri, size_t len)
|
||||||
{
|
{
|
||||||
|
|
@ -1257,6 +1263,14 @@ fdm_receive_decoder_uri(struct clipboard_receive *ctx, char *data, size_t size)
|
||||||
ctx->buf.idx = left;
|
ctx->buf.idx = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fdm_receive_finish_uri(struct clipboard_receive *ctx)
|
||||||
|
{
|
||||||
|
LOG_DBG("finish: %.*s", (int)ctx->buf.idx, ctx->buf.data);
|
||||||
|
if (ctx->buf.idx > 0)
|
||||||
|
decode_one_uri(ctx, ctx->buf.data, ctx->buf.idx);
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
fdm_receive(struct fdm *fdm, int fd, int events, void *data)
|
fdm_receive(struct fdm *fdm, int fd, int events, void *data)
|
||||||
{
|
{
|
||||||
|
|
@ -1307,6 +1321,7 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
ctx->finish(ctx);
|
||||||
clipboard_receive_done(fdm, ctx);
|
clipboard_receive_done(fdm, ctx);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1348,6 +1363,9 @@ begin_receive_clipboard(struct terminal *term, int read_fd,
|
||||||
.decoder = (mime_type == DATA_OFFER_MIME_URI_LIST
|
.decoder = (mime_type == DATA_OFFER_MIME_URI_LIST
|
||||||
? &fdm_receive_decoder_uri
|
? &fdm_receive_decoder_uri
|
||||||
: &fdm_receive_decoder_plain),
|
: &fdm_receive_decoder_plain),
|
||||||
|
.finish = (mime_type == DATA_OFFER_MIME_URI_LIST
|
||||||
|
? &fdm_receive_finish_uri
|
||||||
|
: &fdm_receive_finish_plain),
|
||||||
.cb = cb,
|
.cb = cb,
|
||||||
.done = done,
|
.done = done,
|
||||||
.user = user,
|
.user = user,
|
||||||
|
|
@ -1389,6 +1407,9 @@ text_from_clipboard(struct seat *seat, struct terminal *term,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DBG("receive from clipboard: mime-type=%s",
|
||||||
|
mime_type_map[clipboard->mime_type]);
|
||||||
|
|
||||||
int read_fd = fds[0];
|
int read_fd = fds[0];
|
||||||
int write_fd = fds[1];
|
int write_fd = fds[1];
|
||||||
|
|
||||||
|
|
@ -1533,6 +1554,9 @@ text_from_primary(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_DBG("receive from primary: mime-type=%s",
|
||||||
|
mime_type_map[primary->mime_type]);
|
||||||
|
|
||||||
int read_fd = fds[0];
|
int read_fd = fds[0];
|
||||||
int write_fd = fds[1];
|
int write_fd = fds[1];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue