- 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:
1 parent
c5dbe028e6
commit
589d167f79
11 files changed
+552
-19
No files matched your search
@@ -201,6 +201,7 @@ class MockCtlServer:
|
||||
self.brightness = 75
|
||||
self.osk = 1
|
||||
self.clip_serial = 0
|
||||
self.clip_get = None # (mime, bytes) clipboard-get-fd writes, or its error
|
||||
self.clips = [] # (mime, bytes) put on the clipboard
|
||||
self.th = threading.Thread(target=self._serve, daemon=True)
|
||||
self.th.start()
|
||||
@@ -258,6 +259,25 @@ class MockCtlServer:
|
||||
os.close(fd)
|
||||
self.clip_serial += 1
|
||||
rep = f"ok serial={self.clip_serial}\n"
|
||||
elif cmd == "clipboard-get-fd":
|
||||
fd = files.pop(0)
|
||||
if self.clip_get is None:
|
||||
rep = "error empty\n"
|
||||
elif isinstance(self.clip_get, str):
|
||||
rep = self.clip_get + "\n"
|
||||
else:
|
||||
mime, data = self.clip_get
|
||||
rep = f"ok serial={self.clip_serial} type={mime}\n"
|
||||
|
||||
def write(out=os.dup(fd), data=data):
|
||||
try:
|
||||
with os.fdopen(out, "wb") as f:
|
||||
f.write(data)
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
|
||||
threading.Thread(target=write, daemon=True).start()
|
||||
os.close(fd)
|
||||
elif cmd == "osk toggle":
|
||||
self.osk = 0 if self.osk else 1
|
||||
rep = f"ok {'on' if self.osk else 'off'}\n"
|
||||
@@ -832,6 +852,58 @@ class RemoteTests(unittest.TestCase):
|
||||
self.assertEqual(self.clip_request("POST", b"y", {**hdr, "Cookie": "chandra_remote=" + tok})[0], 200)
|
||||
self.assertEqual(self.ctl.clips, [("text/plain", b"x"), ("text/plain", b"y")])
|
||||
|
||||
def clip_data(self, headers):
|
||||
c = http.client.HTTPConnection("127.0.0.1", self.web_port, timeout=15)
|
||||
c.request("GET", "/api/clipboard/data", headers=headers)
|
||||
r = c.getresponse()
|
||||
out = r.status, r.getheader("Content-Type"), r.read(), r.getheader("X-Clipboard-Serial")
|
||||
c.close()
|
||||
return out
|
||||
|
||||
def test_10_copy_from_the_desktop(self):
|
||||
self.shm.write_frame(64, 48, lambda x, y: (1, 2, 3))
|
||||
self.start_daemon(auth="none")
|
||||
own = {"X-Chandra-Remote": "1"}
|
||||
self.ctl.clip_serial = 7
|
||||
self.assertEqual(self.clip_data(own)[0], 404) # nothing there
|
||||
text = "líne 1\nline 2 \"q\"\n".encode() * 20000
|
||||
self.ctl.clip_get = ("text/plain", text)
|
||||
self.assertEqual(self.clip_data(own), (200, "text/plain; charset=utf-8", text, "7"))
|
||||
png = b"\x89PNG\r\n\x1a\n" + os.urandom(3 * 1024 * 1024)
|
||||
self.ctl.clip_get = ("image/png", png)
|
||||
self.assertEqual(self.clip_data(own), (200, "image/png", png, "7"))
|
||||
# Refused: no own-page header, too large, locked, a compositor from before.
|
||||
self.assertEqual(self.clip_data({})[0], 403)
|
||||
self.ctl.clip_get = ("image/png", bytes(16 * 1024 * 1024 + 1))
|
||||
self.assertEqual(self.clip_data(own)[0], 502)
|
||||
self.ctl.clip_get = "error locked"
|
||||
self.assertEqual(self.clip_data(own)[0], 403)
|
||||
self.ctl.clip_get = "error unknown command 'clipboard-get-fd' (try: help)"
|
||||
st, _, body, _ = self.clip_data(own)
|
||||
self.assertEqual(st, 502)
|
||||
self.assertIn("restart", json.loads(body)["error"])
|
||||
|
||||
ws, status_line, _, extra = ws_connect("127.0.0.1", self.web_port)
|
||||
self.assertIn("101", status_line)
|
||||
buf = bytearray(extra)
|
||||
ws_send_text(ws, json.dumps({"t": "clipmark", "id": 3}))
|
||||
ws_send_text(ws, json.dumps({"t": "copy"}))
|
||||
while True:
|
||||
op, payload = ws_read_frame(ws, buf)
|
||||
if op == 1 and json.loads(payload)["t"] == "clipmark":
|
||||
break
|
||||
self.assertEqual(json.loads(payload), {"t": "clipmark", "id": 3, "serial": 7})
|
||||
deadline = time.time() + 3.0
|
||||
while time.time() < deadline and "input-copy" not in self.ctl.commands:
|
||||
time.sleep(0.02)
|
||||
self.assertIn("input-copy", self.ctl.commands)
|
||||
ws.close()
|
||||
|
||||
def test_11_copy_needs_login(self):
|
||||
self.start_daemon(auth="password", password="TestPass99")
|
||||
self.ctl.clip_get = ("text/plain", b"secret")
|
||||
self.assertEqual(self.clip_data({"X-Chandra-Remote": "1"})[0], 401)
|
||||
|
||||
def test_09_sigusr2_restarts_in_place(self):
|
||||
self.start_daemon(auth="none")
|
||||
ws, status_line, _, _ = ws_connect("127.0.0.1", self.web_port)
|
||||
|
||||
Reference in new issue
Block a user