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
use crate::Context;
#[cfg(target_os = "linux")]
mod linux {
use crate::Context;
pub fn get(_ctx: &mut Context) -> Option<String> {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
let fmtname = CString::new("UTF8_STRING").unwrap();
unsafe { sapp_linux::clipboard::get_clipboard(bufname.as_ptr(), fmtname.as_ptr()) }
}
pub fn set(_ctx: &mut Context, data: &str) {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
unsafe {
sapp_linux::clipboard::claim_clipboard_ownership(bufname.as_ptr(), data.to_owned())
};
}
}
#[cfg(target_arch = "wasm32")]
mod wasm {
use crate::Context;
pub fn get(_ctx: &mut Context) -> Option<String> {
sapp_wasm::clipboard_get()
}
pub fn set(_ctx: &mut Context, data: &str) {
sapp_wasm::clipboard_set(data);
}
}
#[cfg(not(any(target_os = "linux", target_arch = "wasm32")))]
mod dummy {
use crate::Context;
pub fn get(_ctx: &mut Context) -> Option<String> {
None
}
pub fn set(_ctx: &mut Context, _data: &str) {}
}
#[cfg(not(any(target_os = "linux", target_arch = "wasm32")))]
use dummy as clipboard;
#[cfg(target_arch = "wasm32")]
use wasm as clipboard;
#[cfg(target_os = "linux")]
use linux as clipboard;
pub fn get(ctx: &mut Context) -> Option<String> {
clipboard::get(ctx)
}
pub fn set(ctx: &mut Context, data: &str) {
clipboard::set(ctx, data);
}