Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed bug 1599 - On X11, SDL2 should use CLIPBOARD as well as PRIMARY…
Browse files Browse the repository at this point in the history
… for copy/paste

David White 2012-09-12 13:22:52 PDT

Background: X has two main 'buffers' for copy/paste:

PRIMARY -- normally used for implicit selection of text, with middle-click to
paste
CLIPBOARD -- works with an explicit copy/paste like on other platforms.

Currently SDL2 only provides access to PRIMARY. Since CLIPBOARD is much closer
to functionality of other platforms, SDL should provide access to that instead.

The attached patch makes it so that SDL_SetClipboardText() sets both PRIMARY
and CLIPBOARD and SDL_GetClipboardText() reads from CLIPBOARD instead of
primary.
  • Loading branch information
slouken committed Sep 14, 2012
1 parent 4916f55 commit 2c3d301
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/video/x11/SDL_x11clipboard.c
Expand Up @@ -54,6 +54,7 @@ X11_SetClipboardText(_THIS, const char *text)
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
Atom format;
Window window;
Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);

/* Get the SDL window that will own the selection */
window = GetWindow(_this);
Expand All @@ -68,6 +69,11 @@ X11_SetClipboardText(_THIS, const char *text)
XA_CUT_BUFFER0, format, 8, PropModeReplace,
(const unsigned char *)text, SDL_strlen(text));

if (XA_CLIPBOARD != None &&
XGetSelectionOwner(display, XA_CLIPBOARD) != window) {
XSetSelectionOwner(display, XA_CLIPBOARD, window, CurrentTime);
}

if (XGetSelectionOwner(display, XA_PRIMARY) != window) {
XSetSelectionOwner(display, XA_PRIMARY, window, CurrentTime);
}
Expand All @@ -89,21 +95,26 @@ X11_GetClipboardText(_THIS)
unsigned long overflow;
unsigned char *src;
char *text;
Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
if (XA_CLIPBOARD == None) {
SDL_SetError("Couldn't access X clipboard");
return NULL;
}

text = NULL;

/* Get the window that holds the selection */
window = GetWindow(_this);
format = TEXT_FORMAT;
owner = XGetSelectionOwner(display, XA_PRIMARY);
owner = XGetSelectionOwner(display, XA_CLIPBOARD);
if ((owner == None) || (owner == window)) {
owner = DefaultRootWindow(display);
selection = XA_CUT_BUFFER0;
} else {
/* Request that the selection owner copy the data to our window */
owner = window;
selection = XInternAtom(display, "SDL_SELECTION", False);
XConvertSelection(display, XA_PRIMARY, format, selection, owner,
XConvertSelection(display, XA_CLIPBOARD, format, selection, owner,
CurrentTime);

/* FIXME: Should we have a timeout here? */
Expand Down

0 comments on commit 2c3d301

Please sign in to comment.