fix(linux): paste via xclip on X11 regardless of clipboard ownership - #171
Open
trouni wants to merge 1 commit into
Open
fix(linux): paste via xclip on X11 regardless of clipboard ownership#171trouni wants to merge 1 commit into
trouni wants to merge 1 commit into
Conversation
On Linux the paste path chose its clipboard tool with
`XMODE and self.is_x_clipboard_owner`, ANDing two unrelated signals.
XMODE already answers the relevant question: it is derived from
XDG_SESSION_TYPE via detect_linux_display_server(), so it is True on
X11 and XWayland. is_x_clipboard_owner() answers "does something
currently hold the CLIPBOARD selection", which says nothing about which
tool can write to it -- and `xclip -selection clipboard` does not need a
prior owner, it becomes one.
The probe runs once in __init__ and is cached for the process lifetime.
When ClipCascade starts before anything has been copied -- the normal
case for a session-scoped systemd unit ordered after
graphical-session.target -- `xclip -t TARGETS -o` exits non-zero, the
cached value is False, and every subsequent paste falls through to the
wl-copy branch. On an X11-only host wl-copy is not installed, so every
incoming clip fails for the whole session:
ERROR - Failed to execute command: [Errno 2] No such file or directory: 'wl-copy'
ERROR - Failed to copy data to clipboard: [Errno 2] ...
ERROR - Failed to convert base64 data to clipboard: [Errno 2] ...
Sync itself is healthy throughout; only the local write fails, so the
symptom is silent one-way sync until the process is restarted at a
moment when the clipboard happens to be owned.
Select the tool by display server alone, and drop the now-unused probe
from __init__.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #156. Same bug as #99 (reported March 2025, closed only because the reporter stopped using the app).
Cause
ClipboardManager.paste()picks its clipboard tool withXMODE and self.is_x_clipboard_owner(clipboard_manager.py:221and:261), which ANDs two unrelated signals:XMODEalready answers the question — it is derived fromXDG_SESSION_TYPEviadetect_linux_display_server(), so it isTrueon X11 and XWayland.is_x_clipboard_owner()answers "does something currently hold the CLIPBOARD selection". That says nothing about which tool can write to it, andxclip -selection clipboarddoes not require a prior owner — it becomes one.The probe also runs only once, in
__init__(:41), and is cached for the process lifetime. When ClipCascade starts before anything has been copied — the normal case for an autostart entry or a systemd unit ordered aftergraphical-session.target—xclip -t TARGETS -oexits non-zero, the cached value isFalse, and every subsequent paste takes thewl-copybranch for the rest of the session.On an X11-only host
wl-copyis not installed, so every inbound clip fails:Sync itself stays healthy throughout — only the local write fails — so the symptom is silent one-way sync, and launching the app manually after copying something masks it entirely. That matches the autostart-only behaviour reported in both #156 and #99.
Change
Select the tool by display server alone, in both the text and image paths, and drop the now-unused probe from
__init__.Relationship to #157
Complementary, not competing — #157 changes the probe command in
clipboard_monitor_linux.py; this changes the paste decision inclipboard_manager.py, which #157 does not touch. They do not conflict. I have left_start_clipboard_polling()'s use of the same probe (clipboard_monitor_linux.py:380) alone: it only runs when the GTK X11 path is unavailable, so I could not exercise it.Testing
On X11, forced
is_x_clipboard_owner()to returnFalse(the bug condition), calledpaste(), and confirmed it selectsxclipand the text lands in the clipboard. Byte-compiles clean, no imports orphaned, and the change is whitespace-neutral so formatting is unaffected.One thing worth a second opinion: on XWayland
XMODEis alsoTrue, so the fallback there changes fromwl-copytoxclip. That appears to be the intent givendetect_linux_display_server()deliberately maps XWayland toXMODE = True, but I only have an X11 machine and cannot verify it.