Skip to content

wayland, x11: add setPrimaryText and getPrimaryText - #32

Open
neurocyte wants to merge 1 commit into
ypsvlq:masterfrom
neurocyte:get-set-primary-text
Open

neurocyte wants to merge 1 commit into
ypsvlq:masterfrom
neurocyte:get-set-primary-text

Conversation

@neurocyte

Copy link
Copy Markdown
Contributor

These are noops on all other platforms.

These are noops on all other platforms.
Comment thread src/unix/x11.zig
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);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread src/wio.zig
Comment on lines +214 to +221
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);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants