Skip to content

Skip the X11 clipboard manager handover when no manager is running - #246

Open
RaphaelFakhri wants to merge 2 commits into
1Password:masterfrom
RaphaelFakhri:fix-x11-handover-without-manager
Open

RaphaelFakhri wants to merge 2 commits into
1Password:masterfrom
RaphaelFakhri:fix-x11-handover-without-manager

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 24, 2026 •

Copy link
Copy Markdown

Summary

When a Clipboard that owns the CLIPBOARD selection is dropped on X11, arboard asks the clipboard manager to save the contents by converting the CLIPBOARD_MANAGER selection to SAVE_TARGETS. If no clipboard manager is running, nothing owns CLIPBOARD_MANAGER, so the X server immediately answers with a refused SelectionNotify. arboard then waits for a content request that never arrives, which:

  • blocks the drop for the full 100 ms handover timeout, and
  • logs Could not hand the clipboard contents over to the clipboard manager. The request timed out. even though there was nothing to hand over to.

This happens on every drop under window managers without a clipboard manager, as reported in #226.

The ClipboardManager specification states that clipboard persistence is unavailable when CLIPBOARD_MANAGER has no owner. This change checks the owner first and skips the handover when there is none. The behavior with a running clipboard manager is unchanged.

Related to #226. The all_tests persistence check in that report still requires a clipboard manager, because without one nothing can keep the contents after the owner exits.

Testing

The fix has no automated test, because the X server can't be mocked and Clipboard::new uses the global clipboard, which races with the other clipboard tests.

cargo fmt --all -- --check and cargo clippy --all-features -- -D warnings -D clippy::dbg_macro are clean.

Comment thread src/platform/linux/x11.rs Outdated
Comment on lines +774 to +777
// Per the `ClipboardManager` specification, if nothing owns the `CLIPBOARD_MANAGER`
// selection then no clipboard manager is running and clipboard persistence isn't
// available. The X server would reject the conversion right away, so don't wait for
// a handover that can never happen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please link an exact section of the specification or quote it directly inline.

Additionally, let's go ahead and link to the GTK clipboard implementation which performs this operation as well as a citation of correctness: https://gitlab.gnome.org/GNOME/gtk/-/blob/1ef7621a27abf0fb0f3aa719b895868b55766156/gdk/x11/gdkclipboard-x11.c#L645

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in fa56ca8. The comment now quotes both sections of the specification with links to them, and links the GTK check at gdkclipboard-x11.c#L645.

Comment thread src/platform/linux/x11.rs Outdated
Comment on lines +776 to +777
// available. The X server would reject the conversion right away, so don't wait for
// a handover that can never happen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// available. The X server would reject the conversion right away, so don't wait for
// a handover that can never happen.
// available.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied in fa56ca8.

Comment thread src/platform/linux/x11.rs Outdated
.unwrap();

let start = Instant::now();
inner.ask_clipboard_manager_to_request_our_data().unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure this test is valid because Clipboard::new uses the global clipboard and therefore may race with other clipboard tests running in parallel and being Droped (or writing to it). Its also something that is going to have variable results depending on if its running in CI or on someone's desktop.

I think its probably best to just remove it since we have no way to mock the X server itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed in fa56ca8, along with the MAX_HANDOVER_DURATION constant that only the test used. cargo fmt --check and cargo clippy --all-features -- -D warnings pass.

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.

2 participants