More improvements

This commit is contained in:
daxpedda 2021-03-10 21:28:59 +01:00
parent 40e3e94b0b
commit 25e67b760b
No known key found for this signature in database
GPG key ID: 43D62A3EA388E46F
3 changed files with 57 additions and 108 deletions

54
examples/big_file.rs Normal file
View file

@ -0,0 +1,54 @@
use rand::distributions::{Alphanumeric, Distribution};
use window_clipboard::Clipboard;
use winit::{
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};
fn main() {
let mut rng = rand::thread_rng();
let data: String = Alphanumeric
.sample_iter(&mut rng)
.take(10_000_000)
.map(char::from)
.collect();
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("Press G to start the test!")
.build(&event_loop)
.unwrap();
let mut clipboard =
Clipboard::connect(&window).expect("Connect to clipboard");
clipboard.write(data.clone()).unwrap();
event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::G),
state: ElementState::Released,
..
},
..
},
..
} => {
let new_data = clipboard.read().expect("Read data");
assert_eq!(data, new_data, "Data is equal");
println!("Data copied successfully!");
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
});
}