diff --git a/Cargo.toml b/Cargo.toml index 3bdacff..0c04c4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,11 @@ keywords = ["clipboard", "window", "ui", "gui", "raw-window-handle"] categories = ["gui"] [dependencies] -raw-window-handle = "0.5" +raw-window-handle = { version = "0.6", features = ["std"] } thiserror = "1.0" [target.'cfg(windows)'.dependencies] -clipboard-win = { version = "4.0", features = ["std"] } +clipboard-win = { version = "5.0", features = ["std"] } [target.'cfg(target_os = "macos")'.dependencies] clipboard_macos = { version = "0.1", path = "./macos" } @@ -27,7 +27,7 @@ clipboard_wayland = { version = "0.2", path = "./wayland" } [dev-dependencies] rand = "0.8" -winit = "0.28" +winit = "0.29" [workspace] members = [ diff --git a/examples/big_file.rs b/examples/big_file.rs index 9584b72..f666812 100644 --- a/examples/big_file.rs +++ b/examples/big_file.rs @@ -1,12 +1,14 @@ use rand::distributions::{Alphanumeric, Distribution}; use window_clipboard::Clipboard; use winit::{ - event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, + error::EventLoopError, + event::{ElementState, Event, KeyEvent, WindowEvent}, + event_loop::EventLoop, + keyboard::Key, window::WindowBuilder, }; -fn main() { +fn main() -> Result<(), EventLoopError> { let mut rng = rand::thread_rng(); let data: String = Alphanumeric @@ -15,7 +17,7 @@ fn main() { .map(char::from) .collect(); - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); let window = WindowBuilder::new() .with_title("Press G to start the test!") @@ -23,24 +25,24 @@ 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(); - event_loop.run(move |event, _, control_flow| match event { + event_loop.run(move |event, elwt| match event { Event::WindowEvent { event: WindowEvent::KeyboardInput { - input: - KeyboardInput { - virtual_keycode: Some(VirtualKeyCode::G), + event: + KeyEvent { + logical_key: Key::Character(c), state: ElementState::Released, .. }, .. }, .. - } => { + } if c == "G" => { let new_data = clipboard.read().expect("Read data"); assert_eq!(data, new_data, "Data is equal"); println!("Data copied successfully!"); @@ -48,7 +50,7 @@ fn main() { Event::WindowEvent { event: WindowEvent::CloseRequested, window_id, - } if window_id == window.id() => *control_flow = ControlFlow::Exit, - _ => *control_flow = ControlFlow::Wait, - }); + } if window_id == window.id() => elwt.exit(), + _ => {} + }) } diff --git a/examples/read.rs b/examples/read.rs index 6839347..ddbaf8b 100644 --- a/examples/read.rs +++ b/examples/read.rs @@ -1,28 +1,30 @@ use window_clipboard::Clipboard; use winit::{ + error::EventLoopError, event::{Event, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, + event_loop::EventLoop, window::WindowBuilder, }; -fn main() { - let event_loop = EventLoop::new(); +fn main() -> Result<(), EventLoopError> { + let event_loop = EventLoop::new().unwrap(); let window = WindowBuilder::new() .with_title("A fantastic window!") .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, _, control_flow| match event { - Event::MainEventsCleared => { + event_loop.run(move |event, elwt| match event { + Event::AboutToWait => { println!("{:?}", clipboard.read()); } Event::WindowEvent { event: WindowEvent::CloseRequested, window_id, - } if window_id == window.id() => *control_flow = ControlFlow::Exit, - _ => *control_flow = ControlFlow::Wait, - }); + } if window_id == window.id() => elwt.exit(), + _ => {} + }) } diff --git a/examples/write.rs b/examples/write.rs index b72fed6..40e6263 100644 --- a/examples/write.rs +++ b/examples/write.rs @@ -1,12 +1,13 @@ use window_clipboard::Clipboard; use winit::{ + error::EventLoopError, event::{Event, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, + event_loop::EventLoop, window::WindowBuilder, }; -fn main() { - let event_loop = EventLoop::new(); +fn main() -> Result<(), EventLoopError> { + let event_loop = EventLoop::new().unwrap(); let window = WindowBuilder::new() .with_title("A fantastic window!") @@ -14,18 +15,17 @@ 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!")) .expect("Write to clipboard"); - event_loop.run(move |event, _, control_flow| match event { - Event::MainEventsCleared => {} + event_loop.run(move |event, elwt| match event { Event::WindowEvent { event: WindowEvent::CloseRequested, window_id, - } if window_id == window.id() => *control_flow = ControlFlow::Exit, - _ => *control_flow = ControlFlow::Wait, - }); + } if window_id == window.id() => elwt.exit(), + _ => {} + }) } 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 16aa8c4..02b6da9 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -1,21 +1,17 @@ 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() { + let clipboard = match window.display_handle()?.as_raw() { RawDisplayHandle::Wayland(handle) => { - assert!(!handle.display.is_null()); - - Box::new(unsafe { - wayland::Clipboard::connect(handle.display as *mut _) - }) as _ + 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)) diff --git a/wayland/Cargo.toml b/wayland/Cargo.toml index 70386c5..f3ae126 100644 --- a/wayland/Cargo.toml +++ b/wayland/Cargo.toml @@ -10,4 +10,4 @@ documentation = "https://docs.rs/clipboard_wayland" keywords = ["clipboard", "wayland"] [dependencies] -smithay-clipboard = "0.6" +smithay-clipboard = "0.7" diff --git a/x11/Cargo.toml b/x11/Cargo.toml index 8fa396e..cbfc18e 100644 --- a/x11/Cargo.toml +++ b/x11/Cargo.toml @@ -10,5 +10,5 @@ documentation = "https://docs.rs/clipboard_x11" keywords = ["clipboard", "x11"] [dependencies] -x11rb = "0.11" +x11rb = "0.13" thiserror = "1.0"