glfw: add glfw.getClipboardString

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-16 17:59:17 -07:00 committed by Stephen Gutekanst
parent d1346a5186
commit 5f423b3149

View file

@ -22,31 +22,28 @@ pub inline fn setClipboardString(value: [*c]const u8) Error!void {
try getError(); try getError();
} }
// TODO(clipboard): /// Returns the contents of the clipboard as a string.
// /// Returns the contents of the clipboard as a string. ///
// /// /// This function returns the contents of the system clipboard, if it contains or is convertible to
// /// This function returns the contents of the system clipboard, if it contains /// a UTF-8 encoded string. If the clipboard is empty or if its contents cannot be converted,
// /// or is convertible to a UTF-8 encoded string. If the clipboard is empty or /// glfw.Error.FormatUnavailable is returned.
// /// if its contents cannot be converted, null is returned and a glfw.Error.FormatUnavailable error is generated. ///
// /// /// @return The contents of the clipboard as a UTF-8 encoded string, or null if an error occurred.
// /// @param[in] window Deprecated. Any valid window or null. ///
// /// @return The contents of the clipboard as a UTF-8 encoded string, or null /// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError.
// /// if an error occurred. ///
// /// /// @pointer_lifetime The returned string is allocated and freed by GLFW. You should not free it
// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.PlatformError. /// yourself. It is valid until the next call to glfw.getClipboardString or glfw.setClipboardString
// /// /// or until the library is terminated.
// /// @pointer_lifetime The returned string is allocated and freed by GLFW. You ///
// /// should not free it yourself. It is valid until the next call to @ref /// @thread_safety This function must only be called from the main thread.
// /// glfwGetClipboardString or @ref glfwSetClipboardString, or until the library ///
// /// is terminated. /// see also: clipboard, glfwSetClipboardString
// /// pub inline fn getClipboardString() Error![*c]const u8 {
// /// @thread_safety This function must only be called from the main thread. const value = c.glfwGetClipboardString(null);
// /// try getError();
// /// see also: clipboard, glfwSetClipboardString return value;
// /// }
// ///
// /// @ingroup input
// GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window);
test "setClipboardString" { test "setClipboardString" {
const glfw = @import("main.zig"); const glfw = @import("main.zig");
@ -55,3 +52,11 @@ test "setClipboardString" {
try glfw.setClipboardString("hello mach"); try glfw.setClipboardString("hello mach");
} }
test "getClipboardString" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
_ = try glfw.getClipboardString();
}