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 2266

Summary: please add notifications for clipboard updates on X11 and Android
Product: SDL Reporter: chw
Component: eventsAssignee: Sylvain <sylvain.becker>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: 2.0.1   
Hardware: x86   
OS: Linux   
Attachments: SDL2-2.0.1-x11-clipboard.patch
SDL2-2.0.1-android-clipboard.patch
SDL 2.0.1 cutbuffer type
Android patch for notifcation clipboard, with multiple API level

Description chw 2013-11-24 00:53:12 UTC
(Sorry for being PITA on bug #2258 which IMO has been closed to early): In order to make the clipboard really be usable on X11 and Android it seems to be necessary to generate SDL_CLIPBOARDUPDATE events (i.e. when the selection/clipboard has been updated from the outside world), which unfortunately are never generated for those two platforms.
Comment 1 Sam Lantinga 2013-11-24 01:20:51 UTC
Patches welcome! :)
Comment 2 chw 2013-11-24 02:20:36 UTC
Created attachment 1471 [details]
SDL2-2.0.1-x11-clipboard.patch
Comment 3 chw 2013-11-24 02:31:51 UTC
Created attachment 1472 [details]
SDL2-2.0.1-android-clipboard.patch

Hopefully deals with API version differences (Android < 3.0 etc) and deals with outside clipboard changes for Android >= 3.0 using SQL_CLIPBOARDCHANGE event.
Comment 4 Sam Lantinga 2013-11-28 11:38:54 UTC
Great, thanks!
Gabriel, can you take a look at these?
Comment 5 chw 2013-11-29 05:31:34 UTC
Created attachment 1478 [details]
SDL 2.0.1 cutbuffer type

There's another problem on X11. According to Xlib documentation CUTBUFFER_0 must be of type XA_STRING. If SDL changes this to UFT8_STRING other X11 programs may break. I've observed this with Emacs 23.x which goes in an endless loop on CentOS6.
Comment 6 Gabriel Jacobo 2013-11-29 13:18:26 UTC
The X11 patches look sane to me, assuming they work ;)

The Android patch as it is, is a no go, right at the top you are using "android.content.ClipboardManager" which isn't defined in API 10, and is not protected by a android.os.Build.VERSION.SDK_INT conditional, so I guess that will error out if you run it on an API 10 device. Also, the Android_JNI_SetClipboardText seems to be the same as in your previous patch, where I think the changes made by Philipp should make those modifications obsolete (I think!).

For this to work, you need to abstract the clipboard functionality behind two classes, SDLClipboardManager and SDLClipboardManager_API11 or whatever, inheriting from SDLClipboardManager and extending it with the listener and anything else new is available, in a similar fashion as the joystick code works.
Comment 7 Ryan C. Gordon 2015-02-19 05:22:15 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 8 Ryan C. Gordon 2015-05-27 01:28:16 UTC
(In reply to chw from comment #5)
> There's another problem on X11. According to Xlib documentation CUTBUFFER_0
> must be of type XA_STRING. If SDL changes this to UFT8_STRING other X11
> programs may break. I've observed this with Emacs 23.x which goes in an
> endless loop on CentOS6.

We had caught the second part of this patch in another bug report already, but I've applied the first piece of it in https://hg.libsdl.org/SDL/rev/12d477422f47, thanks!

--ryan.
Comment 9 Ryan C. Gordon 2015-05-27 01:32:40 UTC
(In reply to chw from comment #2)
> Created attachment 1471 [details]
> SDL2-2.0.1-x11-clipboard.patch

This is now https://hg.libsdl.org/SDL/rev/b5a26bd8b0e7, thanks!

I can't commit the Android pieces until Gabriel's concerns are resolved, but I think this resolves all the X11 issues for now.

--ryan.
Comment 10 Ryan C. Gordon 2015-05-27 03:42:59 UTC
(In reply to Ryan C. Gordon from comment #8)
> (In reply to chw from comment #5)
> > There's another problem on X11. According to Xlib documentation CUTBUFFER_0
> > must be of type XA_STRING. If SDL changes this to UFT8_STRING other X11
> > programs may break. I've observed this with Emacs 23.x which goes in an
> > endless loop on CentOS6.
> 
> We had caught the second part of this patch in another bug report already,
> but I've applied the first piece of it in
> https://hg.libsdl.org/SDL/rev/12d477422f47, thanks!

Whoops, this doesn't do what I thought it did, I've backed it out.

The other bug report I mentioned addressed this specific concern, though, and _should_ fix the problem properly (the above patch predated it). Namely, it doesn't use CUTBUFFER_0 anymore. I haven't tested emacs, but I believe the latest in SDL revision control should work with it.

--ryan.
Comment 11 Ryan C. Gordon 2015-06-04 19:56:49 UTC
Comment on attachment 1478 [details]
SDL 2.0.1 cutbuffer type


> There's another problem on X11. According to Xlib documentation CUTBUFFER_0
> must be of type XA_STRING. If SDL changes this to UFT8_STRING other X11
> programs may break. I've observed this with Emacs 23.x which goes in an
> endless loop on CentOS6.

I think we have a proper fix for this now, if you could sync up to the latest and retest Emacs:

     https://hg.libsdl.org/SDL/rev/92472fcca43f

This fixed Google Chrome freezing up when you try to paste into it from an SDL clipboard (and even works with Unicode characters), so I assume it will fix Emacs too.

If Emacs just goes into an infinite loop if it sees Unicode characters, that's an Emacs bug and they should fix it, but the problem in this particular case was very likely SDL.

(Marking the cutbuffer patch attachment as Obsolete so we don't apply it by accident again.)

--ryan.
Comment 12 Sam Lantinga 2017-08-15 04:37:49 UTC
Sylvain, when you get a chance can you take a crack at rewriting this with the multiple API level support that Gabriel was suggesting here?
Comment 13 Sylvain 2017-08-27 14:56:20 UTC
Created attachment 2896 [details]
Android patch for notifcation clipboard, with multiple API level

Hi! here's a patch for that with two class loaded regarding API level.
Test both case : before API 11 and after.

I also remove now unused GetSystemServiceFromUIThread() and minor clean-up (haptic warning prototype).
Comment 14 Sam Lantinga 2017-08-28 01:44:18 UTC
This is in, thanks!
https://hg.libsdl.org/SDL/rev/6185fb86f046