diff --git a/Cargo.toml b/Cargo.toml index 477eee2..0c04c4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["clipboard", "window", "ui", "gui", "raw-window-handle"] categories = ["gui"] [dependencies] -raw-window-handle = "0.6" +raw-window-handle = { version = "0.6", features = ["std"] } thiserror = "1.0" [target.'cfg(windows)'.dependencies] diff --git a/examples/big_file.rs b/examples/big_file.rs index ac08f92..5714059 100644 --- a/examples/big_file.rs +++ b/examples/big_file.rs @@ -24,7 +24,7 @@ fn main() { .unwrap(); let mut clipboard = - Clipboard::connect(&window).expect("Connect to clipboard"); + unsafe { Clipboard::connect(&window) }.expect("Connect to clipboard"); clipboard.write(data.clone()).unwrap(); diff --git a/examples/read.rs b/examples/read.rs index 2ef753e..f13f871 100644 --- a/examples/read.rs +++ b/examples/read.rs @@ -13,7 +13,8 @@ fn main() { .build(&event_loop) .unwrap(); - let clipboard = Clipboard::connect(&window).expect("Connect to clipboard"); + let clipboard = + unsafe { Clipboard::connect(&window) }.expect("Connect to clipboard"); event_loop .run(move |event, elwt| match event { diff --git a/examples/write.rs b/examples/write.rs index d3d8ae9..7b658cb 100644 --- a/examples/write.rs +++ b/examples/write.rs @@ -14,7 +14,7 @@ fn main() { .unwrap(); let mut clipboard = - Clipboard::connect(&window).expect("Connect to clipboard"); + unsafe { Clipboard::connect(&window) }.expect("Connect to clipboard"); clipboard .write(String::from("Hello, world!")) diff --git a/src/lib.rs b/src/lib.rs index b8e2aa6..016ed0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,7 +46,7 @@ mod platform; #[path = "platform/dummy.rs"] mod platform; -use raw_window_handle::HasRawDisplayHandle; +use raw_window_handle::HasDisplayHandle; use std::error::Error; pub struct Clipboard { @@ -54,7 +54,8 @@ pub struct Clipboard { } impl Clipboard { - pub fn connect( + /// Safety: the display handle must be valid for the lifetime of `Clipboard` + pub unsafe fn connect( window: &W, ) -> Result> { let raw = platform::connect(window)?; diff --git a/src/platform/android.rs b/src/platform/android.rs index b808911..b0ac8b6 100644 --- a/src/platform/android.rs +++ b/src/platform/android.rs @@ -1,9 +1,9 @@ use crate::ClipboardProvider; -use raw_window_handle::HasRawDisplayHandle; +use raw_window_handle::HasDisplayHandle; use std::error::Error; -pub fn connect( +pub fn connect( _window: &W, ) -> Result, Box> { Ok(Box::new(Clipboard::new()?)) diff --git a/src/platform/dummy.rs b/src/platform/dummy.rs index edb02dc..8cf7418 100644 --- a/src/platform/dummy.rs +++ b/src/platform/dummy.rs @@ -1,10 +1,10 @@ use crate::ClipboardProvider; -use raw_window_handle::HasRawDisplayHandle; +use raw_window_handle::HasDisplayHandle; struct Dummy; -pub fn connect( +pub fn connect( _window: &W, ) -> Result, Box> { Ok(Box::new(Dummy)) diff --git a/src/platform/ios.rs b/src/platform/ios.rs index b64d8ed..84ae06a 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -1,9 +1,9 @@ use crate::ClipboardProvider; -use raw_window_handle::HasRawDisplayHandle; +use raw_window_handle::HasDisplayHandle; use std::error::Error; -pub fn connect( +pub fn connect( _window: &W, ) -> Result, Box> { Ok(Box::new(Clipboard::new()?)) diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 476e80d..02b6da9 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -1,18 +1,18 @@ use crate::ClipboardProvider; -use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle}; +use raw_window_handle::{HasDisplayHandle, RawDisplayHandle}; use std::error::Error; pub use clipboard_wayland as wayland; pub use clipboard_x11 as x11; -pub fn connect( +pub unsafe fn connect( window: &W, ) -> Result, Box> { - let clipboard = match window.raw_display_handle() { - Ok(RawDisplayHandle::Wayland(handle)) => Box::new(unsafe { - wayland::Clipboard::connect(handle.display.as_ptr()) - }) as _, + let clipboard = match window.display_handle()?.as_raw() { + RawDisplayHandle::Wayland(handle) => { + Box::new(wayland::Clipboard::connect(handle.display.as_ptr())) as _ + } _ => Box::new(x11::Clipboard::connect()?) as _, }; diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 4ebecc1..5b399e0 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -1,9 +1,9 @@ use crate::ClipboardProvider; -use raw_window_handle::HasRawDisplayHandle; +use raw_window_handle::HasDisplayHandle; use std::error::Error; -pub fn connect( +pub fn connect( _window: &W, ) -> Result, Box> { Ok(Box::new(clipboard_macos::Clipboard::new()?)) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 85a9136..a0c774b 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1,11 +1,11 @@ use crate::ClipboardProvider; use clipboard_win::{get_clipboard_string, set_clipboard_string}; -use raw_window_handle::HasRawDisplayHandle; +use raw_window_handle::HasDisplayHandle; use std::error::Error; -pub fn connect( +pub fn connect( _window: &W, ) -> Result, Box> { Ok(Box::new(Clipboard))