Skip to content

wayland: keep the clipboard alive when its surface is destroyed - #360

Open
MohamedAklamaash wants to merge 1 commit into
pop-os:masterfrom
MohamedAklamaash:fix-clipboard-survive-surface
Open

wayland: keep the clipboard alive when its surface is destroyed#360
MohamedAklamaash wants to merge 1 commit into
pop-os:masterfrom
MohamedAklamaash:fix-clipboard-survive-surface

Conversation

@MohamedAklamaash

Copy link
Copy Markdown

When a layer-shell surface, popup, or subsurface is destroyed, the wayland event loop resets the clipboard with *clipboard = Clipboard::unconnected(). That drops the window_clipboard::Clipboard and the smithay-clipboard worker serving whatever was just copied. So any app that copies to the clipboard and then closes the surface it copied from loses the offer immediately.

COSMIC's screenshot portal is the clearest case. It owns a single overlay surface, and copying to the clipboard destroys that overlay in the same batch as the copy, so the image/png offer dies a moment after it's set and nothing can paste the screenshot. See pop-os/xdg-desktop-portal-cosmic#295.

The reset isn't needed. window_clipboard only wants the wayland display handle, not the surface, and smithay-clipboard runs its own connection to serve the selection. The display outlives every surface, so a copied selection should survive the surface going away. The regular window-close path in lib.rs already does the right thing by rebinding to another window instead of dropping; only the layer/popup/subsurface destroy paths did the unconditional reset. This removes those three.

Before, copying a screenshot to the clipboard:

$ wl-paste --list-types
text/plain;charset=utf-8
UTF8_STRING
text/plain

After:

$ wl-paste --list-types
image/png
text/plain

@MohamedAklamaash

Copy link
Copy Markdown
Author

@Drakulix Can you take a look at this?

@Drakulix
Drakulix requested review from a team July 7, 2026 13:04
@mmstick

mmstick commented Jul 13, 2026

Copy link
Copy Markdown
Member

This requires a PR to the xdg-desktop-portal for QA testing to validate the change.

@wash2 wash2 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.

I don't think this will work properly, because the clipboard when in a connected state holds onto the underlying window to satisfy safety invariants from the window_clipboard crate. It needs to be dropped when a surface is destroyed, so the clipboard needs to be disconnected. To do this, we would need to make some more changes.

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.

3 participants