From f3e39ce6808934c18bfae3309e6f3b50fc53da85 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 29 Jan 2013 02:45:08 +0100 Subject: [PATCH] Cleanup of clipboard and string atoms. --- src/x11_clipboard.c | 6 +++--- src/x11_init.c | 20 +++++++++++--------- src/x11_platform.h | 8 ++++++-- src/x11_window.c | 6 ++---- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 8f64d736..949105fa 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -88,7 +88,7 @@ Atom _glfwWriteSelection(XSelectionRequestEvent* request) if (property == None) property = _glfw.x11.selection.property; - if (request->target == _glfw.x11.selection.targets) + if (request->target == _glfw.x11.TARGETS) { // The list of supported targets was requested @@ -139,7 +139,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) // Set the specified window as owner of the selection XSetSelectionOwner(_glfw.x11.display, - _glfw.x11.selection.atom, + _glfw.x11.CLIPBOARD, window->x11.handle, CurrentTime); } @@ -155,7 +155,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) _glfw.x11.selection.target = _glfw.x11.selection.formats[i]; XConvertSelection(_glfw.x11.display, - _glfw.x11.selection.atom, + _glfw.x11.CLIPBOARD, _glfw.x11.selection.target, _glfw.x11.selection.property, window->x11.handle, CurrentTime); diff --git a/src/x11_init.c b/src/x11_init.c index cd502380..3cab2571 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -518,26 +518,28 @@ static GLboolean initDisplay(void) // Detect whether an EWMH-conformant window manager is running detectEWMH(); + // Find or create string format atoms + _glfw.x11.UTF8_STRING = + XInternAtom(_glfw.x11.display, "UTF8_STRING", False); + _glfw.x11.COMPOUND_STRING = + XInternAtom(_glfw.x11.display, "COMPOUND_STRING", False); + // Find or create selection property atom _glfw.x11.selection.property = XInternAtom(_glfw.x11.display, "GLFW_SELECTION", False); - // Find or create clipboard atom - _glfw.x11.selection.atom = - XInternAtom(_glfw.x11.display, "CLIPBOARD", False); + // Find or create standard clipboard atoms + _glfw.x11.TARGETS = XInternAtom(_glfw.x11.display, "TARGETS", False); + _glfw.x11.CLIPBOARD = XInternAtom(_glfw.x11.display, "CLIPBOARD", False); // Find or create selection target atoms _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_UTF8] = - XInternAtom(_glfw.x11.display, "UTF8_STRING", False); + _glfw.x11.UTF8_STRING; _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] = - XInternAtom(_glfw.x11.display, "COMPOUND_STRING", False); + _glfw.x11.COMPOUND_STRING; _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_STRING] = XA_STRING; - _glfw.x11.selection.targets = XInternAtom(_glfw.x11.display, - "TARGETS", - False); - return GL_TRUE; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 80f38470..61bff91f 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -132,6 +132,12 @@ typedef struct _GLFWlibraryX11 Atom NET_WM_STATE_FULLSCREEN; Atom NET_ACTIVE_WINDOW; + // Selection atoms + Atom TARGETS; + Atom CLIPBOARD; + Atom UTF8_STRING; + Atom COMPOUND_STRING; + // True if window manager supports EWMH GLboolean hasEWMH; @@ -176,11 +182,9 @@ typedef struct _GLFWlibraryX11 } timer; struct { - Atom atom; Atom formats[_GLFW_CLIPBOARD_FORMAT_COUNT]; char* string; Atom target; - Atom targets; Atom property; int status; } selection; diff --git a/src/x11_window.c b/src/x11_window.c index 1db28a59..59d6902b 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -872,8 +872,6 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) { - Atom type = XInternAtom(_glfw.x11.display, "UTF8_STRING", False); - #if defined(X_HAVE_UTF8_STRING) Xutf8SetWMProperties(_glfw.x11.display, window->x11.handle, @@ -893,7 +891,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) if (_glfw.x11.NET_WM_NAME != None) { XChangeProperty(_glfw.x11.display, window->x11.handle, - _glfw.x11.NET_WM_NAME, type, 8, + _glfw.x11.NET_WM_NAME, _glfw.x11.UTF8_STRING, 8, PropModeReplace, (unsigned char*) title, strlen(title)); } @@ -901,7 +899,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) if (_glfw.x11.NET_WM_ICON_NAME != None) { XChangeProperty(_glfw.x11.display, window->x11.handle, - _glfw.x11.NET_WM_ICON_NAME, type, 8, + _glfw.x11.NET_WM_ICON_NAME, _glfw.x11.UTF8_STRING, 8, PropModeReplace, (unsigned char*) title, strlen(title)); }