diff --git a/src/Window.zig b/src/Window.zig index f2348a94e..e127d8535 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -543,7 +543,7 @@ fn clipboardRead(self: *const Window, kind: u8) !void { return; } - const data = glfw.getClipboardString() catch |err| { + const data = self.windowing_system.getClipboardString() catch |err| { log.warn("error reading clipboard: {}", .{err}); return; }; @@ -591,7 +591,7 @@ fn clipboardWrite(self: *const Window, data: []const u8) !void { try dec.decode(buf, data); assert(buf[buf.len] == 0); - glfw.setClipboardString(buf) catch |err| { + self.windowing_system.setClipboardString(buf) catch |err| { log.err("error setting clipboard string err={}", .{err}); return; }; @@ -821,7 +821,7 @@ pub fn keyCallback( }; defer self.alloc.free(buf); - glfw.setClipboardString(buf) catch |err| { + self.windowing_system.setClipboardString(buf) catch |err| { log.err("error setting clipboard string err={}", .{err}); return; }; @@ -829,7 +829,7 @@ pub fn keyCallback( }, .paste_from_clipboard => { - const data = glfw.getClipboardString() catch |err| { + const data = self.windowing_system.getClipboardString() catch |err| { log.warn("error reading clipboard: {}", .{err}); return; }; diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 1a94d17a7..8e8bd58fa 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -194,6 +194,20 @@ pub const Window = struct { try self.window.setTitle(slice.ptr); } + /// Read the clipboard. The windowing system is responsible for allocating + /// a buffer as necessary. This should be a stable pointer until the next + /// time getClipboardString is called. + pub fn getClipboardString(self: *const Window) ![:0]const u8 { + _ = self; + return try glfw.getClipboardString(); + } + + /// Set the clipboard. + pub fn setClipboardString(self: *const Window, val: [:0]const u8) !void { + _ = self; + try glfw.setClipboardString(val); + } + /// The cursor position from glfw directly is in screen coordinates but /// all our interface works in pixels. fn cursorPosToPixels(self: *const Window, pos: glfw.Window.CursorPos) !glfw.Window.CursorPos {