lagrange icon indicating copy to clipboard operation
lagrange copied to clipboard

Selected text and copied text should go to separate clipboards — standard X11 clipboard behavior

Open DrZingo opened this issue 4 years ago • 4 comments

When selecting text, you should be able to paste it into terminal (or other applications) with middle mouse click. PRIMARY clipboard should be used for this. Also when selecting text and choosing copy, when pasted into vim (terminal), vim hangs for a while, and pastes something old instead. CLIPBOARD clipboard should be used for this Tested with vim -u DEFAULTS -U NONE -i NONE

https://specifications.freedesktop.org/clipboards-spec/clipboards-latest.txt

DrZingo avatar Feb 14 '21 21:02 DrZingo

Thanks for the link, this is all news to me as a casual X11 user.

I'll have to dig into the SDL source code to see what exactly SDL_SetClipboardText() does in practice, and if there is any way to influence the behavior. Of course, there is always the option of using X11 APIs directly for this, but I would prefer a more cross-platform solution...

There is an existing command line tool: https://github.com/astrand/xclip/

That is a good resource to see how the APIs work (appears quite complex!), but one option is to simply run xclip behind the scenes when the user marks a selection, or clicks the middle button.

skyjake avatar Feb 15 '21 07:02 skyjake

To call xclip behind the scenes is fine with me, but I think xlib is the way to go if not SDL have a way to do it. I compiled this, which shows lagrange window name as "null" when copying from it. Maybe it have something to do with this? https://wahjava.wordpress.com/2006/08/05/x-cut-and-paste-aka-x-clipboard/

DrZingo avatar Feb 15 '21 21:02 DrZingo

I'll have to take a much closer look at the Xlib APIs. If it turns out to be not too complicated, it is indeed better to not call external tools just for accessing the clipboard.

skyjake avatar Feb 16 '21 07:02 skyjake

Interesting new feature in SDL 2.26:

Added SDL_SetPrimarySelectionText(), SDL_GetPrimarySelectionText(), and SDL_HasPrimarySelectionText() to interact with the X11 primary selection clipboard

skyjake avatar Nov 22 '22 04:11 skyjake