From 31cbb20ba276af45f7d5dffcb91fd231e597f6ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sat, 4 Nov 2017 21:11:58 +0100 Subject: [PATCH] Deprecate window parameter of clipboard functions --- README.md | 1 + docs/input.dox | 8 ++------ include/GLFW/glfw3.h | 4 ++-- src/cocoa_window.m | 4 ++-- src/input.c | 9 ++------- src/internal.h | 4 ++-- src/mir_window.c | 4 ++-- src/null_window.c | 4 ++-- src/win32_window.c | 4 ++-- src/wl_window.c | 4 ++-- src/x11_window.c | 4 ++-- tests/clipboard.c | 4 ++-- 12 files changed, 23 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 4048baf1..fe6a7325 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ information on what to include when reporting a bug. - Added `GLFW_OSMESA_CONTEXT_API` for creating OpenGL contexts with [OSMesa](https://www.mesa3d.org/osmesa.html) (#281) - Added `GenerateMappings.cmake` script for updating gamepad mappings +- Deprecated window parameter of clipboard string functions - Removed `GLFW_USE_RETINA` compile-time option - Removed `GLFW_USE_CHDIR` compile-time option - Removed `GLFW_USE_MENUBAR` compile-time option diff --git a/docs/input.dox b/docs/input.dox index 318d48d5..89ff9832 100644 --- a/docs/input.dox +++ b/docs/input.dox @@ -846,7 +846,7 @@ converted to one, you can retrieve it with @ref glfwGetClipboardString. See the reference documentation for the lifetime of the returned string. @code -const char* text = glfwGetClipboardString(window); +const char* text = glfwGetClipboardString(NULL); if (text) { insert_text(text); @@ -860,13 +860,9 @@ The contents of the system clipboard can be set to a UTF-8 encoded string with @ref glfwSetClipboardString. @code -glfwSetClipboardString(window, "A string with words in it"); +glfwSetClipboardString(NULL, "A string with words in it"); @endcode -The clipboard functions take a window handle argument because some window -systems require a window to communicate with the system clipboard. Any valid -window may be used. - @section path_drop Path drop input diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index bd20d9af..fc7d3cb3 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -4655,7 +4655,7 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state); * This function sets the system clipboard to the specified, UTF-8 encoded * string. * - * @param[in] window The window that will own the clipboard contents. + * @param[in] window Deprecated. Any valid window or `NULL`. * @param[in] string A UTF-8 encoded string. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref @@ -4684,7 +4684,7 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); * if its contents cannot be converted, `NULL` is returned and a @ref * GLFW_FORMAT_UNAVAILABLE error is generated. * - * @param[in] window The window that will request the clipboard contents. + * @param[in] window Deprecated. Any valid window or `NULL`. * @return The contents of the clipboard as a UTF-8 encoded string, or `NULL` * if an [error](@ref error_handling) occurred. * diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 1ee85bc6..5f2686b2 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1740,7 +1740,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) updateCursorImage(window); } -void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) +void _glfwPlatformSetClipboardString(const char* string) { NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; @@ -1750,7 +1750,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) forType:NSStringPboardType]; } -const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) +const char* _glfwPlatformGetClipboardString(void) { NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; diff --git a/src/input.c b/src/input.c index 7d9ff774..c06715aa 100644 --- a/src/input.c +++ b/src/input.c @@ -1099,21 +1099,16 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state) GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) { - _GLFWwindow* window = (_GLFWwindow*) handle; - assert(window != NULL); assert(string != NULL); _GLFW_REQUIRE_INIT(); - _glfwPlatformSetClipboardString(window, string); + _glfwPlatformSetClipboardString(string); } GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) { - _GLFWwindow* window = (_GLFWwindow*) handle; - assert(window != NULL); - _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - return _glfwPlatformGetClipboardString(window); + return _glfwPlatformGetClipboardString(); } GLFWAPI double glfwGetTime(void) diff --git a/src/internal.h b/src/internal.h index 1bfdb859..4c214638 100644 --- a/src/internal.h +++ b/src/internal.h @@ -647,8 +647,8 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode); void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp); void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); -void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string); -const char* _glfwPlatformGetClipboardString(_GLFWwindow* window); +void _glfwPlatformSetClipboardString(const char* string); +const char* _glfwPlatformGetClipboardString(void); int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode); void _glfwPlatformUpdateGamepadGUID(char* guid); diff --git a/src/mir_window.c b/src/mir_window.c index c752cdb4..fa28d0cf 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -858,13 +858,13 @@ int _glfwPlatformGetKeyScancode(int key) return _glfw.mir.scancodes[key]; } -void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) +void _glfwPlatformSetClipboardString(const char* string) { _glfwInputError(GLFW_PLATFORM_ERROR, "Mir: Unsupported function %s", __PRETTY_FUNCTION__); } -const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) +const char* _glfwPlatformGetClipboardString(void) { _glfwInputError(GLFW_PLATFORM_ERROR, "Mir: Unsupported function %s", __PRETTY_FUNCTION__); diff --git a/src/null_window.c b/src/null_window.c index 3cc3905d..11ccb4f4 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -266,11 +266,11 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) { } -void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) +void _glfwPlatformSetClipboardString(const char* string) { } -const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) +const char* _glfwPlatformGetClipboardString(void) { return NULL; } diff --git a/src/win32_window.c b/src/win32_window.c index 6d3e76cc..564a99ea 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1796,7 +1796,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) updateCursorImage(window); } -void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) +void _glfwPlatformSetClipboardString(const char* string) { int characterCount; HANDLE object; @@ -1839,7 +1839,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) CloseClipboard(); } -const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) +const char* _glfwPlatformGetClipboardString(void) { HANDLE object; WCHAR* buffer; diff --git a/src/wl_window.c b/src/wl_window.c index f0f2637e..264cf379 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1008,14 +1008,14 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) } } -void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) +void _glfwPlatformSetClipboardString(const char* string) { // TODO _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Clipboard setting not implemented yet"); } -const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) +const char* _glfwPlatformGetClipboardString(void) { // TODO _glfwInputError(GLFW_PLATFORM_ERROR, diff --git a/src/x11_window.c b/src/x11_window.c index c89d2ec5..d9d34b01 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2773,7 +2773,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) } } -void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) +void _glfwPlatformSetClipboardString(const char* string) { free(_glfw.x11.clipboardString); _glfw.x11.clipboardString = strdup(string); @@ -2791,7 +2791,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) } } -const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) +const char* _glfwPlatformGetClipboardString(void) { return getSelectionString(_glfw.x11.CLIPBOARD); } diff --git a/tests/clipboard.c b/tests/clipboard.c index a24d0c07..7281a05d 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -67,7 +67,7 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, { const char* string; - string = glfwGetClipboardString(window); + string = glfwGetClipboardString(NULL); if (string) printf("Clipboard contains \"%s\"\n", string); else @@ -79,7 +79,7 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, if (mods == MODIFIER) { const char* string = "Hello GLFW World!"; - glfwSetClipboardString(window, string); + glfwSetClipboardString(NULL, string); printf("Setting clipboard to \"%s\"\n", string); } break;