Update examples to winit 0.29

This commit is contained in:
Ian Douglas Scott 2024-01-16 21:09:18 -08:00
parent d6224e1b03
commit 555678e6ed
4 changed files with 56 additions and 50 deletions

View file

@ -27,7 +27,7 @@ clipboard_wayland = { version = "0.2", path = "./wayland" }
[dev-dependencies]
rand = "0.8"
winit = "0.28"
winit = { version = "0.29", features = ["rwh_05"] }
[workspace]
members = [

View file

@ -1,8 +1,9 @@
use rand::distributions::{Alphanumeric, Distribution};
use window_clipboard::Clipboard;
use winit::{
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::{ControlFlow, EventLoop},
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::EventLoop,
keyboard::Key,
window::WindowBuilder,
};
@ -15,7 +16,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!")
@ -27,28 +28,30 @@ fn main() {
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,
});
event_loop
.run(move |event, elwt| match event {
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
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!");
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => elwt.exit(),
_ => {}
})
.unwrap();
}

View file

@ -1,12 +1,12 @@
use window_clipboard::Clipboard;
use winit::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
event_loop::EventLoop,
window::WindowBuilder,
};
fn main() {
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new()
.with_title("A fantastic window!")
@ -15,14 +15,16 @@ fn main() {
let clipboard = Clipboard::connect(&window).expect("Connect to clipboard");
event_loop.run(move |event, _, control_flow| match event {
Event::MainEventsCleared => {
println!("{:?}", clipboard.read());
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
});
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();
}

View file

@ -1,12 +1,12 @@
use window_clipboard::Clipboard;
use winit::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
event_loop::EventLoop,
window::WindowBuilder,
};
fn main() {
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();
let window = WindowBuilder::new()
.with_title("A fantastic window!")
@ -20,12 +20,13 @@ fn main() {
.write(String::from("Hello, world!"))
.expect("Write to clipboard");
event_loop.run(move |event, _, control_flow| match event {
Event::MainEventsCleared => {}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
});
event_loop
.run(move |event, elwt| match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => elwt.exit(),
_ => {}
})
.unwrap();
}