- 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
@@ -512,6 +512,22 @@ static void ws_handle_text(WsState *ws, const char *msg) {
|
||||
free(txt);
|
||||
return;
|
||||
}
|
||||
if (strcmp(type, "clipmark") == 0) { /* the clipboard serial, before keys that may copy something */
|
||||
unsigned long serial = 0;
|
||||
char js[64];
|
||||
long id = 0;
|
||||
json_get_int(msg, "id", &id);
|
||||
if (remote_clipboard_serial(&ws->app->ctl, &serial) == 0) {
|
||||
snprintf(js, sizeof js, "{\"t\":\"clipmark\",\"id\":%ld,\"serial\":%lu}", id, serial);
|
||||
ws_send_text(ws->fd, js);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (strcmp(type, "copy") == 0) { /* press the focused app's copy keys */
|
||||
ws_note_key_activity(ws);
|
||||
ctl_fire(&ws->app->ctl, "input-copy");
|
||||
return;
|
||||
}
|
||||
if (strcmp(type, "paste") == 0) { /* paste the phone's clipboard, by the given chord or the app's usual one */
|
||||
long code = 0, mods = 0;
|
||||
char cmd[64] = "input-paste";
|
||||
@@ -621,6 +637,45 @@ fail:
|
||||
http_send(fd, status, "application/json", NULL, js, strlen(js));
|
||||
}
|
||||
|
||||
/* GET /api/clipboard/data: what is on the phone's clipboard, text or a PNG image, with its serial
|
||||
in X-Clipboard-Serial. */
|
||||
static void web_clipboard_data(RemoteApp *app, int fd, const char *hdrs) {
|
||||
char val[16] = {0}, out[160];
|
||||
const char *status = "502 Bad Gateway", *err = "The desktop did not give its clipboard", *mime = NULL;
|
||||
uint8_t *data = NULL;
|
||||
size_t len = 0;
|
||||
unsigned long serial = 0;
|
||||
/* As in web_clipboard: only the page itself can set this. */
|
||||
if (!find_header(hdrs, "X-Chandra-Remote", val, sizeof val)) {
|
||||
status = "403 Forbidden";
|
||||
err = "Forbidden";
|
||||
} else {
|
||||
switch (remote_clipboard_get(&app->ctl, &mime, &data, &len, &serial)) {
|
||||
case REMOTE_CLIP_OK:
|
||||
snprintf(out, sizeof out, "X-Clipboard-Serial: %lu\r\nX-Content-Type-Options: nosniff\r\n", serial);
|
||||
http_send(fd, "200 OK", mime, out, data, len);
|
||||
free(data);
|
||||
return;
|
||||
case REMOTE_CLIP_EMPTY:
|
||||
status = "404 Not Found";
|
||||
err = "No text or image on the phone's clipboard";
|
||||
break;
|
||||
case REMOTE_CLIP_LOCKED:
|
||||
status = "403 Forbidden";
|
||||
err = "The phone is locked";
|
||||
break;
|
||||
case REMOTE_CLIP_OLD:
|
||||
err = "The phone's session needs a restart for this (updated since)";
|
||||
break;
|
||||
case REMOTE_CLIP_TOO_LARGE:
|
||||
err = "Too large (16 MB at most)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
snprintf(out, sizeof out, "{\"ok\":false,\"error\":\"%s\"}", err);
|
||||
http_send(fd, status, "application/json", NULL, out, strlen(out));
|
||||
}
|
||||
|
||||
static void ws_loop(RemoteApp *app, int fd) {
|
||||
WsState ws;
|
||||
memset(&ws, 0, sizeof ws);
|
||||
@@ -924,6 +979,16 @@ void web_handle_client(RemoteApp *app, int fd) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
if (strcmp(path, "/api/clipboard/data") == 0 && !strcmp(method, "GET")) {
|
||||
if (!web_authorized(app, &cfg, target, buf)) {
|
||||
const char *m = "{\"ok\":false,\"error\":\"Unauthorized\"}";
|
||||
http_send(fd, "401 Unauthorized", "application/json", NULL, m, strlen(m));
|
||||
} else {
|
||||
web_clipboard_data(app, fd, buf);
|
||||
}
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
if (strcmp(method, "GET") == 0 && strcmp(path, "/ws") == 0) {
|
||||
if (!web_authorized(app, &cfg, target, buf)) {
|
||||
const char *m = "Unauthorized";
|
||||
|
||||
Reference in new issue
Block a user