mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-31 07:11:09 -04:00
selection: read until EOF when reading from clipboard
This commit is contained in:
parent
e8b6705ab8
commit
c1c6646b98
1 changed files with 17 additions and 6 deletions
23
selection.c
23
selection.c
|
|
@ -289,22 +289,33 @@ selection_from_clipboard(struct terminal *term, uint32_t serial)
|
||||||
int read_fd = fds[0];
|
int read_fd = fds[0];
|
||||||
int write_fd = fds[1];
|
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);
|
wl_display_roundtrip(term->wl.display);
|
||||||
|
|
||||||
char text[4096];
|
|
||||||
ssize_t amount = read(read_fd, text, sizeof(text));
|
|
||||||
|
|
||||||
close(read_fd);
|
|
||||||
close(write_fd);
|
close(write_fd);
|
||||||
|
|
||||||
if (term->bracketed_paste)
|
if (term->bracketed_paste)
|
||||||
write(term->ptmx, "\033[200~", 6);
|
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)
|
if (term->bracketed_paste)
|
||||||
write(term->ptmx, "\033[201~", 6);
|
write(term->ptmx, "\033[201~", 6);
|
||||||
|
|
||||||
|
close(read_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue