aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-11 14:27:12 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-11 15:38:03 +0000
commitc1c6646b98e0e67cc964ca1cb62522e7ac52085b (patch)
tree8e65ad9a54ce4759837503225cacfd46a74f187f /selection.c
parentselection: it's an error to call offset_accept() on non-drag-and-drop (diff)
selection: read until EOF when reading from clipboard
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/selection.c b/selection.c
index 9560126d..67cf10ea 100644
--- a/selection.c
+++ b/selection.c
@@ -289,22 +289,33 @@ selection_from_clipboard(struct terminal *term, uint32_t serial)
int read_fd = fds[0];
int write_fd = fds[1];
- wl_data_offer_receive(clipboard->data_offer, "text/plain;charset=utf-8", write_fd);
+ wl_data_offer_receive(
+ clipboard->data_offer, "text/plain;charset=utf-8", write_fd);
wl_display_roundtrip(term->wl.display);
- char text[4096];
- ssize_t amount = read(read_fd, text, sizeof(text));
-
- close(read_fd);
close(write_fd);
if (term->bracketed_paste)
write(term->ptmx, "\033[200~", 6);
- write(term->ptmx, text, amount);
+ /* Read until EOF */
+ while (true) {
+ char text[256];
+ ssize_t amount = read(read_fd, text, sizeof(text));
+
+ if (amount == -1) {
+ LOG_ERRNO("failed to read clipboard data: %d", errno);
+ break;
+ } else if (amount == 0)
+ break;
+
+ write(term->ptmx, text, amount);
+ }
if (term->bracketed_paste)
write(term->ptmx, "\033[201~", 6);
+
+ close(read_fd);
}
static void