Trait arboard::SetExtLinux

source ·
pub trait SetExtLinux: Sealed {
    // Required methods
    fn wait(self) -> Self;
    fn wait_until(self, deadline: Instant) -> Self;
    fn clipboard(self, selection: LinuxClipboardKind) -> Self;
}
Expand description

Linux specific extensions to the Set builder.

Required Methods§

source

fn wait(self) -> Self

Whether to wait for the clipboard’s contents to be replaced after setting it.

The Wayland and X11 clipboards work by having the clipboard content being, at any given time, “owned” by a single process, and that process is expected to reply to all the requests from any other system process that wishes to access the clipboard’s contents. As a consequence, when that process exits the contents of the clipboard will effectively be cleared since there is no longer anyone around to serve requests for it.

This poses a problem for short-lived programs that just want to copy to the clipboard and then exit, since they don’t want to wait until the user happens to copy something else just to finish. To resolve that, whenever the user copies something you can offload the actual work to a newly-spawned daemon process which will run in the background (potentially outliving the current process) and serve all the requests. That process will then automatically and silently exit once the user copies something else to their clipboard so it doesn’t take up too many resources.

To support that pattern, this method will not only have the contents of the clipboard be set, but will also wait and continue to serve requests until the clipboard is overwritten. As long as you don’t exit the current process until that method has returned, you can avoid all surprising situations where the clipboard’s contents seemingly disappear from under your feet.

See the daemonize example for a demo of how you could implement this.

source

fn wait_until(self, deadline: Instant) -> Self

Whether or not to wait for the clipboard’s content to be replaced after setting it. This waits until the deadline has exceeded.

This is useful for short-lived programs so it won’t block until new contents on the clipboard were added.

Note: this is a superset of wait() and will overwrite any state that was previously set using it.

source

fn clipboard(self, selection: LinuxClipboardKind) -> Self

Sets the clipboard the operation will store its data to.

If wayland support is enabled and available, attempting to use the Secondary clipboard will return an error.

§Examples
use arboard::{Clipboard, SetExtLinux, LinuxClipboardKind};
let mut ctx = Clipboard::new()?;

let clipboard = "This goes in the traditional (ex. Copy & Paste) clipboard.";
ctx.set().clipboard(LinuxClipboardKind::Clipboard).text(clipboard.to_owned())?;

let primary = "This goes in the primary keyboard. It's typically used via middle mouse click.";
ctx.set().clipboard(LinuxClipboardKind::Primary).text(primary.to_owned())?;

Object Safety§

This trait is not object safe.

Implementors§