diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index d7be4fd2..6b1cc470 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -576,8 +576,8 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); /* Clipboard */ -GLFWAPI void glfwSetClipboardString(const char* data); -GLFWAPI size_t glfwGetClipboardString(char* data, size_t size); +GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* data); +GLFWAPI size_t glfwGetClipboardString(GLFWwindow window, char* data, size_t size); /* Time */ GLFWAPI double glfwGetTime(void); diff --git a/src/clipboard.c b/src/clipboard.c index a816ebb0..b66d5656 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -41,15 +41,17 @@ // Set the clipboard contents //======================================================================== -GLFWAPI void glfwSetClipboardString(const char* string) +GLFWAPI void glfwSetClipboardString(GLFWwindow handle, const char* string) { + _GLFWwindow* window = (_GLFWwindow*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return; } - _glfwPlatformSetClipboardString(string); + _glfwPlatformSetClipboardString(window, string); } @@ -57,8 +59,10 @@ GLFWAPI void glfwSetClipboardString(const char* string) // Return the current clipboard contents //======================================================================== -GLFWAPI size_t glfwGetClipboardString(char* string, size_t size) +GLFWAPI size_t glfwGetClipboardString(GLFWwindow handle, char* string, size_t size) { + _GLFWwindow* window = (_GLFWwindow*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); @@ -68,6 +72,6 @@ GLFWAPI size_t glfwGetClipboardString(char* string, size_t size) if (!string || !size) return 0; - return _glfwPlatformGetClipboardString(string, size); + return _glfwPlatformGetClipboardString(window, string, size); } diff --git a/src/internal.h b/src/internal.h index 2e0b9c38..407270ea 100644 --- a/src/internal.h +++ b/src/internal.h @@ -289,8 +289,8 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp); void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp); // Clipboard -void _glfwPlatformSetClipboardString(const char* string); -size_t _glfwPlatformGetClipboardString(char *data, size_t size); +void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string); +size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char *data, size_t size); // Joystick int _glfwPlatformGetJoystickParam(int joy, int param); diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index b733b486..4bbfb83c 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -93,7 +93,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) // Set the clipboard contents //======================================================================== -void _glfwPlatformSetClipboardString(const char* string) +void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { size_t size = strlen(string) + 1; @@ -115,10 +115,10 @@ void _glfwPlatformSetClipboardString(const char* string) // Set the selection owner to our active window XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, - _glfwLibrary.activeWindow->X11.handle, CurrentTime); + window->X11.handle, CurrentTime); XSetSelectionOwner(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, - _glfwLibrary.activeWindow->X11.handle, CurrentTime); + window->X11.handle, CurrentTime); XFlush(_glfwLibrary.X11.display); } @@ -127,16 +127,13 @@ void _glfwPlatformSetClipboardString(const char* string) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardString(char* data, size_t size) +size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* data, size_t size) { size_t len, rembytes, dummy; unsigned char* d; int i, fmt; Atom type; - // Get the currently active window - Window window = _glfwLibrary.activeWindow->X11.handle; - for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++) { // Specify the format we would like. @@ -147,7 +144,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size) XConvertSelection(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, _glfwLibrary.X11.selection.request, - None, window, CurrentTime); + None, window->X11.handle, CurrentTime); XFlush(_glfwLibrary.X11.display); // Process pending events until we get a SelectionNotify. @@ -176,7 +173,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size) // Check the length of data to receive (rembytes) XGetWindowProperty(_glfwLibrary.X11.display, - window, + window->X11.handle, _glfwLibrary.X11.selection.request, 0, 0, 0, @@ -190,7 +187,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size) if (rembytes > 0) { int result = XGetWindowProperty(_glfwLibrary.X11.display, - window, + window->X11.handle, _glfwLibrary.X11.selection.request, 0, rembytes, 0, diff --git a/tests/clipboard.c b/tests/clipboard.c index ac83448b..376ebbcd 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -64,7 +64,7 @@ static void key_callback(GLFWwindow window, int key, int action) printf("Paste test.\n"); - size = glfwGetClipboardString(buffer, sizeof(buffer)); + size = glfwGetClipboardString(window, buffer, sizeof(buffer)); if (size >= sizeof(buffer)) printf("Buffer wasn't big enough to hold clipboard data.\n"); @@ -76,7 +76,7 @@ static void key_callback(GLFWwindow window, int key, int action) if (control_is_down(window)) { const char* string = "Hello GLFW World!"; - glfwSetClipboardString(string); + glfwSetClipboardString(window, string); printf("Setting clipboard to: %s\n", string); } break;