Repository navigation
Conversation
8ac2f51 to
03a253c
Compare
Automated AI review
Outcome: A clipboard read does not use up a Wayland selection, so this drops image history without a demonstrated cause. The single-use pipe premise does not reproduceHyprland forwards each read to the owner; Suggested change: Share Reproducer (premise, at 03a253c)Checks the PR's premise with the image watcher the PR removes (the two watcher commands are copied from The watcher reads the 3 MiB image first, then three pastes each still get identical bytes, and Run: put relay.c// Minimal Wayland display with only wl_seat and ext-data-control, relaying
// clipboard reads the way wlroots/Hyprland do: each offer.receive(mime, fd)
// becomes source.send(mime, fd). Logs one line per relayed read to stderr.
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wayland-server.h>
#include "ext-data-control-v1-server-protocol.h"
struct source { struct wl_resource *res; struct wl_array mimes; };
struct offer { struct source *src; struct wl_list link; };
struct device { struct wl_resource *res; struct wl_list link; };
static struct wl_list devices, offers;
static struct source *selection;
static void offer_receive(struct wl_client *c, struct wl_resource *r, const char *mime, int32_t fd) {
struct offer *o = wl_resource_get_user_data(r);
if (o->src && o->src == selection) {
fprintf(stderr, "relay: read of %s forwarded to the source\n", mime);
ext_data_control_source_v1_send_send(o->src->res, mime, fd);
}
close(fd);
}
static void destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); }
static const struct ext_data_control_offer_v1_interface offer_impl = {offer_receive, destroy_req};
static void offer_gone(struct wl_resource *r) {
struct offer *o = wl_resource_get_user_data(r);
wl_list_remove(&o->link);
free(o);
}
static void send_selection(struct device *d) {
if (!selection) { ext_data_control_device_v1_send_selection(d->res, NULL); return; }
struct wl_resource *or = wl_resource_create(wl_resource_get_client(d->res), &ext_data_control_offer_v1_interface, 1, 0);
struct offer *o = calloc(1, sizeof *o);
o->src = selection;
wl_list_insert(&offers, &o->link);
wl_resource_set_implementation(or, &offer_impl, o, offer_gone);
ext_data_control_device_v1_send_data_offer(d->res, or);
char **m;
wl_array_for_each(m, &selection->mimes) ext_data_control_offer_v1_send_offer(or, *m);
ext_data_control_device_v1_send_selection(d->res, or);
}
static void broadcast(void) { struct device *d; wl_list_for_each(d, &devices, link) send_selection(d); }
static void set_selection(struct wl_client *c, struct wl_resource *r, struct wl_resource *sr) {
struct source *s = sr ? wl_resource_get_user_data(sr) : NULL, *old = selection;
if (s == old) return;
selection = s;
if (old) ext_data_control_source_v1_send_cancelled(old->res);
broadcast();
}
static void set_primary(struct wl_client *c, struct wl_resource *r, struct wl_resource *sr) {}
static const struct ext_data_control_device_v1_interface device_impl = {set_selection, destroy_req, set_primary};
static void device_gone(struct wl_resource *r) {
struct device *d = wl_resource_get_user_data(r);
wl_list_remove(&d->link);
free(d);
}
static void source_offer(struct wl_client *c, struct wl_resource *r, const char *mime) {
struct source *s = wl_resource_get_user_data(r);
*(char **)wl_array_add(&s->mimes, sizeof(char *)) = strdup(mime);
}
static const struct ext_data_control_source_v1_interface source_impl = {source_offer, destroy_req};
static void source_gone(struct wl_resource *r) {
struct source *s = wl_resource_get_user_data(r);
struct offer *o;
wl_list_for_each(o, &offers, link) if (o->src == s) o->src = NULL;
if (selection == s) { selection = NULL; broadcast(); }
char **m;
wl_array_for_each(m, &s->mimes) free(*m);
wl_array_release(&s->mimes);
free(s);
}
static void create_source(struct wl_client *c, struct wl_resource *r, uint32_t id) {
struct source *s = calloc(1, sizeof *s);
wl_array_init(&s->mimes);
s->res = wl_resource_create(c, &ext_data_control_source_v1_interface, 1, id);
wl_resource_set_implementation(s->res, &source_impl, s, source_gone);
}
static void get_device(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *seat) {
struct device *d = calloc(1, sizeof *d);
d->res = wl_resource_create(c, &ext_data_control_device_v1_interface, 1, id);
wl_resource_set_implementation(d->res, &device_impl, d, device_gone);
wl_list_insert(&devices, &d->link);
send_selection(d);
}
static const struct ext_data_control_manager_v1_interface manager_impl = {create_source, get_device, destroy_req};
static void bind_manager(struct wl_client *c, void *data, uint32_t v, uint32_t id) {
wl_resource_set_implementation(wl_resource_create(c, &ext_data_control_manager_v1_interface, 1, id), &manager_impl, NULL, NULL);
}
static void bind_seat(struct wl_client *c, void *data, uint32_t v, uint32_t id) {
struct wl_resource *r = wl_resource_create(c, &wl_seat_interface, v, id);
wl_resource_set_implementation(r, NULL, NULL, NULL);
wl_seat_send_capabilities(r, 0);
wl_seat_send_name(r, "seat0");
}
static int quit(int sig, void *dpy) { wl_display_terminate(dpy); return 0; }
int main(void) {
signal(SIGPIPE, SIG_IGN);
wl_list_init(&devices);
wl_list_init(&offers);
struct wl_display *dpy = wl_display_create();
const char *name = wl_display_add_socket_auto(dpy);
wl_global_create(dpy, &wl_seat_interface, 2, NULL, bind_seat);
wl_global_create(dpy, &ext_data_control_manager_v1_interface, 1, NULL, bind_manager);
wl_event_loop_add_signal(wl_display_get_event_loop(dpy), SIGTERM, quit, dpy);
printf("%s\n", name);
fflush(stdout);
wl_display_run(dpy);
wl_display_destroy_clients(dpy);
wl_display_destroy(dpy);
return 0;
}repro.sh#!/bin/bash
# Does the image watcher that PR #11715 removes stop a paste from getting an image?
# Usage: OMARCHY=/path/to/omarchy/checkout bash repro.sh (needs relay.c next to it)
# Needs wl-clipboard, gcc, wayland-scanner, wayland-protocols, jq, perl, setpriv.
# Everything runs on a private Wayland display; the session clipboard is not touched.
set -u
here=$(cd "$(dirname "$0")" && pwd)
work=$(mktemp -d)
pids=()
trap 'kill "${pids[@]}" 2>/dev/null; wait 2>/dev/null; rm -rf "$work"' EXIT
export XDG_RUNTIME_DIR=$work HOME=$work/home XDG_STATE_HOME=$work/state
mkdir -p "$HOME" "$XDG_STATE_HOME"
xml=$(pkg-config --variable=pkgdatadir wayland-protocols)/staging/ext-data-control/ext-data-control-v1.xml
wayland-scanner server-header "$xml" "$work/ext-data-control-v1-server-protocol.h"
wayland-scanner private-code "$xml" "$work/ext-data-control-v1-protocol.c"
gcc -I"$work" -o "$work/relay" "$here/relay.c" "$work/ext-data-control-v1-protocol.c" -lwayland-server || exit 1
"$work/relay" >"$work/display" 2>"$work/relay.log" &
pids+=($!)
until [[ -s $work/display ]]; do sleep 0.05; done
export WAYLAND_DISPLAY=$(<"$work/display")
# The two watchers as Clipboard.qml declares them before the PR.
capture=$OMARCHY/shell/plugins/clipboard/capture.sh
setpriv --pdeathsig TERM wl-paste --type text --watch "$capture" text >"$work/text-watcher.out" &
pids+=($!)
setpriv --pdeathsig TERM wl-paste --type image/png --watch "$capture" image/png >"$work/image-watcher.out" &
pids+=($!)
sleep 1
{ printf '\x89PNG\r\n\x1a\n'; head -c 3145728 /dev/urandom; } >"$work/image.png"
wl-copy --foreground --type image/png <"$work/image.png" &
copy_pid=$!
pids+=($copy_pid)
for _ in $(seq 1 100); do [[ -s $work/image-watcher.out ]] && break; sleep 0.05; done
echo "image watcher recorded: $(jq -c '{type, mime}' "$work/image-watcher.out")"
cmp -s "$(jq -r .path "$work/image-watcher.out")" "$work/image.png" && echo "image watcher's stored copy is identical"
for i in 1 2 3; do
if timeout 5 wl-paste --type image/png | cmp -s - "$work/image.png"; then
echo "paste $i after the watcher's read: identical $(stat -c %s "$work/image.png") bytes"
else
echo "paste $i after the watcher's read: DIFFERENT or empty"
fi
done
kill -0 "$copy_pid" 2>/dev/null && echo "wl-copy is still serving the image"
echo "reads the source served:"
sed 's/^/ /' "$work/relay.log"
# Shell start runs capture.sh with no arguments (currentProc), which the PR keeps.
echo "startup snapshot at the PR head records: $("$capture" | jq -c '{type, mime}')"Actual output (PR head 03a253c, wl-clipboard 2.3.0)More findings: the kept text watcher still reads browser image copiesFor images with a URL, Chromium's "Copy image" also offers Suggested change: Drop the description's claim that text copies are exempt. Reproducer (text watcher, at 03a253c)Chromium's "Copy image" writes The text watcher reads Run: put source.c// A clipboard owner shaped like Chromium's "Copy image": it offers image/png,
// text/html (<img> markup) and text/x-moz-url, serves every read separately
// from memory on a forked writer, and logs each read to stderr.
// Usage: source IMAGEFILE (prints "ready" once it owns the selection)
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wayland-client.h>
#include "ext-data-control-v1-client-protocol.h"
static struct wl_seat *seat;
static struct ext_data_control_manager_v1 *manager;
static char image[8 << 20];
static size_t image_len;
static const char html[] = "<img src=\"https://example.com/cat.png\" alt=\"cat\">";
static const char mozurl[] = "h\0t\0t\0p\0s\0:\0/\0/\0e\0x\0a\0m\0p\0l\0e\0.\0c\0o\0m\0";
static void global(void *d, struct wl_registry *r, uint32_t name, const char *iface, uint32_t v) {
if (!strcmp(iface, "wl_seat") && !seat) seat = wl_registry_bind(r, name, &wl_seat_interface, 2);
if (!strcmp(iface, "ext_data_control_manager_v1")) manager = wl_registry_bind(r, name, &ext_data_control_manager_v1_interface, 1);
}
static void global_remove(void *d, struct wl_registry *r, uint32_t name) {}
static const struct wl_registry_listener registry_listener = {global, global_remove};
static void on_send(void *d, struct ext_data_control_source_v1 *s, const char *mime, int32_t fd) {
const char *buf = !strcmp(mime, "image/png") ? image : !strcmp(mime, "text/html") ? html : mozurl;
size_t len = buf == image ? image_len : buf == html ? strlen(html) : sizeof mozurl - 1;
fprintf(stderr, "source: served a read of %s\n", mime);
if (fork() == 0) {
fcntl(fd, F_SETFL, 0);
for (size_t off = 0; off < len;) {
ssize_t w = write(fd, buf + off, len - off);
if (w <= 0) break;
off += w;
}
_exit(0);
}
close(fd);
}
static void on_cancelled(void *d, struct ext_data_control_source_v1 *s) { exit(0); }
static const struct ext_data_control_source_v1_listener source_listener = {on_send, on_cancelled};
static void data_offer(void *d, struct ext_data_control_device_v1 *dev, struct ext_data_control_offer_v1 *o) {}
static void selection(void *d, struct ext_data_control_device_v1 *dev, struct ext_data_control_offer_v1 *o) {
if (o) ext_data_control_offer_v1_destroy(o);
}
static void finished(void *d, struct ext_data_control_device_v1 *dev) { exit(1); }
static const struct ext_data_control_device_v1_listener device_listener = {data_offer, selection, finished, selection};
int main(int argc, char **argv) {
signal(SIGCHLD, SIG_IGN);
int fd = open(argv[1], O_RDONLY);
image_len = read(fd, image, sizeof image);
struct wl_display *dpy = wl_display_connect(NULL);
wl_registry_add_listener(wl_display_get_registry(dpy), ®istry_listener, NULL);
wl_display_roundtrip(dpy);
struct ext_data_control_source_v1 *src = ext_data_control_manager_v1_create_data_source(manager);
ext_data_control_source_v1_add_listener(src, &source_listener, NULL);
ext_data_control_source_v1_offer(src, "image/png");
ext_data_control_source_v1_offer(src, "text/html");
ext_data_control_source_v1_offer(src, "text/x-moz-url");
struct ext_data_control_device_v1 *dev = ext_data_control_manager_v1_get_data_device(manager, seat);
ext_data_control_device_v1_add_listener(dev, &device_listener, NULL);
ext_data_control_device_v1_set_selection(dev, src);
wl_display_roundtrip(dpy);
printf("ready\n");
fflush(stdout);
while (wl_display_dispatch(dpy) >= 0) {}
return 1;
}repro-text-watcher.sh#!/bin/bash
# Does the text watcher that PR #11715 keeps still read from a browser-style image copy?
# Usage: OMARCHY=/path/to/omarchy/checkout bash repro-text-watcher.sh (relay.c and source.c next to it)
# Needs wl-clipboard, gcc, wayland-scanner, wayland-protocols, jq, perl, setpriv.
set -u
here=$(cd "$(dirname "$0")" && pwd)
work=$(mktemp -d)
pids=()
trap 'kill "${pids[@]}" 2>/dev/null; wait 2>/dev/null; rm -rf "$work"' EXIT
export XDG_RUNTIME_DIR=$work HOME=$work/home XDG_STATE_HOME=$work/state
mkdir -p "$HOME" "$XDG_STATE_HOME"
xml=$(pkg-config --variable=pkgdatadir wayland-protocols)/staging/ext-data-control/ext-data-control-v1.xml
wayland-scanner server-header "$xml" "$work/ext-data-control-v1-server-protocol.h"
wayland-scanner client-header "$xml" "$work/ext-data-control-v1-client-protocol.h"
wayland-scanner private-code "$xml" "$work/ext-data-control-v1-protocol.c"
gcc -I"$work" -o "$work/relay" "$here/relay.c" "$work/ext-data-control-v1-protocol.c" -lwayland-server || exit 1
gcc -I"$work" -o "$work/source" "$here/source.c" "$work/ext-data-control-v1-protocol.c" -lwayland-client || exit 1
"$work/relay" >"$work/display" 2>/dev/null &
pids+=($!)
until [[ -s $work/display ]]; do sleep 0.05; done
export WAYLAND_DISPLAY=$(<"$work/display")
# The only watcher Clipboard.qml declares at the PR head.
capture=$OMARCHY/shell/plugins/clipboard/capture.sh
setpriv --pdeathsig TERM wl-paste --type text --watch "$capture" text >"$work/text-watcher.out" &
pids+=($!)
sleep 1
{ printf '\x89PNG\r\n\x1a\n'; head -c 3145728 /dev/urandom; } >"$work/image.png"
"$work/source" "$work/image.png" >"$work/source.ready" 2>"$work/source.log" &
pids+=($!)
for _ in $(seq 1 100); do [[ -s $work/text-watcher.out ]] && break; sleep 0.05; done
echo "reads the source served after the copy:"
sed 's/^/ /' "$work/source.log"
echo "text watcher recorded: $(jq -c . "$work/text-watcher.out")"
timeout 5 wl-paste --type image/png | cmp -s - "$work/image.png" && echo "a later image paste is still identical"Actual output (PR head 03a253c, wl-clipboard 2.3.0)More findings: manual and startup captureManual still promises image history
Suggested change: Update both lines if image history is removed. Image capture is only partly removedThe shell-start snapshot ( Suggested change: Either keep image capture or remove it from the startup snapshot too, so the behaviour is consistent. DetailsOverlap with open PRs: #11920 conflicts in Hypothesis (simulated, not the reporter's confirmed cause): This is not a reproduction of the reporter's hang. It shows a mechanism that produces the symptoms the PR describes ("leaves the user's paste target with nothing and results in stuck
With a 3 MiB payload, a paste during the stall gets nothing within its 3 s timeout, and the old Run: put repro-stall.sh#!/bin/bash
# What happens to wl-copy when a watcher callback stops before reading its pipe?
# Simulation: a wrapper makes `wl-paste --list-types` (capture.sh runs it before
# reading stdin) sleep 6 s. Usage: OMARCHY=... bash repro-stall.sh WATCHER-TYPE MIME BYTES
# e.g. image/png image/png 3145728 (watcher removed by the PR)
# text text/plain 3145728 (watcher kept by the PR)
# text text/plain 16384
set -u
watch_type=$1 mime=$2 bytes=$3
here=$(cd "$(dirname "$0")" && pwd)
work=$(mktemp -d)
pids=()
trap 'kill "${pids[@]}" 2>/dev/null; wait 2>/dev/null; rm -rf "$work"' EXIT
export XDG_RUNTIME_DIR=$work HOME=$work/home XDG_STATE_HOME=$work/state
mkdir -p "$HOME" "$XDG_STATE_HOME" "$work/bin"
xml=$(pkg-config --variable=pkgdatadir wayland-protocols)/staging/ext-data-control/ext-data-control-v1.xml
wayland-scanner server-header "$xml" "$work/ext-data-control-v1-server-protocol.h"
wayland-scanner private-code "$xml" "$work/ext-data-control-v1-protocol.c"
gcc -I"$work" -o "$work/relay" "$here/relay.c" "$work/ext-data-control-v1-protocol.c" -lwayland-server || exit 1
"$work/relay" >"$work/display" 2>/dev/null &
pids+=($!)
until [[ -s $work/display ]]; do sleep 0.05; done
export WAYLAND_DISPLAY=$(<"$work/display")
real=$(command -v wl-paste)
cat >"$work/bin/wl-paste" <<SH
#!/bin/bash
[[ \${1:-} == --list-types && -e $work/stall ]] && sleep 6
exec $real "\$@"
SH
chmod +x "$work/bin/wl-paste"
capture=$OMARCHY/shell/plugins/clipboard/capture.sh
PATH="$work/bin:$PATH" setpriv --pdeathsig TERM wl-paste --type "$watch_type" --watch "$capture" "$watch_type" >"$work/watcher.out" &
pids+=($!)
sleep 1
if [[ $mime == image/* ]]; then head -c "$bytes" /dev/urandom >"$work/payload"; else head -c "$bytes" /dev/zero | tr '\0' a >"$work/payload"; fi
touch "$work/stall"
wl-copy --foreground --type "$mime" <"$work/payload" &
old=$!
pids+=($old)
sleep 0.7
start=$(date +%s%3N)
timeout 3 "$real" --no-newline --type "$mime" | cmp -s - "$work/payload" &&
echo "paste while the callback is stalled: identical after $(($(date +%s%3N) - start)) ms" ||
echo "paste while the callback is stalled: nothing after $(($(date +%s%3N) - start)) ms (timed out)"
printf 'next copy' | wl-copy --foreground --type text/plain &
pids+=($!)
start=$(date +%s%3N)
while kill -0 "$old" 2>/dev/null; do sleep 0.05; done
echo "previous wl-copy exited $(($(date +%s%3N) - start)) ms after a new copy replaced it"Actual output (PR head 03a253c, wl-clipboard 2.3.0)
Verified:
Optional test improvement: The new substring check misses other spellings such as Review informationTest scope: Source and sandbox runs of wl-clipboard 2.3.0 on a minimal Wayland relay at AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
|
Reviewed at 03a253c. I could not reproduce the problem this fixes, and the change removes image clipboard history, so it is not ready. What was run. On a disposable Omarchy worker (Hyprland 0.56.2, wl-clipboard 2.3.0), in its live session:
Why the premise does not hold. A Wayland selection is not a pipe one reader can drain. Each paste sends its own What the change costs. New image copies stop reaching history, while A real hang has a narrower fix. If you have seen a paste hang and Second opinion. Codex Medium reviewed the diff and the reasoning separately and reached the same conclusion. It added the Waiting on the author: a reproduction or process listing from an actual hang. Whether to drop image history at all is the maintainer's call. |
Problem:
The Omarchy clipboard manager ran a continuous
wl-paste --type image/png --watchprocess to capture image history. In Wayland, when an image is copied (e.g., from Chromium, Brave, or a screenshot tool), the source application often uses a single-use pipe to serve the clipboard data. Because this background watcher immediately requests the data, it consumes the single-use pipe before the user can paste it into another application. This leaves the user's paste target with nothing and results in stuckwl-copyprocesses that deadlock the clipboard entirely.Solution:
This PR completely removes the
imageWatchProcfrom the clipboard manager.While this means Omarchy no longer maintains a background history of copied images, it guarantees that image pasting works reliably 100% of the time. Text history remains perfectly intact because text payloads are tiny and aren't subject to the same single-use pipe restrictions. An explicit test has been added to ensure the image watcher is not accidentally reintroduced.
Retaining Image History
Removing the background watcher drops the image history feature. Building a background image clipboard manager on Wayland using purely bash and
wl-pasteis fundamentally flawed due to the single-use pipe issue. If the project wants to retain image history, here are the architectural alternatives:1. "Capture on Demand" (Best UX without new dependencies)
Instead of a background watcher, modify
Clipboard.qmlto read the clipboard only when the user opens the history menu (Super+Ctrl+V).2. Opt-In Toggle
Restore the watcher but put it behind a toggle (e.g.
omarchy toggle image-clipboard-history).3. Native Wayland Daemon
Integrate a native Wayland data-control daemon (like
cliphistorwl-clip-persist) that is explicitly designed to safely proxy and store clipboard file descriptors without destroying the offer for the user.