Conversation
These are noops on all other platforms.
| internal.allocator.free(globals.clipboard_text); | ||
| globals.clipboard_text = internal.allocator.dupe(u8, text) catch ""; | ||
| _ = c.XSetSelectionOwner(globals.display, atoms.CLIPBOARD, self.window, h.CurrentTime); | ||
| _ = c.XSetSelectionOwner(globals.display, h.XA_PRIMARY, self.window, h.CurrentTime); |
There was a problem hiding this comment.
Adding XFlush is probably good here, but I think setting CLIPBOARD should also set PRIMARY. From https://specifications.freedesktop.org/clipboard/latest/:
explicit cut/copy commands (i.e. menu items, toolbar buttons) should always set CLIPBOARD to the currently-selected data (i.e. conceptually copy PRIMARY to CLIPBOARD)
explicit cut/copy commands should always set both CLIPBOARD and PRIMARY, even when copying doesn’t involve a selection (e.g. a “copy url” -option which explicitly copies an url without the url being selected first)
| pub fn setPrimaryText(self: *Window, text: []const u8) void { | ||
| self.backend.setPrimaryText(text); | ||
| } | ||
|
|
||
| pub fn getPrimaryText(self: *Window, clipboardTextFn: *const fn (?*anyopaque, []const u8) void, clipboard_text_fn_data: ?*anyopaque) void { | ||
| self.backend.getPrimaryText(clipboardTextFn, clipboard_text_fn_data); | ||
| } | ||
|
|
There was a problem hiding this comment.
Rather than add functions that are only useful on Unix, I think I would rather adapt the existing clipboard API to support the primary selection. The Wayland implementations of getClipboardText/getPrimaryText are also very similar where they might benefit from that.
Something like:
pub const Window = struct {
pub fn getClipboardText(self: *Window, text: []const u8, options: ClipboardOptions) void;
};
pub const ClipboardOptions = struct {
/// `.primary` is only supported on X11 and Wayland.
selection: enum { clipboard, primary } = .clipboard,
};
These are noops on all other platforms.