Skip to content

fix: use wl-copy for clipboard writes on native Wayland sessions#12536

Open
jb0421 wants to merge 2 commits into
owncloud:6from
jb0421:fix/wayland-clipboard
Open

fix: use wl-copy for clipboard writes on native Wayland sessions#12536
jb0421 wants to merge 2 commits into
owncloud:6from
jb0421:fix/wayland-clipboard

Conversation

@jb0421

@jb0421 jb0421 commented May 6, 2026

Copy link
Copy Markdown

Summary

Fixes #12534

On native Wayland sessions, QApplication::clipboard()->setText() is silently
dropped by the compositor when the ownCloud daemon has no focused surface β€” which
is always the case when the command arrives via the socket from a file manager
shell integration.

This change detects a native Wayland session via WAYLAND_DISPLAY and delegates
the clipboard write to wl-copy(1), which uses the Wayland primary selection
protocol and does not require a compositor surface.

Changes

Testing

Tested manually on Ubuntu 24.04 LTS (GNOME Wayland, Nautilus 46.4) with a locally
built client:

  • Before: right-click β†’ "Copy private link" β†’ clipboard empty
  • After: right-click β†’ "Copy private link" β†’ URL correctly pasted

Notes

wl-copy is provided by the wl-clipboard package, which is available on all
major Linux distributions and is a common dependency for Wayland clipboard tools.
If wl-copy is not installed, QProcess::startDetached silently fails and the
clipboard write is lost β€” same behaviour as before this fix.

See also: owncloud/client-desktop-shell-integration-nautilus#11 (comment)

On Wayland the ownCloud daemon has no compositor surface and never
receives keyboard focus, so QClipboard::setText() is silently dropped
by the compositor when COPY_PRIVATE_LINK is handled.

Detect a native Wayland session via WAYLAND_DISPLAY and delegate the
clipboard write to wl-copy(1), which does not require a compositor
surface.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@DeepDiver1975

Copy link
Copy Markdown
Member

Interesting approach indeed ..... requires wl-copy to be installed .... also needs to be ltested with the appimage - I guess we would need wl-copy to be packaged into the app image ...

@jb0421

jb0421 commented May 7, 2026

Copy link
Copy Markdown
Author

@DeepDiver1975 Should I create a new PR with wl-clipboard packaged into the AppImage, or do you as a Maintainer want to take over from here?

@DeepDiver1975

Copy link
Copy Markdown
Member

Should I create a new PR with wl-clipboard packaged into the AppImage

feel free to give it a shot - thank you

@jb0421 jb0421 force-pushed the fix/wayland-clipboard branch 2 times, most recently from 5d10c84 to 4e5e57e Compare May 7, 2026 19:07
On Wayland, look for wl-copy next to the application binary first
(covers self-contained builds like AppImage), then fall back to PATH.
Add BUNDLE_WL_COPY cmake option to install wl-copy alongside the client
binary during packaging.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jb0421 jb0421 force-pushed the fix/wayland-clipboard branch from 4e5e57e to b99fc81 Compare May 7, 2026 19:22
@jb0421

jb0421 commented May 12, 2026

Copy link
Copy Markdown
Author

@DeepDiver1975 Now it bundles wl-copy within the AppImage.

@dj4oC dj4oC left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a Wayland-specific clipboard write path (spawns wl-copy) for "Copy private link to clipboard" instead of always using QApplication::clipboard().

Findings

Security: Medium β€” falls back to a bare "wl-copy" resolved via $PATH when no bundled binary is found next to the app; a writable-earlier-in-PATH binary could be planted and executed with the private-link URL as an argument. Prefer a fixed system path (e.g. /usr/bin/wl-copy) or an explicit allow-list instead of trusting ambient PATH. Argument injection via URLs starting with - is a low-severity edge case (a -- separator would be cheap defense-in-depth). QProcess::startDetached is called with an argv list (not a shell string), which correctly avoids shell/command injection.

Stability: Concern β€” the branch triggers on any non-empty WAYLAND_DISPLAY, including XWayland-forced sessions (QT_QPA_PLATFORM=xcb) where the old QApplication::clipboard() path already worked; those users lose a previously-working path with no fallback. wl-copy also requires the wlr-data-control-unstable-v1 protocol, which GNOME/Mutter does not implement β€” on GNOME Wayland this silently no-ops, with no error surfaced to the user. Recommend falling back to QApplication::clipboard() when wl-copy isn't found or fails, rather than silently dropping the copy.

Performance: Clean β€” one stat() + a detached, non-blocking process spawn per user click; no UI-thread blocking, no hot loop.

Coverage: Minor gap β€” the binary-resolution logic is pure/testable but inlined in copyUrlToClipboard; no test added. Not blocking given this is UI/clipboard glue rather than sync logic.

Cross-platform check

Clean β€” change is scoped behind qgetenv("WAYLAND_DISPLAY") and if(UNIX AND NOT APPLE) in CMake; Windows/macOS unaffected.

Verdict

Changes requested

πŸ€– Automated review by Claude Code (security Β· stability Β· performance Β· coverage)


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants