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
//! Improved cross-platform clipboard library
//!
//! Fork of https://github.com/aweinstock314/rust-clipboard with better error handling

#[cfg(target_os="windows")]
extern crate clipboard_win;
#[cfg(target_os="linux")]
extern crate x11_clipboard;
#[cfg(target_os="macos")]
#[macro_use]
extern crate objc;
#[cfg(target_os="macos")]
extern crate objc_id;
#[cfg(target_os="macos")]
extern crate objc_foundation;

mod errors;
mod clipboard_metadata;

pub use errors::ClipboardError;
pub use clipboard_metadata::ClipboardContentType;

pub trait Clipboard {
	type Output;
	fn new() -> Result<Self::Output, ClipboardError>;
	fn get_contents(&self) -> Result<(Vec<u8>, ClipboardContentType), ClipboardError>;
	fn get_string_contents(&self) -> Result<String, ClipboardError>;
	fn set_contents(&self, contents: Vec<u8>, format: ClipboardContentType) -> Result<(), ClipboardError>;
	fn set_string_contents(&self, contents: String) -> Result<(), ClipboardError>;
}

#[cfg(target_os="windows")]
pub mod win;
#[cfg(target_os="windows")]
pub use win::WindowsClipboard as SystemClipboard;

#[cfg(target_os="linux")]
pub mod x11;
#[cfg(target_os="linux")]
pub use x11::X11Clipboard as SystemClipboard;

#[cfg(target_os="macos")]
pub mod macos;
#[cfg(target_os="macos")]
pub use macos::MacOsClipboard as SystemClipboard;