window_clipboard/examples/read.rs
Ian Douglas Scott 869737dadc Use HasDisplayHandle instead of deprecated HasRawDisplayHandle
Currently `connect` is unsafe because it doesn't take ownership of the
display or have a lifetime bound.
2024-01-16 21:37:13 -08:00

31 lines
812 B
Rust

use window_clipboard::Clipboard;
use winit::{
event::{Event, WindowEvent},
event_loop::EventLoop,
window::WindowBuilder,
};
fn main() {
let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
let clipboard =
unsafe { Clipboard::connect(&window) }.expect("Connect to clipboard");
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() => elwt.exit(),
_ => {}
})
.unwrap();
}