X11: Fix events not being reported when using run_return (#1245)

* X11: Fix events not being reported using `run_return`

* Adapt examples to be more practical

* Add CHANGELOG entry
This commit is contained in:
Murarth 2019-11-10 11:24:43 -07:00 committed by Hal Gentz
parent c66784995d
commit 1ed15c7ec7
5 changed files with 88 additions and 78 deletions

View file

@ -17,7 +17,10 @@ fn main() {
let timer_length = Duration::new(1, 0);
event_loop.run(move |event, _, control_flow| {
println!("{:?}", event);
if let Event::WindowEvent { event, .. } = &event {
// Print only Window events to reduce noise
println!("{:?}", event);
}
match event {
Event::NewEvents(StartCause::Init) => {

View file

@ -9,6 +9,7 @@
target_os = "openbsd"
))]
fn main() {
use std::{thread::sleep, time::Duration};
use winit::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
@ -17,36 +18,38 @@ fn main() {
};
let mut event_loop = EventLoop::new();
let window = WindowBuilder::new()
let _window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
println!("Close the window to continue.");
event_loop.run_return(|event, _, control_flow| match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
});
drop(window);
let mut quit = false;
let _window_2 = WindowBuilder::new()
.with_title("A second, fantasticer window!")
.build(&event_loop)
.unwrap();
while !quit {
event_loop.run_return(|event, _, control_flow| {
if let Event::WindowEvent { event, .. } = &event {
// Print only Window events to reduce noise
println!("{:?}", event);
}
println!("Wa ha ha! You thought that closing the window would finish this?!");
event_loop.run_return(|event, _, control_flow| match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
});
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
quit = true;
*control_flow = ControlFlow::Exit;
}
Event::EventsCleared => {
*control_flow = ControlFlow::Exit;
}
_ => *control_flow = ControlFlow::Wait,
}
});
println!("Okay we're done now for real.");
// Sleep for 1/60 second to simulate rendering
sleep(Duration::from_millis(16));
}
}
#[cfg(any(target_os = "ios", target_os = "android", target_arch = "wasm32"))]