Skip to main content

Module clipboard

Module clipboard 

Source
Expand description

The system clipboard over arboard (feature clipboard): the clipboard’s SystemBackend for files, images, HTML and text, and the primary selection on X11 and Wayland.

Experimental: may change in any release (docs/stability.md).

egui-pop’s default backend writes text through egui and reads nothing. SystemClipboardPlugin installs Arboard instead (egui_pop_api::clipboard::set_backend): a copy writes its richest standard representation, a paste reads every format the clipboard holds as one external item, and the paste key works when the clipboard holds no text (a file manager’s files, a browser’s image).

Writes (one per copy, the first it has)Reads
filestext/uri-list (file:// URIs)yes
an imageimage/pngyes
HTMLtext/html, with the text as its alternativeyes
texttext/plainyes

arboard writes one format per copy (HTML takes its text along): files win over an image, an image over HTML, HTML over text. Private types stay in the owner; a kernel wanting them on the system clipboard gives its own backend (Clipboard::system).

The platform’s path (Arboard::path, in the clipboard collector):

  • Windows (the Win32 clipboard), macOS (NSPasteboard) and X11 (selections, through x11rb) as arboard reaches them.
  • Wayland: through XWayland by default. A copy then reaches native Wayland applications only when the compositor hands XWayland’s selection over, which some do only while an X11 window has the focus. The clipboard-wayland feature adds the data-control protocol (arboard’s wayland-data-control, through wl-clipboard-rs): used where the compositor offers it (wlroots compositors, KDE Plasma), XWayland elsewhere. The core protocol, which needs the window’s input serial, is what egui-winit’s own text clipboard uses (smithay-clipboard); arboard does not.
  • The web: nothing (the module is not built for wasm32).

The primary selection (select to copy, middle-click to paste) is read and written on X11 and Wayland (clipboard::primary_text, clipboard::set_primary_text); elsewhere there is none. egui-pop’s own widgets do not use it yet (ADR 0015: opt-in, for text inputs and the code editor).

The clipboard is opened on first use, not when the plugin connects, so connecting it touches nothing (tests, catalogues).

use egui_pop_platform::clipboard::{file_uris, paths_of};

let list = file_uris(&[std::path::PathBuf::from("/tmp/a b.png")]);
assert_eq!(list, "file:///tmp/a%20b.png");
assert_eq!(paths_of(&list), [std::path::PathBuf::from("/tmp/a b.png")]);

Structs§

Arboard
The system clipboard through arboard, opened on first use.
SystemClipboardPlugin
Installs Arboard as the clipboard’s system backend when it connects, and egui’s text again when it disconnects. Needs the clipboard plugin (egui_pop_api::clipboard::ClipboardPlugin).

Constants§

PLUGIN
The plugin’s id: with it added, run_native turns eframe’s clipboard shortcuts off and the keymap runs the copy, cut and paste chords, in text fields too (egui_pop_api::clipboard::set_keymap_shortcuts).

Functions§

file_uris
Files as a URI list: one file:// URI per line, CRLF between, each byte outside the unreserved set and / percent-encoded.
paths_of
The local files of a URI list (file:// URIs; comments, other schemes and other hosts left out).