window_clipboard/examples/read.rs

31 lines
822 B
Rust
Raw Permalink Normal View History

use window_clipboard::PlatformClipboard;
2019-12-18 05:55:32 +01:00
use winit::{
error::EventLoopError,
2019-12-18 05:55:32 +01:00
event::{Event, WindowEvent},
2024-01-16 21:09:18 -08:00
event_loop::EventLoop,
2019-12-18 05:55:32 +01:00
window::WindowBuilder,
};
fn main() -> Result<(), EventLoopError> {
2024-01-16 21:09:18 -08:00
let event_loop = EventLoop::new().unwrap();
2019-12-18 05:55:32 +01:00
let window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
let clipboard = unsafe { PlatformClipboard::connect(&window) }
.expect("Connect to clipboard");
2019-12-18 05:55:32 +01:00
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(),
_ => {}
})
2019-12-18 05:55:32 +01:00
}