aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-12 13:45:41 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-21 10:55:33 +0000
commit4303401f69a92cfc1939354fe6ac2fb6489c01be (patch)
treeae8a9d7f8162df1ef3dc855afb3a8cea29ff96f8 /selection.c
parentselection: URI decoder: break out decoding of a single URI (diff)
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.
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/selection.c b/selection.c
index 05c699d6..8a1e2943 100644
--- a/selection.c
+++ b/selection.c
@@ -1145,6 +1145,7 @@ struct clipboard_receive {
struct itimerspec timeout;
void (*decoder)(struct clipboard_receive *ctx, char *data, size_t size);
+ void (*finish)(struct clipboard_receive *ctx);
/* URI state */
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);
}
+static void
+fdm_receive_finish_plain(struct clipboard_receive *ctx)
+{
+}
+
static bool
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;
}
+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
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:
+ ctx->finish(ctx);
clipboard_receive_done(fdm, ctx);
return true;
}
@@ -1348,6 +1363,9 @@ begin_receive_clipboard(struct terminal *term, int read_fd,
.decoder = (mime_type == DATA_OFFER_MIME_URI_LIST
? &fdm_receive_decoder_uri
: &fdm_receive_decoder_plain),
+ .finish = (mime_type == DATA_OFFER_MIME_URI_LIST
+ ? &fdm_receive_finish_uri
+ : &fdm_receive_finish_plain),
.cb = cb,
.done = done,
.user = user,
@@ -1389,6 +1407,9 @@ text_from_clipboard(struct seat *seat, struct terminal *term,
return;
}
+ LOG_DBG("receive from clipboard: mime-type=%s",
+ mime_type_map[clipboard->mime_type]);
+
int read_fd = fds[0];
int write_fd = fds[1];
@@ -1533,6 +1554,9 @@ text_from_primary(
return;
}
+ LOG_DBG("receive from primary: mime-type=%s",
+ mime_type_map[primary->mime_type]);
+
int read_fd = fds[0];
int write_fd = fds[1];