1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! [`BackendKind`] + [`Capabilities`] — runtime introspection of the active
//! clipboard backend.
use bitflags::bitflags;
/// Stable identifier for the active backend.
///
/// Returned by [`Clipboard::kind`][crate::Clipboard::kind] for diagnostics,
/// status display, and feature gating without parsing strings.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BackendKind {
/// Wayland data-control protocol.
Wayland,
/// X11 selections via XCB.
X11,
/// macOS NSPasteboard.
MacOs,
/// Win32 clipboard.
Windows,
/// OSC 52 terminal escape — write-only, text-only.
Osc52,
/// In-memory test backend.
Mock,
/// SSH-aware decorator wrapping a native backend with OSC 52 fallback.
SshAware,
}
impl BackendKind {
/// Stable lowercase identifier suitable for status lines or log fields.
pub fn as_str(&self) -> &'static str {
match self {
Self::Wayland => "wayland",
Self::X11 => "x11",
Self::MacOs => "macos",
Self::Windows => "windows",
Self::Osc52 => "osc52",
Self::Mock => "mock",
Self::SshAware => "ssh-aware",
}
}
}
impl std::fmt::Display for BackendKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
bitflags! {
/// Per-backend capability flags. Returned by
/// [`Clipboard::capabilities`][crate::Clipboard::capabilities].
///
/// Callers should check the relevant flag before invoking a method that
/// might return [`ClipboardError::UnsupportedMime`][crate::ClipboardError::UnsupportedMime]
/// or [`ClipboardError::UnsupportedAsync`][crate::ClipboardError::UnsupportedAsync]
/// — capability checks are cheap, error round-trips can be expensive
/// (Wayland/X11 thread hop).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Capabilities: u32 {
/// `set` works at all (sync).
const WRITE = 1 << 0;
/// `get` works at all (sync).
const READ = 1 << 1;
/// `clear` works (sync).
const CLEAR = 1 << 2;
/// `available` returns a real, non-empty list when data is present
/// (sync).
const AVAILABLE = 1 << 3;
/// `Selection::Primary` is honored alongside `Selection::Clipboard`.
const PRIMARY = 1 << 4;
/// Image MIME types (PNG, JPEG, etc) round-trip.
const IMAGE = 1 << 5;
/// Rich-text MIME types (HTML, RTF) round-trip.
const RICH_TEXT = 1 << 6;
/// `text/uri-list` (file copy/paste) round-trips.
const URI_LIST = 1 << 7;
/// `set_async` is a real async operation (not a `ready()` wrapper).
const ASYNC_WRITE = 1 << 8;
/// `get_async` is a real async operation.
const ASYNC_READ = 1 << 9;
/// `clear_async` is a real async operation.
const ASYNC_CLEAR = 1 << 10;
/// `available_async` is a real async operation.
const ASYNC_AVAILABLE = 1 << 11;
}
}