Remote: copy from the phone to this device's clipboard
CI / test (pull_request) Successful in 1m22s

- Web UI: Ctrl+C, Ctrl+X, Ctrl+Shift+C (Cmd+C on Mac) also put what they copied, text or PNG, on this device's clipboard; Copy, Copy Selection and Copy Clipboard buttons
- chandra-remote: GET /api/clipboard/data, with the same authorization as the upload
- Compositor: clipboard-get-fd has the clipboard's owner write into a pipe, refused while locked; input-copy presses Ctrl+Shift+C in terminals, Ctrl+C elsewhere
- Pending clipboard transfers keep the main loop awake

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-30 18:26:53 -08:00
1 parent c5dbe028e6
commit 589d167f79
11 files changed
+552 -19

No files matched your search

+75
View File
@@ -322,3 +322,78 @@ test "a paste still being written keeps its data when the clipboard changes" {
@sys.unlink(sink_path)
comp.close()
}
///|
test "the clipboard written into a pipe sent along: the compositor's own, a client's, none, locked" {
let (comp, path) = control_comp("clipget")
let fd = @sys.memfd_create("out", 0)
assert_eq(ask_with_file(comp, path, "clipboard-get-fd", fd), "error empty")
assert_true(ask(comp, path, "clipboard-get-fd")[0].has_prefix("error usage"))
// The compositor's own: more than fits at once, so it is written over several turns.
let sink_path = path + ".sink"
let listener = @sys.unix_listen(sink_path)
let reader = @sys.unix_connect(sink_path)
let writer = @sys.unix_accept(listener)
let data = Bytes::makei(3000000, i => (i * 7 % 251).to_byte())
comp.server.set_own_selection(["image/png"], data)
assert_eq(ask_with_file(comp, path, "clipboard-get-fd", writer), "ok serial=1 type=image/png")
@sys.close_fd(writer)
assert_true(comp.has_timed_work())
let buf : FixedArray[Byte] = FixedArray::make(65536, b'\x00')
let mut got = 0
let mut same = true
let mut eof = false
for _i = 0; _i < 2000 && !eof; _i = _i + 1 {
comp.step()
if @sys.poll_read(reader, 5) > 0 {
let (n, _) = @sys.recvmsg_fd(reader, buf, 65536)
if n == 0 {
eof = true
}
for j = 0; j < n; j = j + 1 {
same = same && buf[j] == data[got + j]
}
if n > 0 {
got = got + n
}
}
}
assert_true(eof) // the compositor closed its end
assert_true(same)
assert_eq(got, data.length())
@sys.close_fd(reader)
@sys.close_fd(listener)
@sys.unlink(sink_path)
// A client's: it is asked to write, as text when there is any.
let (a, _, _, _, _, _) = open_and_configure_client(comp, comp.server.socket_path, "A", "foot")
let (mgr, dev) = data_device_for(a)
let src = a.alloc_id()
let w1 = @wayland.WireWriter::new()
w1.u32(src)
a.send(w1.finish_msg(mgr, 0U))
for m in ["image/png", "UTF8_STRING"] {
let w = @wayland.WireWriter::new()
w.str(m)
a.send(w.finish_msg(src, 0U))
}
let w2 = @wayland.WireWriter::new()
w2.u32(src)
w2.u32(1U)
a.send(w2.finish_msg(dev, 1U))
for _i = 0; _i < 5; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
ignore(drain_args(a))
assert_eq(ask_with_file(comp, path, "clipboard-get-fd", fd), "ok serial=2 type=text/plain")
assert_true(has_msg(drain_args(a).map(m => (m.0, m.1)), src, 1U)) // send(mime, fd)
// Copy keys: to the focused window, never into the shell's own popups.
assert_eq(ask(comp, path, "input-copy"), ["ok keys"])
assert_eq(ask(comp, path, "shortcut launcher"), ["ok launcher"])
assert_eq(ask(comp, path, "input-copy"), ["ok nothing"])
assert_eq(ask(comp, path, "shortcut launcher"), ["ok launcher"])
comp.locked = true
assert_eq(ask_with_file(comp, path, "clipboard-get-fd", fd), "error locked")
@sys.close_fd(fd)
comp.close()
}