Use HasDisplayHandle instead of deprecated HasRawDisplayHandle
Currently `connect` is unsafe because it doesn't take ownership of the display or have a lifetime bound.
This commit is contained in:
parent
bf49c91331
commit
869737dadc
11 changed files with 24 additions and 22 deletions
|
|
@ -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<W: HasRawDisplayHandle>(
|
||||
pub unsafe fn connect<W: HasDisplayHandle>(
|
||||
window: &W,
|
||||
) -> Result<Box<dyn ClipboardProvider>, Box<dyn Error>> {
|
||||
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 _,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue