diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 71f2f7c9..a0640873 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -142,8 +142,7 @@ void _glfwPlatformSetClipboardData(void *data, size_t size, int format) XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, _glfwLibrary.activeWindow->X11.handle, CurrentTime); XSetSelectionOwner(_glfwLibrary.X11.display, - _glfwLibrary.X11.selection.atoms.clipboard - [_GLFW_CLIPBOARD_ATOM_CLIPBOARD], + _glfwLibrary.X11.selection.atom, _glfwLibrary.activeWindow->X11.handle, CurrentTime); XFlush(_glfwLibrary.X11.display); } @@ -162,44 +161,36 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) // Try different clipboards and formats that relate to the GLFW // format with preference for more appropriate formats first - Atom *xcbrd = _glfwLibrary.X11.selection.atoms.clipboard; - Atom *xcbrdend = _glfwLibrary.X11.selection.atoms.clipboard + - _GLFW_CLIPBOARD_ATOM_COUNT; Atom *xfmt = getInternalFormat(format); Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT; // Get the currently active window Window window = _glfwLibrary.activeWindow->X11.handle; - for ( ; xcbrd != xcbrdend; xcbrd++) + for ( ; xfmt != xfmtend; xfmt++) { - for ( ; xfmt != xfmtend; xfmt++) - { - // Specify the format we would like. - _glfwLibrary.X11.selection.request = *xfmt; + // Specify the format we would like. + _glfwLibrary.X11.selection.request = *xfmt; - // Convert the selection into a format we would like. - XConvertSelection(_glfwLibrary.X11.display, *xcbrd, - *xfmt, None, window, CurrentTime); - XFlush(_glfwLibrary.X11.display); + // Convert the selection into a format we would like. + XConvertSelection(_glfwLibrary.X11.display, + _glfwLibrary.X11.selection.atom, + *xfmt, None, window, CurrentTime); + XFlush(_glfwLibrary.X11.display); - // Process pending events until we get a SelectionNotify. - while (!_glfwLibrary.X11.selection.converted) - _glfwPlatformWaitEvents(); - - // Successful? - if (_glfwLibrary.X11.selection.converted == 1) - break; - } + // Process pending events until we get a SelectionNotify. + while (!_glfwLibrary.X11.selection.converted) + _glfwPlatformWaitEvents(); // Successful? if (_glfwLibrary.X11.selection.converted == 1) - { - _glfwLibrary.X11.selection.converted = 0; break; - } } + // Successful? + if (_glfwLibrary.X11.selection.converted == 1) + _glfwLibrary.X11.selection.converted = 0; + // Unsuccessful conversion, bail with no clipboard data if (_glfwLibrary.X11.selection.converted) { diff --git a/src/x11_init.c b/src/x11_init.c index 8b832d52..f9adc7f5 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -456,13 +456,9 @@ static GLboolean initDisplay(void) // the keyboard mapping. updateKeyCodeLUT(); - // Find or create clipboard atoms - _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_PRIMARY] = - XA_PRIMARY; - _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_CLIPBOARD] = + // Find or create clipboard atom + _glfwLibrary.X11.selection.atom = XInternAtom(_glfwLibrary.X11.display, "CLIPBOARD", False); - _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_SECONDARY] = - XA_SECONDARY; // Find or create selection atoms _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_UTF8] = diff --git a/src/x11_platform.h b/src/x11_platform.h index 2e6bbc21..163fcd19 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -85,12 +85,6 @@ #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX -// Clipboard atoms -#define _GLFW_CLIPBOARD_ATOM_PRIMARY 0 -#define _GLFW_CLIPBOARD_ATOM_CLIPBOARD 1 -#define _GLFW_CLIPBOARD_ATOM_SECONDARY 2 -#define _GLFW_CLIPBOARD_ATOM_COUNT 3 - // String atoms #define _GLFW_STRING_ATOM_UTF8 0 #define _GLFW_STRING_ATOM_COMPOUND 1 @@ -236,8 +230,8 @@ typedef struct _GLFWlibraryX11 // Selection data struct { + Atom atom; struct { - Atom clipboard[_GLFW_CLIPBOARD_ATOM_COUNT]; Atom string[_GLFW_STRING_ATOM_COUNT]; } atoms; struct {