-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use copypasta for clipboard handling
- Loading branch information
1 parent
4340303
commit 08dae8f
Showing
5 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use raw_window_handle::RawDisplayHandle; | ||
|
||
#[cfg(not(any(target_os = "macos", windows)))] | ||
use copypasta::{ | ||
wayland_clipboard, | ||
x11_clipboard::{Primary as X11SelectionClipboard, X11ClipboardContext}, | ||
}; | ||
|
||
use copypasta::{ClipboardContext, ClipboardProvider}; | ||
|
||
pub struct Clipboard { | ||
pub clipboard: Box<dyn ClipboardProvider>, | ||
pub selection: Option<Box<dyn ClipboardProvider>>, | ||
} | ||
|
||
impl Clipboard { | ||
pub unsafe fn new(display: RawDisplayHandle) -> Self { | ||
#[cfg(not(any(target_os = "macos", windows)))] | ||
if let RawDisplayHandle::Wayland(display) = display { | ||
let (selection, clipboard) = | ||
wayland_clipboard::create_clipboards_from_external(display.display); | ||
return Self { | ||
clipboard: Box::new(clipboard), | ||
selection: Some(Box::new(selection)), | ||
}; | ||
} | ||
|
||
#[cfg(not(any(target_os = "macos", windows)))] | ||
return Self { | ||
clipboard: Box::new(ClipboardContext::new().unwrap()), | ||
selection: Some(Box::new( | ||
X11ClipboardContext::<X11SelectionClipboard>::new().unwrap(), | ||
)), | ||
}; | ||
|
||
#[cfg(any(target_os = "macos", windows))] | ||
return Self { | ||
clipboard: Box::new(ClipboardContext::new().unwrap()), | ||
selection: None, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters