Files
magpie/internal/gui/testdata
yetone 64487d458e gui: copying on KDE Wayland no longer breaks the connection to the compositor and quits magpie (#2039, dannisun0412)
dannisun0412 runs magpie on KDE Plasma 6.6.6 (kwin_wayland, libwayland
1.24) and it quit three times in twelve minutes with "Error 22 (Invalid
argument) dispatching to Wayland display" / "Error reading events from
display: Invalid argument".

The cause is the clipboard read-back probe (clipboard_gtk3.h). It made
its own wl_data_device and, when done, called wl_data_device_destroy,
which only frees the client side. The compositor still thinks the
device is live and keeps sending it a fresh wl_data_offer on every
later copy. libwayland drops those events for the dead proxy without
reserving their new ids, so the client's id map falls behind the
server's; the next server-created object whose id lands past the gap
makes wl_map_reserve_new return EINVAL and GDK exits.

The probe now binds the data device manager at version 3 at most and
releases the device with wl_data_device_release (version 2+), so the
compositor stops sending to it. On a version-1 manager it doesn't read
back at all (returns -2, which the Go side takes as "copy held").

The probe test (testdata/clipboard_probe.c) gets an "again" mode: copy
and read back eight times, then make the compositor hand out four
offers at once (the "burst" that needs ids past the leak), then check
the process is still alive.

Run:
- Fedora 44 container with kwin_wayland --virtual (SYS_NICE),
  gtk3/webkit2gtk-4.1, go 1.26.9: with origin/main's header the probe
  died with EINVAL 6 of 6 times (primary selection on and off) and
  TestClipboardReadBack failed 3 of 3 with "Error reading events from
  display: Invalid argument"; with this change the probe stayed alive
  6 of 6 and TestClipboardReadBack passed 3 of 3. GOOS=linux go vet
  with the gtk3 build in the container was clean.
- macOS: gofmt -l clean; go vet darwin, linux nogui, windows nogui;
  go test -tags nogui ./internal/gui passed.
Not tried: a real Plasma desktop or the full app over Selkies.
2026-10-14 09:15:21 +08:00
..