■ ■ ■ ■ ■ ■
alacritty/src/clipboard.rs
1 | | - | #[cfg(not(any(target_os = "macos", target_os = "windows")))] |
| 1 | + | #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] |
2 | 2 | | use std::ffi::c_void; |
3 | 3 | | |
4 | 4 | | use log::{debug, warn}; |
| skipped 2 lines |
7 | 7 | | |
8 | 8 | | #[cfg(any(test, not(any(feature = "x11", target_os = "macos", windows))))] |
9 | 9 | | use copypasta::nop_clipboard::NopClipboardContext; |
10 | | - | #[cfg(all(not(any(target_os = "macos", windows)), feature = "wayland"))] |
| 10 | + | #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] |
11 | 11 | | use copypasta::wayland_clipboard; |
12 | | - | #[cfg(all(not(any(target_os = "macos", windows)), feature = "x11"))] |
| 12 | + | #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] |
13 | 13 | | use copypasta::x11_clipboard::{Primary as X11SelectionClipboard, X11ClipboardContext}; |
14 | 14 | | #[cfg(any(feature = "x11", target_os = "macos", windows))] |
15 | 15 | | use copypasta::ClipboardContext; |
| skipped 5 lines |
21 | 21 | | } |
22 | 22 | | |
23 | 23 | | impl Clipboard { |
24 | | - | #[cfg(any(target_os = "macos", windows))] |
| 24 | + | #[cfg(any(not(feature = "wayland"), target_os = "macos", windows))] |
25 | 25 | | pub fn new() -> Self { |
26 | 26 | | Self::default() |
27 | 27 | | } |
28 | 28 | | |
29 | | - | #[cfg(not(any(target_os = "macos", windows)))] |
30 | | - | pub fn new(_display: Option<*mut c_void>) -> Self { |
31 | | - | #[cfg(feature = "wayland")] |
32 | | - | if let Some(display) = _display { |
33 | | - | let (selection, clipboard) = |
34 | | - | unsafe { wayland_clipboard::create_clipboards_from_external(display) }; |
35 | | - | return Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) }; |
| 29 | + | #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] |
| 30 | + | pub unsafe fn new(display: Option<*mut c_void>) -> Self { |
| 31 | + | match display { |
| 32 | + | Some(display) => { |
| 33 | + | let (selection, clipboard) = |
| 34 | + | wayland_clipboard::create_clipboards_from_external(display); |
| 35 | + | Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) } |
| 36 | + | }, |
| 37 | + | None => Self::default(), |
36 | 38 | | } |
37 | | - | |
38 | | - | #[cfg(feature = "x11")] |
39 | | - | return Self { |
40 | | - | clipboard: Box::new(ClipboardContext::new().unwrap()), |
41 | | - | selection: Some(Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap())), |
42 | | - | }; |
43 | | - | |
44 | | - | #[cfg(not(feature = "x11"))] |
45 | | - | return Self::new_nop(); |
46 | 39 | | } |
47 | 40 | | |
48 | 41 | | /// Used for tests and to handle missing clipboard provider when built without the `x11` |
| skipped 6 lines |
55 | 48 | | |
56 | 49 | | impl Default for Clipboard { |
57 | 50 | | fn default() -> Self { |
58 | | - | #[cfg(any(feature = "x11", target_os = "macos", windows))] |
| 51 | + | #[cfg(any(target_os = "macos", windows))] |
59 | 52 | | return Self { clipboard: Box::new(ClipboardContext::new().unwrap()), selection: None }; |
| 53 | + | |
| 54 | + | #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] |
| 55 | + | return Self { |
| 56 | + | clipboard: Box::new(ClipboardContext::new().unwrap()), |
| 57 | + | selection: Some(Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap())), |
| 58 | + | }; |
| 59 | + | |
60 | 60 | | #[cfg(not(any(feature = "x11", target_os = "macos", windows)))] |
61 | 61 | | return Self::new_nop(); |
62 | 62 | | } |
| skipped 31 lines |