aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrace Yoder <grace_yoder@outlook.com>2026-07-03 19:43:26 -0600
committerGrace Yoder <grace_yoder@outlook.com>2026-07-03 20:40:06 -0600
commitc228995f20e16a97ad6baff05a0d46d3fffe3295 (patch)
tree005d5c1f517398df287269da59deeb2c35924171
parent43c454a08c7c169df5c3d3ebcd2abded8bf5fa4b (diff)
feat: added ForkOut backend and now forks out to `xclip` and `wl-copy` on linux0.1.1
-rw-r--r--build.zig.zon2
-rw-r--r--src/Clip.zig2
-rw-r--r--src/Clip/ForkOut.zig24
-rw-r--r--src/main.zig16
4 files changed, 43 insertions, 1 deletions
diff --git a/build.zig.zon b/build.zig.zon
index 0f1d653..14a1d13 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,6 +1,6 @@
.{
.name = .tpb,
- .version = "0.1.0",
+ .version = "0.1.1",
.fingerprint = 0x203a601c46df0265,
.minimum_zig_version = "0.16.0",
.paths = .{
diff --git a/src/Clip.zig b/src/Clip.zig
index 299d4c6..7a379a3 100644
--- a/src/Clip.zig
+++ b/src/Clip.zig
@@ -7,6 +7,8 @@ pub const OSC52 = @import("Clip/OSC52.zig");
pub const NSPasteboard =
if (builtin.target.os.tag == .macos) @import("Clip/NSPasteboard.zig") else void;
+pub const ForkOut = @import("Clip/ForkOut.zig");
+
// I am not sure if this is super idiomatic Zig or if this is bad practice, but
// by ensuring that all Clip backends implement the same methods, we are able
// to use the `anytype` type and we are able to have an interface that is able
diff --git a/src/Clip/ForkOut.zig b/src/Clip/ForkOut.zig
new file mode 100644
index 0000000..97c5377
--- /dev/null
+++ b/src/Clip/ForkOut.zig
@@ -0,0 +1,24 @@
+/// ForkOut Clipboard backend
+/// Fulfills `Clip` interface
+pub const ForkOut = @This();
+
+const std = @import("std");
+
+extern fn sendPB(text: [*:0]const u8) void;
+extern fn initPB() void;
+
+io: std.Io,
+
+child: std.process.Child,
+
+pub fn init(io: std.Io, argv: []const []const u8) !ForkOut {
+ return .{ .child = try std.process.spawn(io, .{ .argv = argv, .stdin = .pipe }), .io = io };
+}
+
+pub fn writeCopyBuffer(self: *ForkOut, buf: []const u8) anyerror!void {
+ try self.child.stdin.?.writeStreamingAll(self.io, buf);
+}
+
+pub fn writePasteboard(self: *ForkOut) anyerror!void {
+ self.child.stdin.?.close(self.io);
+}
diff --git a/src/main.zig b/src/main.zig
index bb0aa14..60b498d 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -42,6 +42,22 @@ pub fn main(init: std.process.Init) !void {
return;
}
+ // I don't like this but it will stay until I review how dispatch works
+ // with zig since I will probably be refactoring there
+ linux: {
+ const xdg_type = init.environ_map.get("XDG_SESSION_TYPE") orelse "";
+
+ if (std.mem.eql(u8, xdg_type, "wayland")) {
+ var clip = Clip.ForkOut.init(io, &[_][]const u8{"wl-copy"}) catch break :linux;
+ try run(io, &clip);
+ return;
+ } else if (std.mem.eql(u8, xdg_type, "x11")) {
+ var clip = Clip.ForkOut.init(io, &[_][]const u8{ "xclip", "-selection", "clipboard" }) catch break :linux;
+ try run(io, &clip);
+ return;
+ }
+ }
+
// Fallback Clipboard
var clip = try Clip.OSC52.init(alloc, io, size);
defer clip.free();