Multi platform clipboard read/write library

I’m working on a larger project that will eventually run on Linux and mac, and that larger project is a kind of a clipboard management tool just like many others out there, but since my newfould love for Zig I decided to write mine in Zig of course.

Now the big project is far from ready, but one thing I needed to have worked out is clipboard handling for Wayland/X11/Mac with a generic interface, and I came up with this:

Its still in early stages, but it’s usable to read from clipboard and write to clipboard, and it was tested on Linux (both X11 and Wayland) and Mac.

As always, all and any feedback is much aprpeciated

5 Likes

Need to add Windows.

pub const ClipboardBackend = struct {
    platform_type: PlatformType,
    wayland_backend: ?*wayland.WaylandClipboard,
    x11_backend: ?*x11.X11Clipboard,

I suggest a tagged union, with PlatformType as the tag, where the payload is the backend pointer. Then you can switch on the union instead of checking each of the two nullable pointers.

3 Likes