We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3718

Summary: [X11] [Clipboard] Clipboard text set by SDL_SetClipboardText is destroyed with the window
Product: SDL Reporter: Ethan Lee <flibitijibibo>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED DUPLICATE QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: HG 2.0   
Hardware: All   
OS: Linux   
Attachments: X11 Clipboard Test Program

Description Ethan Lee 2017-07-29 14:25:20 UTC
Created attachment 2811 [details]
X11 Clipboard Test Program

Currently, in addition to the X11 clipboard implementation requiring a window (see #3222), it appears clipboard text set by SDL_SetClipboardText is tied to that window afterward. After the window is destroyed, the clipboard will be cleared as well if SDL previously set it. The test program explains it best (attached).
Comment 1 Ryan C. Gordon 2017-07-30 19:29:30 UTC
I was just looking at this too. X11 clipboards are strange, in that a window declares it has clipboard data, and when something else "pastes" it, it's actually sent on demand from the window itself. I guess this was to save resources in the 1970's?

There's a freedesktop standard that makes this work like other OSes [1], and supporting that in SDL should solve this problem. I'm going to take this bug and poke at it for a little and see if it's hard to implement.

  [1]: https://www.freedesktop.org/wiki/Specifications/clipboard-manager-spec/?action=show&redirect=Standards/clipboard-manager-spec
Comment 2 Ryan C. Gordon 2017-07-30 19:38:24 UTC
(also, X11 needs a window for clipboard access in any case; that's unavoidable. But maybe SDL can make an invisible window that handles clipboard data, unrelated to any first class SDL_Window objects that might exist. This approach would still need to implement the freedesktop spec to make clipboard data live beyond the end of the SDL process life, but it would also remove the limitation of needing an SDL_Window created at all to access the clipboard. That seems like the right thing to do, but we'll deal with that aspect over in Bug #3222.)

--ryan.
Comment 3 Ryan C. Gordon 2017-07-31 03:24:00 UTC
Hmm, I can Google out a few clients that support SAVE_TARGETS (the freedesktop spec), but I can't find any clipboard managers that do.

That spec is a 0.1 release from 2005, so I suppose it just sort of died. Clipboard managers can still do their work without this spec, so I guess it's not clear why it's useful anyhow...I guess as a protocol for blocking until a clipboard manager confirms the selection has transferred, so it isn't lost on process shutdown?

So the solution is going to be:
- Move SDL clipboard stuff to an unmapped window that exists just to manage the clipboard, so the clipboard doesn't vanish with a random SDL window.
- Users that want X11 selections to live past the borders of process lives should be running a clipboard manager daemon. I don't understand why Ubuntu doesn't install one of these by default (launch Terminal on Ubuntu, copy text, close every Terminal window, try to paste the text...it's gone.)

Since the separate task from Bug #3222 isn't valid anymore, I'm going to mark this as a duplicate and set up the unmapped clipboard window code on that bug.

--ryan.

*** This bug has been marked as a duplicate of bug 3222 ***
Comment 4 Ryan C. Gordon 2017-08-02 14:22:35 UTC
(As of https://hg.libsdl.org/SDL/rev/3767cdd2d64b, X11 clipboard data isn't tied to any SDL_Window, so this is good to go now.)

--ryan.