Skip to main content

tilo_clipboard/
caps.rs

1//! What this crate provides on each target, as data an app can query.
2
3pub use tilo_platform_caps::{Availability, availability, available};
4
5pub type Unsupported = tilo_platform_caps::Unsupported<Feature>;
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum Feature {
10    Text,
11    ReadAnytime,
12    Images,
13    PrimarySelection,
14}
15
16pub(crate) const WEB_READ: &str = "A web page reads the clipboard only while the user pastes.";
17pub(crate) const WEB_IMAGES: &str = "Tilo copies only text in the browser.";
18pub(crate) const MAC_PRIMARY: &str = "macOS has no middle-click selection.";
19pub(crate) const WEB_PRIMARY: &str = "Browsers have no middle-click selection.";
20
21impl tilo_platform_caps::Feature for Feature {
22    /// The feature's availability on Linux, macOS and the web, in that
23    /// order. A process handed no clipboard connection (neither a session nor a
24    /// launcher serves one) provides nothing: it copies nothing and pastes
25    /// nothing.
26    fn targets(self) -> [Availability; 3] {
27        use Availability::{Available, Unsupported};
28        match self {
29            Self::Text => [Available, Available, Available],
30            Self::ReadAnytime => [Available, Available, Unsupported(WEB_READ)],
31            Self::Images => [Available, Available, Unsupported(WEB_IMAGES)],
32            Self::PrimarySelection => [
33                Available,
34                Unsupported(MAC_PRIMARY),
35                Unsupported(WEB_PRIMARY),
36            ],
37        }
38    }
39}