From 0f351101230c485112b71c970d3f094cc8f1d5af Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 16 Oct 2021 17:56:25 -0700 Subject: [PATCH] glfw: add glfw.setClipboardString Signed-off-by: Stephen Gutekanst --- src/clipboard.zig | 53 ++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/clipboard.zig b/src/clipboard.zig index 3726b55..95e3808 100644 --- a/src/clipboard.zig +++ b/src/clipboard.zig @@ -1,25 +1,28 @@ -// TODO(clipboard): -// /// Sets the clipboard to the specified string. -// /// -// /// This function sets the system clipboard to the specified, UTF-8 encoded -// /// string. -// /// -// /// @param[in] window Deprecated. Any valid window or null. -// /// @param[in] string A UTF-8 encoded string. -// /// -// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError. -// /// -// /// @pointer_lifetime The specified string is copied before this function -// /// returns. -// /// -// /// @thread_safety This function must only be called from the main thread. -// /// -// /// see also: clipboard, glfwGetClipboardString -// /// -// /// -// /// @ingroup input -// GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); +const std = @import("std"); +const c = @import("c.zig").c; +const Error = @import("errors.zig").Error; +const getError = @import("errors.zig").getError; + +/// Sets the clipboard to the specified string. +/// +/// This function sets the system clipboard to the specified, UTF-8 encoded string. +/// +/// @param[in] string A UTF-8 encoded string. +/// +/// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError. +/// +/// @pointer_lifetime The specified string is copied before this function returns. +/// +/// @thread_safety This function must only be called from the main thread. +/// +/// see also: clipboard, glfwGetClipboardString +pub inline fn setClipboardString(value: [*c]const u8) Error!void { + c.glfwSetClipboardString(null, value); + try getError(); +} + +// TODO(clipboard): // /// Returns the contents of the clipboard as a string. // /// // /// This function returns the contents of the system clipboard, if it contains @@ -44,3 +47,11 @@ // /// // /// @ingroup input // GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window); + +test "setClipboardString" { + const glfw = @import("main.zig"); + try glfw.init(); + defer glfw.terminate(); + + try glfw.setClipboardString("hello mach"); +}