mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 13:51:30 +11:00
Move Event::RedrawRequested
to WindowEvent
(#3049)
This commit is contained in:
parent
a3cba838ea
commit
67d3fd28f7
|
@ -11,6 +11,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
- Fix window size sometimes being invalid when resizing on macOS.
|
- Fix window size sometimes being invalid when resizing on macOS.
|
||||||
- On Web, `ControlFlow::Poll` and `ControlFlow::WaitUntil` are now using the Prioritized Task Scheduling API. `setTimeout()` with a trick to circumvent throttling to 4ms is used as a fallback.
|
- On Web, `ControlFlow::Poll` and `ControlFlow::WaitUntil` are now using the Prioritized Task Scheduling API. `setTimeout()` with a trick to circumvent throttling to 4ms is used as a fallback.
|
||||||
- On Web, never return a `MonitorHandle`.
|
- On Web, never return a `MonitorHandle`.
|
||||||
|
- **Breaking:** Move `Event::RedrawRequested` to `WindowEvent::RedrawRequested`.
|
||||||
|
|
||||||
# 0.29.1-beta
|
# 0.29.1-beta
|
||||||
|
|
||||||
|
|
|
@ -72,12 +72,13 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
} => {
|
} => {
|
||||||
spawn_child_window(&parent_window, event_loop, &mut windows);
|
spawn_child_window(&parent_window, event_loop, &mut windows);
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
if let Some(window) = windows.get(&window_id) {
|
||||||
|
fill::fill_window(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else if let Event::RedrawRequested(wid) = event {
|
|
||||||
if let Some(window) = windows.get(&wid) {
|
|
||||||
fill::fill_window(window);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,9 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::AboutToWait => {
|
Event::AboutToWait => {
|
||||||
|
@ -117,9 +120,6 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
control_flow.set_exit();
|
control_flow.set_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_window_id) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,37 +22,32 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent {
|
match event {
|
||||||
event:
|
WindowEvent::KeyboardInput {
|
||||||
WindowEvent::KeyboardInput {
|
event:
|
||||||
event:
|
KeyEvent {
|
||||||
KeyEvent {
|
state: ElementState::Pressed,
|
||||||
state: ElementState::Pressed,
|
..
|
||||||
..
|
},
|
||||||
},
|
..
|
||||||
..
|
} => {
|
||||||
},
|
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
|
||||||
..
|
window.set_cursor_icon(CURSORS[cursor_idx]);
|
||||||
} => {
|
if cursor_idx < CURSORS.len() - 1 {
|
||||||
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
|
cursor_idx += 1;
|
||||||
window.set_cursor_icon(CURSORS[cursor_idx]);
|
} else {
|
||||||
if cursor_idx < CURSORS.len() - 1 {
|
cursor_idx = 0;
|
||||||
cursor_idx += 1;
|
}
|
||||||
} else {
|
|
||||||
cursor_idx = 0;
|
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
|
WindowEvent::CloseRequested => {
|
||||||
|
control_flow.set_exit();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
control_flow.set_exit();
|
|
||||||
}
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::ModifiersChanged(new) => modifiers = new.state(),
|
WindowEvent::ModifiersChanged(new) => modifiers = new.state(),
|
||||||
|
WindowEvent::RedrawRequested => fill::fill_window(&window),
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::DeviceEvent { event, .. } => match event {
|
Event::DeviceEvent { event, .. } => match event {
|
||||||
|
@ -70,7 +71,6 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::RedrawRequested(_) => fill::fill_window(&window),
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -49,7 +49,10 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => control_flow.set_exit(),
|
} => control_flow.set_exit(),
|
||||||
Event::RedrawRequested(_) => {
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
fill::fill_window(&window);
|
fill::fill_window(&window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -59,15 +59,16 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
name_windows(entered_id, switched, &window_1, &window_2);
|
name_windows(entered_id, switched, &window_1, &window_2);
|
||||||
println!("Switched!")
|
println!("Switched!")
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
if window_id == window_1.id() {
|
||||||
|
fill::fill_window(&window_1);
|
||||||
|
} else if window_id == window_2.id() {
|
||||||
|
fill::fill_window(&window_2);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::RedrawRequested(wid) => {
|
|
||||||
if wid == window_1.id() {
|
|
||||||
fill::fill_window(&window_1);
|
|
||||||
} else if wid == window_2.id() {
|
|
||||||
fill::fill_window(&window_2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,8 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, elwt, control_flow| {
|
event_loop.run(move |event, elwt, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => control_flow.set_exit(),
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
event:
|
event:
|
||||||
|
@ -155,12 +155,11 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,67 +25,64 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent { event, .. } => {
|
match event {
|
||||||
match event {
|
WindowEvent::CloseRequested => {
|
||||||
WindowEvent::CloseRequested => {
|
// `CloseRequested` is sent when the close button on the window is pressed (or
|
||||||
// `CloseRequested` is sent when the close button on the window is pressed (or
|
// through whatever other mechanisms the window manager provides for closing a
|
||||||
// through whatever other mechanisms the window manager provides for closing a
|
// window). If you don't handle this event, the close button won't actually do
|
||||||
// window). If you don't handle this event, the close button won't actually do
|
// anything.
|
||||||
// anything.
|
|
||||||
|
|
||||||
// A common thing to do here is prompt the user if they have unsaved work.
|
// A common thing to do here is prompt the user if they have unsaved work.
|
||||||
// Creating a proper dialog box for that is far beyond the scope of this
|
// Creating a proper dialog box for that is far beyond the scope of this
|
||||||
// example, so here we'll just respond to the Y and N keys.
|
// example, so here we'll just respond to the Y and N keys.
|
||||||
println!("Are you ready to bid your window farewell? [Y/N]");
|
println!("Are you ready to bid your window farewell? [Y/N]");
|
||||||
close_requested = true;
|
close_requested = true;
|
||||||
|
|
||||||
// In applications where you can safely close the window without further
|
// In applications where you can safely close the window without further
|
||||||
// action from the user, this is generally where you'd handle cleanup before
|
// action from the user, this is generally where you'd handle cleanup before
|
||||||
// closing the window. How to close the window is detailed in the handler for
|
// closing the window. How to close the window is detailed in the handler for
|
||||||
// the Y key.
|
// the Y key.
|
||||||
}
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
event:
|
|
||||||
KeyEvent {
|
|
||||||
logical_key: key,
|
|
||||||
state: ElementState::Released,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
// WARNING: Consider using `key_without_modifers()` if available on your platform.
|
|
||||||
// See the `key_binding` example
|
|
||||||
match key.as_ref() {
|
|
||||||
Key::Character("y") => {
|
|
||||||
if close_requested {
|
|
||||||
// This is where you'll want to do any cleanup you need.
|
|
||||||
println!("Buh-bye!");
|
|
||||||
|
|
||||||
// For a single-window application like this, you'd normally just
|
|
||||||
// break out of the event loop here. If you wanted to keep running the
|
|
||||||
// event loop (i.e. if it's a multi-window application), you need to
|
|
||||||
// drop the window. That closes it, and results in `Destroyed` being
|
|
||||||
// sent.
|
|
||||||
control_flow.set_exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Key::Character("n") => {
|
|
||||||
if close_requested {
|
|
||||||
println!("Your window will continue to stay by your side.");
|
|
||||||
close_requested = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
|
WindowEvent::KeyboardInput {
|
||||||
|
event:
|
||||||
|
KeyEvent {
|
||||||
|
logical_key: key,
|
||||||
|
state: ElementState::Released,
|
||||||
|
..
|
||||||
|
},
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
// WARNING: Consider using `key_without_modifers()` if available on your platform.
|
||||||
|
// See the `key_binding` example
|
||||||
|
match key.as_ref() {
|
||||||
|
Key::Character("y") => {
|
||||||
|
if close_requested {
|
||||||
|
// This is where you'll want to do any cleanup you need.
|
||||||
|
println!("Buh-bye!");
|
||||||
|
|
||||||
|
// For a single-window application like this, you'd normally just
|
||||||
|
// break out of the event loop here. If you wanted to keep running the
|
||||||
|
// event loop (i.e. if it's a multi-window application), you need to
|
||||||
|
// drop the window. That closes it, and results in `Destroyed` being
|
||||||
|
// sent.
|
||||||
|
control_flow.set_exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Key::Character("n") => {
|
||||||
|
if close_requested {
|
||||||
|
println!("Your window will continue to stay by your side.");
|
||||||
|
close_requested = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
100
examples/ime.rs
100
examples/ime.rs
|
@ -41,69 +41,55 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent {
|
match event {
|
||||||
event: WindowEvent::CloseRequested,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||||
..
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
} => *control_flow = ControlFlow::Exit,
|
cursor_position = position;
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CursorMoved { position, .. },
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
cursor_position = position;
|
|
||||||
}
|
|
||||||
Event::WindowEvent {
|
|
||||||
event:
|
|
||||||
WindowEvent::MouseInput {
|
|
||||||
state: ElementState::Released,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
println!(
|
|
||||||
"Setting ime position to {}, {}",
|
|
||||||
cursor_position.x, cursor_position.y
|
|
||||||
);
|
|
||||||
ime_pos = cursor_position;
|
|
||||||
if may_show_ime {
|
|
||||||
window.set_ime_cursor_area(ime_pos, PhysicalSize::new(10, 10));
|
|
||||||
}
|
}
|
||||||
}
|
WindowEvent::MouseInput {
|
||||||
Event::WindowEvent {
|
state: ElementState::Released,
|
||||||
event: WindowEvent::Ime(event),
|
..
|
||||||
..
|
} => {
|
||||||
} => {
|
println!(
|
||||||
println!("{event:?}");
|
"Setting ime position to {}, {}",
|
||||||
may_show_ime = event != Ime::Disabled;
|
cursor_position.x, cursor_position.y
|
||||||
if may_show_ime {
|
);
|
||||||
window.set_ime_cursor_area(ime_pos, PhysicalSize::new(10, 10));
|
ime_pos = cursor_position;
|
||||||
|
if may_show_ime {
|
||||||
|
window.set_ime_cursor_area(ime_pos, PhysicalSize::new(10, 10));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
WindowEvent::Ime(event) => {
|
||||||
Event::WindowEvent {
|
println!("{event:?}");
|
||||||
event: WindowEvent::KeyboardInput { event, .. },
|
may_show_ime = event != Ime::Disabled;
|
||||||
..
|
if may_show_ime {
|
||||||
} => {
|
window.set_ime_cursor_area(ime_pos, PhysicalSize::new(10, 10));
|
||||||
println!("key: {event:?}");
|
}
|
||||||
|
}
|
||||||
|
WindowEvent::KeyboardInput { event, .. } => {
|
||||||
|
println!("key: {event:?}");
|
||||||
|
|
||||||
if event.state == ElementState::Pressed && event.physical_key == KeyCode::F2 {
|
if event.state == ElementState::Pressed && event.physical_key == KeyCode::F2 {
|
||||||
ime_allowed = !ime_allowed;
|
ime_allowed = !ime_allowed;
|
||||||
window.set_ime_allowed(ime_allowed);
|
window.set_ime_allowed(ime_allowed);
|
||||||
println!("\nIME allowed: {ime_allowed}\n");
|
println!("\nIME allowed: {ime_allowed}\n");
|
||||||
|
}
|
||||||
|
if event.state == ElementState::Pressed && event.logical_key == Key::F3 {
|
||||||
|
ime_purpose = match ime_purpose {
|
||||||
|
ImePurpose::Normal => ImePurpose::Password,
|
||||||
|
ImePurpose::Password => ImePurpose::Terminal,
|
||||||
|
_ => ImePurpose::Normal,
|
||||||
|
};
|
||||||
|
window.set_ime_purpose(ime_purpose);
|
||||||
|
println!("\nIME purpose: {ime_purpose:?}\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if event.state == ElementState::Pressed && event.logical_key == Key::F3 {
|
WindowEvent::RedrawRequested => {
|
||||||
ime_purpose = match ime_purpose {
|
fill::fill_window(&window);
|
||||||
ImePurpose::Normal => ImePurpose::Password,
|
|
||||||
ImePurpose::Password => ImePurpose::Terminal,
|
|
||||||
_ => ImePurpose::Normal,
|
|
||||||
};
|
|
||||||
window.set_ime_purpose(ime_purpose);
|
|
||||||
println!("\nIME purpose: {ime_purpose:?}\n");
|
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||||
WindowEvent::ModifiersChanged(new) => {
|
WindowEvent::ModifiersChanged(new) => {
|
||||||
modifiers = new.state();
|
modifiers = new.state();
|
||||||
|
@ -54,12 +54,11 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,8 @@ In other words, the deltas indicate the direction in which to move the content (
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => control_flow.set_exit(),
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
WindowEvent::MouseWheel { delta, .. } => match delta {
|
WindowEvent::MouseWheel { delta, .. } => match delta {
|
||||||
winit::event::MouseScrollDelta::LineDelta(x, y) => {
|
winit::event::MouseScrollDelta::LineDelta(x, y) => {
|
||||||
|
@ -57,12 +57,11 @@ In other words, the deltas indicate the direction in which to move the content (
|
||||||
window.set_outer_position(pos)
|
window.set_outer_position(pos)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,42 +29,39 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, event_loop, control_flow| {
|
event_loop.run(move |event, event_loop, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, window_id } = event {
|
||||||
Event::WindowEvent { event, window_id } => {
|
match event {
|
||||||
match event {
|
WindowEvent::CloseRequested => {
|
||||||
WindowEvent::CloseRequested => {
|
println!("Window {window_id:?} has received the signal to close");
|
||||||
println!("Window {window_id:?} has received the signal to close");
|
|
||||||
|
|
||||||
// This drops the window, causing it to close.
|
// This drops the window, causing it to close.
|
||||||
windows.remove(&window_id);
|
windows.remove(&window_id);
|
||||||
|
|
||||||
if windows.is_empty() {
|
if windows.is_empty() {
|
||||||
control_flow.set_exit();
|
control_flow.set_exit();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput {
|
}
|
||||||
event:
|
WindowEvent::KeyboardInput {
|
||||||
KeyEvent {
|
event:
|
||||||
state: ElementState::Pressed,
|
KeyEvent {
|
||||||
logical_key: Key::Character(c),
|
state: ElementState::Pressed,
|
||||||
..
|
logical_key: Key::Character(c),
|
||||||
},
|
..
|
||||||
is_synthetic: false,
|
},
|
||||||
..
|
is_synthetic: false,
|
||||||
} if matches!(c.as_ref(), "n" | "N") => {
|
..
|
||||||
let window = Window::new(event_loop).unwrap();
|
} if matches!(c.as_ref(), "n" | "N") => {
|
||||||
println!("Opened a new window: {:?}", window.id());
|
let window = Window::new(event_loop).unwrap();
|
||||||
windows.insert(window.id(), window);
|
println!("Opened a new window: {:?}", window.id());
|
||||||
|
windows.insert(window.id(), window);
|
||||||
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
if let Some(window) = windows.get(&window_id) {
|
||||||
|
fill::fill_window(window);
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(window_id) => {
|
|
||||||
if let Some(window) = windows.get(&window_id) {
|
|
||||||
fill::fill_window(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
|
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => control_flow.set_exit(),
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
WindowEvent::MouseInput {
|
WindowEvent::MouseInput {
|
||||||
state: ElementState::Released,
|
state: ElementState::Released,
|
||||||
|
@ -33,13 +33,12 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
} => {
|
} => {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
println!("\nredrawing!\n");
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
println!("\nredrawing!\n");
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,10 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => control_flow.set_exit(),
|
} => control_flow.set_exit(),
|
||||||
Event::RedrawRequested(_) => {
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
println!("\nredrawing!\n");
|
println!("\nredrawing!\n");
|
||||||
fill::fill_window(&window);
|
fill::fill_window(&window);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => control_flow.set_exit(),
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
event:
|
event:
|
||||||
|
@ -46,12 +46,11 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
println!("Resizable: {resizable}");
|
println!("Resizable: {resizable}");
|
||||||
window.set_resizable(resizable);
|
window.set_resizable(resizable);
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,56 +36,49 @@ mod example {
|
||||||
match event {
|
match event {
|
||||||
Event::Resumed => create_first_window = true,
|
Event::Resumed => create_first_window = true,
|
||||||
|
|
||||||
Event::WindowEvent {
|
Event::WindowEvent { window_id, event } => match event {
|
||||||
window_id,
|
WindowEvent::KeyboardInput {
|
||||||
event:
|
event:
|
||||||
WindowEvent::KeyboardInput {
|
KeyEvent {
|
||||||
event:
|
logical_key,
|
||||||
KeyEvent {
|
state: ElementState::Pressed,
|
||||||
logical_key,
|
..
|
||||||
state: ElementState::Pressed,
|
},
|
||||||
..
|
..
|
||||||
},
|
} => {
|
||||||
..
|
if logical_key == Key::Character("n".into()) {
|
||||||
},
|
if let Some(window) = windows.get(&window_id) {
|
||||||
} => {
|
// Request a new activation token on this window.
|
||||||
if logical_key == Key::Character("n".into()) {
|
// Once we get it we will use it to create a window.
|
||||||
if let Some(window) = windows.get(&window_id) {
|
window
|
||||||
// Request a new activation token on this window.
|
.request_activation_token()
|
||||||
// Once we get it we will use it to create a window.
|
.expect("Failed to request activation token.");
|
||||||
window
|
}
|
||||||
.request_activation_token()
|
|
||||||
.expect("Failed to request activation token.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Event::WindowEvent {
|
WindowEvent::CloseRequested => {
|
||||||
window_id,
|
// Remove the window from the map.
|
||||||
event: WindowEvent::CloseRequested,
|
windows.remove(&window_id);
|
||||||
} => {
|
if windows.is_empty() {
|
||||||
// Remove the window from the map.
|
flow.set_exit();
|
||||||
windows.remove(&window_id);
|
return;
|
||||||
if windows.is_empty() {
|
}
|
||||||
flow.set_exit();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Event::WindowEvent {
|
WindowEvent::ActivationTokenDone { token, .. } => {
|
||||||
event: WindowEvent::ActivationTokenDone { token, .. },
|
current_token = Some(token);
|
||||||
..
|
|
||||||
} => {
|
|
||||||
current_token = Some(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
Event::RedrawRequested(id) => {
|
|
||||||
if let Some(window) = windows.get(&id) {
|
|
||||||
super::fill::fill_window(window);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
WindowEvent::RedrawRequested => {
|
||||||
|
if let Some(window) = windows.get(&window_id) {
|
||||||
|
super::fill::fill_window(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if we've passed the deadline.
|
// See if we've passed the deadline.
|
||||||
|
|
|
@ -30,50 +30,41 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { window_id, event } = event {
|
||||||
Event::WindowEvent {
|
match event {
|
||||||
event: WindowEvent::CloseRequested,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||||
..
|
WindowEvent::ThemeChanged(theme) if window_id == window.id() => {
|
||||||
} => *control_flow = ControlFlow::Exit,
|
println!("Theme is changed: {theme:?}")
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::ThemeChanged(theme),
|
|
||||||
window_id,
|
|
||||||
..
|
|
||||||
} if window_id == window.id() => {
|
|
||||||
println!("Theme is changed: {theme:?}")
|
|
||||||
}
|
|
||||||
Event::WindowEvent {
|
|
||||||
event:
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
event:
|
|
||||||
KeyEvent {
|
|
||||||
logical_key: key,
|
|
||||||
state: ElementState::Pressed,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => match key.as_ref() {
|
|
||||||
Key::Character("A" | "a") => {
|
|
||||||
println!("Theme was: {:?}", window.theme());
|
|
||||||
window.set_theme(None);
|
|
||||||
}
|
}
|
||||||
Key::Character("L" | "l") => {
|
WindowEvent::KeyboardInput {
|
||||||
println!("Theme was: {:?}", window.theme());
|
event:
|
||||||
window.set_theme(Some(Theme::Light));
|
KeyEvent {
|
||||||
}
|
logical_key: key,
|
||||||
Key::Character("D" | "d") => {
|
state: ElementState::Pressed,
|
||||||
println!("Theme was: {:?}", window.theme());
|
..
|
||||||
window.set_theme(Some(Theme::Dark));
|
},
|
||||||
|
..
|
||||||
|
} => match key.as_ref() {
|
||||||
|
Key::Character("A" | "a") => {
|
||||||
|
println!("Theme was: {:?}", window.theme());
|
||||||
|
window.set_theme(None);
|
||||||
|
}
|
||||||
|
Key::Character("L" | "l") => {
|
||||||
|
println!("Theme was: {:?}", window.theme());
|
||||||
|
window.set_theme(Some(Theme::Light));
|
||||||
|
}
|
||||||
|
Key::Character("D" | "d") => {
|
||||||
|
println!("Theme was: {:?}", window.theme());
|
||||||
|
window.set_theme(Some(Theme::Dark));
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
println!("\nredrawing!\n");
|
||||||
|
fill::fill_window(&window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
println!("\nredrawing!\n");
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,10 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
..
|
..
|
||||||
} => control_flow.set_exit(),
|
} => control_flow.set_exit(),
|
||||||
Event::RedrawRequested(_) => {
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
fill::fill_window(&window);
|
fill::fill_window(&window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -42,10 +42,11 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
println!("Rotated clockwise {delta}");
|
println!("Rotated clockwise {delta}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else if let Event::RedrawRequested(_) = event {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,15 +26,14 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
println!("{event:?}");
|
println!("{event:?}");
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
Event::WindowEvent {
|
match event {
|
||||||
event: WindowEvent::CloseRequested,
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
..
|
WindowEvent::RedrawRequested => {
|
||||||
} => control_flow.set_exit(),
|
fill::fill_window(&window);
|
||||||
Event::RedrawRequested(_) => {
|
}
|
||||||
fill::fill_window(&window);
|
_ => (),
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,18 +25,19 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
println!("{event:?}");
|
println!("{event:?}");
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent { event, window_id } if window_id == window.id() => match event {
|
||||||
event: WindowEvent::CloseRequested,
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
window_id,
|
WindowEvent::RedrawRequested => {
|
||||||
} if window_id == window.id() => control_flow.set_exit(),
|
// Notify the windowing system that we'll be presenting to the window.
|
||||||
|
window.pre_present_notify();
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
Event::AboutToWait => {
|
Event::AboutToWait => {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
// Notify the windowing system that we'll be presenting to the window.
|
|
||||||
window.pre_present_notify();
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -34,42 +34,37 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { window_id, event } = event {
|
||||||
Event::WindowEvent {
|
match event {
|
||||||
event:
|
WindowEvent::KeyboardInput {
|
||||||
WindowEvent::KeyboardInput {
|
event:
|
||||||
event:
|
KeyEvent {
|
||||||
KeyEvent {
|
logical_key: key,
|
||||||
logical_key: key,
|
state: ElementState::Pressed,
|
||||||
state: ElementState::Pressed,
|
..
|
||||||
..
|
},
|
||||||
},
|
..
|
||||||
..
|
} => match key.as_ref() {
|
||||||
},
|
Key::Character("F" | "f") => {
|
||||||
..
|
let buttons = window.enabled_buttons();
|
||||||
} => match key.as_ref() {
|
window.set_enabled_buttons(buttons ^ WindowButtons::CLOSE);
|
||||||
Key::Character("F" | "f") => {
|
}
|
||||||
let buttons = window.enabled_buttons();
|
Key::Character("G" | "g") => {
|
||||||
window.set_enabled_buttons(buttons ^ WindowButtons::CLOSE);
|
let buttons = window.enabled_buttons();
|
||||||
}
|
window.set_enabled_buttons(buttons ^ WindowButtons::MAXIMIZE);
|
||||||
Key::Character("G" | "g") => {
|
}
|
||||||
let buttons = window.enabled_buttons();
|
Key::Character("H" | "h") => {
|
||||||
window.set_enabled_buttons(buttons ^ WindowButtons::MAXIMIZE);
|
let buttons = window.enabled_buttons();
|
||||||
}
|
window.set_enabled_buttons(buttons ^ WindowButtons::MINIMIZE);
|
||||||
Key::Character("H" | "h") => {
|
}
|
||||||
let buttons = window.enabled_buttons();
|
_ => (),
|
||||||
window.set_enabled_buttons(buttons ^ WindowButtons::MINIMIZE);
|
},
|
||||||
|
WindowEvent::CloseRequested if window_id == window.id() => control_flow.set_exit(),
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
window_id,
|
|
||||||
} if window_id == window.id() => control_flow.set_exit(),
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,75 +68,71 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::WindowEvent {
|
Event::WindowEvent { window_id, event } => match event {
|
||||||
event:
|
WindowEvent::KeyboardInput {
|
||||||
WindowEvent::KeyboardInput {
|
event:
|
||||||
event:
|
KeyEvent {
|
||||||
KeyEvent {
|
logical_key: Key::Character(key_str),
|
||||||
logical_key: Key::Character(key_str),
|
state: ElementState::Pressed,
|
||||||
state: ElementState::Pressed,
|
..
|
||||||
..
|
},
|
||||||
},
|
..
|
||||||
..
|
} => match key_str.as_ref() {
|
||||||
},
|
// WARNING: Consider using `key_without_modifers()` if available on your platform.
|
||||||
..
|
// See the `key_binding` example
|
||||||
} => match key_str.as_ref() {
|
"e" => {
|
||||||
// WARNING: Consider using `key_without_modifers()` if available on your platform.
|
fn area(size: PhysicalSize<u32>) -> u32 {
|
||||||
// See the `key_binding` example
|
size.width * size.height
|
||||||
"e" => {
|
}
|
||||||
fn area(size: PhysicalSize<u32>) -> u32 {
|
|
||||||
size.width * size.height
|
|
||||||
}
|
|
||||||
|
|
||||||
let monitor = window.current_monitor().unwrap();
|
let monitor = window.current_monitor().unwrap();
|
||||||
if let Some(mode) = monitor
|
if let Some(mode) = monitor
|
||||||
.video_modes()
|
.video_modes()
|
||||||
.max_by(|a, b| area(a.size()).cmp(&area(b.size())))
|
.max_by(|a, b| area(a.size()).cmp(&area(b.size())))
|
||||||
{
|
{
|
||||||
window.set_fullscreen(Some(Fullscreen::Exclusive(mode)));
|
window.set_fullscreen(Some(Fullscreen::Exclusive(mode)));
|
||||||
} else {
|
} else {
|
||||||
eprintln!("no video modes available");
|
eprintln!("no video modes available");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
"f" => {
|
||||||
"f" => {
|
if window.fullscreen().is_some() {
|
||||||
if window.fullscreen().is_some() {
|
window.set_fullscreen(None);
|
||||||
window.set_fullscreen(None);
|
} else {
|
||||||
} else {
|
let monitor = window.current_monitor();
|
||||||
let monitor = window.current_monitor();
|
window.set_fullscreen(Some(Fullscreen::Borderless(monitor)));
|
||||||
window.set_fullscreen(Some(Fullscreen::Borderless(monitor)));
|
}
|
||||||
}
|
}
|
||||||
}
|
"p" => {
|
||||||
"p" => {
|
if window.fullscreen().is_some() {
|
||||||
if window.fullscreen().is_some() {
|
window.set_fullscreen(None);
|
||||||
window.set_fullscreen(None);
|
} else {
|
||||||
} else {
|
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
|
||||||
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
|
}
|
||||||
}
|
}
|
||||||
}
|
"m" => {
|
||||||
"m" => {
|
minimized = !minimized;
|
||||||
minimized = !minimized;
|
window.set_minimized(minimized);
|
||||||
window.set_minimized(minimized);
|
}
|
||||||
}
|
"q" => {
|
||||||
"q" => {
|
control_flow.set_exit();
|
||||||
control_flow.set_exit();
|
}
|
||||||
}
|
"v" => {
|
||||||
"v" => {
|
visible = !visible;
|
||||||
visible = !visible;
|
window.set_visible(visible);
|
||||||
window.set_visible(visible);
|
}
|
||||||
}
|
"x" => {
|
||||||
"x" => {
|
let is_maximized = window.is_maximized();
|
||||||
let is_maximized = window.is_maximized();
|
window.set_maximized(!is_maximized);
|
||||||
window.set_maximized(!is_maximized);
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
WindowEvent::CloseRequested if window_id == window.id() => control_flow.set_exit(),
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
window_id,
|
|
||||||
} if window_id == window.id() => control_flow.set_exit(),
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -68,11 +68,12 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
border = !border;
|
border = !border;
|
||||||
window.set_decorations(border);
|
window.set_decorations(border);
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use simple_logger::SimpleLogger;
|
use simple_logger::SimpleLogger;
|
||||||
use winit::{
|
use winit::{
|
||||||
event::Event,
|
event::{Event, WindowEvent},
|
||||||
event_loop::EventLoop,
|
event_loop::EventLoop,
|
||||||
window::{Icon, WindowBuilder},
|
window::{Icon, WindowBuilder},
|
||||||
};
|
};
|
||||||
|
@ -37,16 +37,14 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
if let Event::WindowEvent { event, .. } = event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
use winit::event::WindowEvent::*;
|
|
||||||
match event {
|
match event {
|
||||||
CloseRequested => control_flow.set_exit(),
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
DroppedFile(path) => {
|
WindowEvent::DroppedFile(path) => {
|
||||||
window.set_window_icon(Some(load_icon(&path)));
|
window.set_window_icon(Some(load_icon(&path)));
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => fill::fill_window(&window),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else if let Event::RedrawRequested(_) = event {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,10 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
app.window = None;
|
app.window = None;
|
||||||
}
|
}
|
||||||
Event::AboutToWait => window.request_redraw(),
|
Event::AboutToWait => window.request_redraw(),
|
||||||
Event::RedrawRequested(_) => {
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
fill::fill_window(window);
|
fill::fill_window(window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -56,14 +56,15 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
window.set_option_as_alt(option_as_alt);
|
window.set_option_as_alt(option_as_alt);
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput { .. } => println!("KeyboardInput: {event:?}"),
|
WindowEvent::KeyboardInput { .. } => println!("KeyboardInput: {event:?}"),
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::AboutToWait => {
|
Event::AboutToWait => {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -48,7 +48,10 @@ fn main() -> std::process::ExitCode {
|
||||||
Event::AboutToWait => {
|
Event::AboutToWait => {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
fill::fill_window(&window);
|
fill::fill_window(&window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -28,36 +28,33 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent { event, window_id } if window_id == window.id() => match event {
|
||||||
event: WindowEvent::CloseRequested,
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
||||||
window_id,
|
WindowEvent::KeyboardInput {
|
||||||
} if window_id == window.id() => control_flow.set_exit(),
|
event:
|
||||||
Event::WindowEvent {
|
KeyEvent {
|
||||||
event:
|
logical_key: Key::Space,
|
||||||
WindowEvent::KeyboardInput {
|
state: ElementState::Released,
|
||||||
event:
|
..
|
||||||
KeyEvent {
|
},
|
||||||
logical_key: Key::Space,
|
..
|
||||||
state: ElementState::Released,
|
} => {
|
||||||
..
|
has_increments = !has_increments;
|
||||||
},
|
|
||||||
..
|
|
||||||
},
|
|
||||||
window_id,
|
|
||||||
} if window_id == window.id() => {
|
|
||||||
has_increments = !has_increments;
|
|
||||||
|
|
||||||
let new_increments = match window.resize_increments() {
|
let new_increments = match window.resize_increments() {
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
None => Some(LogicalSize::new(25.0, 25.0)),
|
None => Some(LogicalSize::new(25.0, 25.0)),
|
||||||
};
|
};
|
||||||
debug!("Had increments: {}", new_increments.is_none());
|
debug!("Had increments: {}", new_increments.is_none());
|
||||||
window.set_resize_increments(new_increments);
|
window.set_resize_increments(new_increments);
|
||||||
}
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
fill::fill_window(&window);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
Event::AboutToWait => window.request_redraw(),
|
Event::AboutToWait => window.request_redraw(),
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
fill::fill_window(&window);
|
|
||||||
}
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -33,75 +33,72 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
event_loop.run(move |event, event_loop, control_flow| {
|
event_loop.run(move |event, event_loop, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
|
||||||
match event {
|
if let Event::WindowEvent { event, window_id } = event {
|
||||||
Event::WindowEvent { event, window_id } => {
|
match event {
|
||||||
match event {
|
WindowEvent::CloseRequested => {
|
||||||
WindowEvent::CloseRequested => {
|
println!("Window {window_id:?} has received the signal to close");
|
||||||
println!("Window {window_id:?} has received the signal to close");
|
|
||||||
|
|
||||||
// This drops the window, causing it to close.
|
// This drops the window, causing it to close.
|
||||||
windows.remove(&window_id);
|
windows.remove(&window_id);
|
||||||
|
|
||||||
if windows.is_empty() {
|
if windows.is_empty() {
|
||||||
control_flow.set_exit();
|
control_flow.set_exit();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
WindowEvent::Resized(_) => {
|
}
|
||||||
if let Some(window) = windows.get(&window_id) {
|
WindowEvent::Resized(_) => {
|
||||||
window.request_redraw();
|
if let Some(window) = windows.get(&window_id) {
|
||||||
}
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput {
|
}
|
||||||
event:
|
WindowEvent::KeyboardInput {
|
||||||
KeyEvent {
|
event:
|
||||||
state: ElementState::Pressed,
|
KeyEvent {
|
||||||
logical_key,
|
state: ElementState::Pressed,
|
||||||
..
|
logical_key,
|
||||||
},
|
..
|
||||||
is_synthetic: false,
|
},
|
||||||
..
|
is_synthetic: false,
|
||||||
} => match logical_key.as_ref() {
|
..
|
||||||
Key::Character("t") => {
|
} => match logical_key.as_ref() {
|
||||||
let tabbing_id = windows.get(&window_id).unwrap().tabbing_identifier();
|
Key::Character("t") => {
|
||||||
let window = WindowBuilder::new()
|
let tabbing_id = windows.get(&window_id).unwrap().tabbing_identifier();
|
||||||
.with_tabbing_identifier(&tabbing_id)
|
let window = WindowBuilder::new()
|
||||||
.build(event_loop)
|
.with_tabbing_identifier(&tabbing_id)
|
||||||
.unwrap();
|
.build(event_loop)
|
||||||
println!("Added a new tab: {:?}", window.id());
|
.unwrap();
|
||||||
windows.insert(window.id(), window);
|
println!("Added a new tab: {:?}", window.id());
|
||||||
}
|
windows.insert(window.id(), window);
|
||||||
Key::Character("w") => {
|
}
|
||||||
let _ = windows.remove(&window_id);
|
Key::Character("w") => {
|
||||||
}
|
let _ = windows.remove(&window_id);
|
||||||
Key::ArrowRight => {
|
}
|
||||||
windows.get(&window_id).unwrap().select_next_tab();
|
Key::ArrowRight => {
|
||||||
}
|
windows.get(&window_id).unwrap().select_next_tab();
|
||||||
Key::ArrowLeft => {
|
}
|
||||||
windows.get(&window_id).unwrap().select_previous_tab();
|
Key::ArrowLeft => {
|
||||||
}
|
windows.get(&window_id).unwrap().select_previous_tab();
|
||||||
Key::Character(ch) => {
|
}
|
||||||
if let Ok(index) = ch.parse::<NonZeroUsize>() {
|
Key::Character(ch) => {
|
||||||
let index = index.get();
|
if let Ok(index) = ch.parse::<NonZeroUsize>() {
|
||||||
// Select the last tab when pressing `9`.
|
let index = index.get();
|
||||||
let window = windows.get(&window_id).unwrap();
|
// Select the last tab when pressing `9`.
|
||||||
if index == 9 {
|
let window = windows.get(&window_id).unwrap();
|
||||||
window.select_tab_at_index(window.num_tabs() - 1)
|
if index == 9 {
|
||||||
} else {
|
window.select_tab_at_index(window.num_tabs() - 1)
|
||||||
window.select_tab_at_index(index - 1);
|
} else {
|
||||||
}
|
window.select_tab_at_index(index - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
}
|
||||||
},
|
|
||||||
_ => (),
|
_ => (),
|
||||||
|
},
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
if let Some(window) = windows.get(&window_id) {
|
||||||
|
fill::fill_window(window);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(window_id) => {
|
|
||||||
if let Some(window) = windows.get(&window_id) {
|
|
||||||
fill::fill_window(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,10 @@ mod imple {
|
||||||
Event::AboutToWait => {
|
Event::AboutToWait => {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
// Notify the windowing system that we'll be presenting to the window.
|
// Notify the windowing system that we'll be presenting to the window.
|
||||||
window.pre_present_notify();
|
window.pre_present_notify();
|
||||||
fill::fill_window(&window);
|
fill::fill_window(&window);
|
||||||
|
|
26
src/event.rs
26
src/event.rs
|
@ -218,20 +218,9 @@ pub enum Event<T: 'static> {
|
||||||
/// ups and also lots of corresponding `AboutToWait` events.
|
/// ups and also lots of corresponding `AboutToWait` events.
|
||||||
///
|
///
|
||||||
/// This is not an ideal event to drive application rendering from and instead applications
|
/// This is not an ideal event to drive application rendering from and instead applications
|
||||||
/// should render in response to [`Event::RedrawRequested`] events.
|
/// should render in response to [`WindowEvent::RedrawRequested`] events.
|
||||||
AboutToWait,
|
AboutToWait,
|
||||||
|
|
||||||
/// Emitted when a window should be redrawn.
|
|
||||||
///
|
|
||||||
/// This gets triggered in two scenarios:
|
|
||||||
/// - The OS has performed an operation that's invalidated the window's contents (such as
|
|
||||||
/// resizing the window).
|
|
||||||
/// - The application has explicitly requested a redraw via [`Window::request_redraw`].
|
|
||||||
///
|
|
||||||
/// Winit will aggregate duplicate redraw requests into a single event, to
|
|
||||||
/// help avoid duplicating rendering work.
|
|
||||||
RedrawRequested(WindowId),
|
|
||||||
|
|
||||||
/// Emitted when the event loop is being shut down.
|
/// Emitted when the event loop is being shut down.
|
||||||
///
|
///
|
||||||
/// This is irreversible - if this event is emitted, it is guaranteed to be the last event that
|
/// This is irreversible - if this event is emitted, it is guaranteed to be the last event that
|
||||||
|
@ -249,7 +238,6 @@ impl<T> Event<T> {
|
||||||
DeviceEvent { device_id, event } => Ok(DeviceEvent { device_id, event }),
|
DeviceEvent { device_id, event } => Ok(DeviceEvent { device_id, event }),
|
||||||
NewEvents(cause) => Ok(NewEvents(cause)),
|
NewEvents(cause) => Ok(NewEvents(cause)),
|
||||||
AboutToWait => Ok(AboutToWait),
|
AboutToWait => Ok(AboutToWait),
|
||||||
RedrawRequested(wid) => Ok(RedrawRequested(wid)),
|
|
||||||
LoopExiting => Ok(LoopExiting),
|
LoopExiting => Ok(LoopExiting),
|
||||||
Suspended => Ok(Suspended),
|
Suspended => Ok(Suspended),
|
||||||
Resumed => Ok(Resumed),
|
Resumed => Ok(Resumed),
|
||||||
|
@ -553,6 +541,17 @@ pub enum WindowEvent {
|
||||||
/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
|
/// [`padding`]: https://developer.mozilla.org/en-US/docs/Web/CSS/padding
|
||||||
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
|
/// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
|
||||||
Occluded(bool),
|
Occluded(bool),
|
||||||
|
|
||||||
|
/// Emitted when a window should be redrawn.
|
||||||
|
///
|
||||||
|
/// This gets triggered in two scenarios:
|
||||||
|
/// - The OS has performed an operation that's invalidated the window's contents (such as
|
||||||
|
/// resizing the window).
|
||||||
|
/// - The application has explicitly requested a redraw via [`Window::request_redraw`].
|
||||||
|
///
|
||||||
|
/// Winit will aggregate duplicate redraw requests into a single event, to
|
||||||
|
/// help avoid duplicating rendering work.
|
||||||
|
RedrawRequested,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Identifier of an input device.
|
/// Identifier of an input device.
|
||||||
|
@ -1122,7 +1121,6 @@ mod tests {
|
||||||
let wid = unsafe { WindowId::dummy() };
|
let wid = unsafe { WindowId::dummy() };
|
||||||
x(UserEvent(()));
|
x(UserEvent(()));
|
||||||
x(NewEvents(event::StartCause::Init));
|
x(NewEvents(event::StartCause::Init));
|
||||||
x(RedrawRequested(wid));
|
|
||||||
x(AboutToWait);
|
x(AboutToWait);
|
||||||
x(LoopExiting);
|
x(LoopExiting);
|
||||||
x(Suspended);
|
x(Suspended);
|
||||||
|
|
|
@ -79,7 +79,10 @@
|
||||||
//! // can just render here instead.
|
//! // can just render here instead.
|
||||||
//! window.request_redraw();
|
//! window.request_redraw();
|
||||||
//! },
|
//! },
|
||||||
//! Event::RedrawRequested(_) => {
|
//! Event::WindowEvent {
|
||||||
|
//! event: WindowEvent::RedrawRequested,
|
||||||
|
//! ..
|
||||||
|
//! } => {
|
||||||
//! // Redraw the application.
|
//! // Redraw the application.
|
||||||
//! //
|
//! //
|
||||||
//! // It's preferable for applications that do not render continuously to render in
|
//! // It's preferable for applications that do not render continuously to render in
|
||||||
|
|
|
@ -407,7 +407,10 @@ impl<T: 'static> EventLoop<T> {
|
||||||
pending_redraw |= self.redraw_flag.get_and_reset();
|
pending_redraw |= self.redraw_flag.get_and_reset();
|
||||||
if pending_redraw {
|
if pending_redraw {
|
||||||
pending_redraw = false;
|
pending_redraw = false;
|
||||||
let event = event::Event::RedrawRequested(window::WindowId(WindowId));
|
let event = event::Event::WindowEvent {
|
||||||
|
window_id: window::WindowId(WindowId),
|
||||||
|
event: event::WindowEvent::RedrawRequested,
|
||||||
|
};
|
||||||
sticky_exit_callback(event, self.window_target(), &mut control_flow, callback);
|
sticky_exit_callback(event, self.window_target(), &mut control_flow, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,13 @@ enum UserCallbackTransitionResult<'a> {
|
||||||
|
|
||||||
impl Event<Never> {
|
impl Event<Never> {
|
||||||
fn is_redraw(&self) -> bool {
|
fn is_redraw(&self) -> bool {
|
||||||
matches!(self, Event::RedrawRequested(_))
|
matches!(
|
||||||
|
self,
|
||||||
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +761,12 @@ pub unsafe fn handle_main_events_cleared() {
|
||||||
let redraw_events: Vec<EventWrapper> = this
|
let redraw_events: Vec<EventWrapper> = this
|
||||||
.main_events_cleared_transition()
|
.main_events_cleared_transition()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|window| EventWrapper::StaticEvent(Event::RedrawRequested(RootWindowId(window.id()))))
|
.map(|window| {
|
||||||
|
EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
|
window_id: RootWindowId(window.id()),
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
})
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
drop(this);
|
drop(this);
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,10 @@ declare_class!(
|
||||||
fn draw_rect(&self, rect: CGRect) {
|
fn draw_rect(&self, rect: CGRect) {
|
||||||
let window = self.window().unwrap();
|
let window = self.window().unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(
|
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
RootWindowId(window.id()),
|
window_id: RootWindowId(window.id()),
|
||||||
)));
|
event: WindowEvent::RedrawRequested,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
let _: () = unsafe { msg_send![super(self), drawRect: rect] };
|
let _: () = unsafe { msg_send![super(self), drawRect: rect] };
|
||||||
}
|
}
|
||||||
|
|
|
@ -580,7 +580,10 @@ impl<T: 'static> EventLoop<T> {
|
||||||
|
|
||||||
if request_redraw {
|
if request_redraw {
|
||||||
sticky_exit_callback(
|
sticky_exit_callback(
|
||||||
Event::RedrawRequested(crate::window::WindowId(window_id)),
|
Event::WindowEvent {
|
||||||
|
window_id: crate::window::WindowId(window_id),
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
},
|
||||||
&self.window_target,
|
&self.window_target,
|
||||||
&mut control_flow,
|
&mut control_flow,
|
||||||
&mut callback,
|
&mut callback,
|
||||||
|
|
|
@ -576,7 +576,10 @@ impl<T: 'static> EventProcessor<T> {
|
||||||
let window = xev.window as xproto::Window;
|
let window = xev.window as xproto::Window;
|
||||||
let window_id = mkwid(window);
|
let window_id = mkwid(window);
|
||||||
|
|
||||||
callback(Event::RedrawRequested(window_id));
|
callback(Event::WindowEvent {
|
||||||
|
window_id,
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ use self::{
|
||||||
use super::{common::xkb_state::KbdState, OsError};
|
use super::{common::xkb_state::KbdState, OsError};
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{EventLoopError, OsError as RootOsError},
|
error::{EventLoopError, OsError as RootOsError},
|
||||||
event::{Event, StartCause},
|
event::{Event, StartCause, WindowEvent},
|
||||||
event_loop::{ControlFlow, DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW},
|
event_loop::{ControlFlow, DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW},
|
||||||
platform::pump_events::PumpStatus,
|
platform::pump_events::PumpStatus,
|
||||||
platform_impl::{
|
platform_impl::{
|
||||||
|
@ -671,7 +671,10 @@ impl<T: 'static> EventLoop<T> {
|
||||||
for window_id in windows {
|
for window_id in windows {
|
||||||
let window_id = crate::window::WindowId(window_id);
|
let window_id = crate::window::WindowId(window_id);
|
||||||
sticky_exit_callback(
|
sticky_exit_callback(
|
||||||
Event::RedrawRequested(window_id),
|
Event::WindowEvent {
|
||||||
|
window_id,
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
},
|
||||||
&self.target,
|
&self.target,
|
||||||
&mut control_flow,
|
&mut control_flow,
|
||||||
callback,
|
callback,
|
||||||
|
@ -708,7 +711,11 @@ impl<T: 'static> EventLoop<T> {
|
||||||
target,
|
target,
|
||||||
control_flow,
|
control_flow,
|
||||||
&mut |event, window_target, control_flow| {
|
&mut |event, window_target, control_flow| {
|
||||||
if let Event::RedrawRequested(crate::window::WindowId(wid)) = event {
|
if let Event::WindowEvent {
|
||||||
|
window_id: crate::window::WindowId(wid),
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
} = event
|
||||||
|
{
|
||||||
wt.redraw_sender.send(wid).unwrap();
|
wt.redraw_sender.send(wid).unwrap();
|
||||||
} else {
|
} else {
|
||||||
callback(event, window_target, control_flow);
|
callback(event, window_target, control_flow);
|
||||||
|
|
|
@ -564,8 +564,10 @@ impl AppState {
|
||||||
// Redraw request might come out of order from the OS.
|
// Redraw request might come out of order from the OS.
|
||||||
// -> Don't go back into the callback when our callstack originates from there
|
// -> Don't go back into the callback when our callstack originates from there
|
||||||
if !HANDLER.in_callback.swap(true, Ordering::AcqRel) {
|
if !HANDLER.in_callback.swap(true, Ordering::AcqRel) {
|
||||||
HANDLER
|
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id)));
|
window_id,
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
}));
|
||||||
HANDLER.set_in_callback(false);
|
HANDLER.set_in_callback(false);
|
||||||
|
|
||||||
// `pump_events` will request to stop immediately _after_ dispatching RedrawRequested events
|
// `pump_events` will request to stop immediately _after_ dispatching RedrawRequested events
|
||||||
|
@ -616,8 +618,10 @@ impl AppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
for window_id in HANDLER.should_redraw() {
|
for window_id in HANDLER.should_redraw() {
|
||||||
HANDLER
|
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id)));
|
window_id,
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::AboutToWait));
|
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::AboutToWait));
|
||||||
|
|
|
@ -608,7 +608,10 @@ impl<T: 'static> EventLoop<T> {
|
||||||
redraws.pop_front()
|
redraws.pop_front()
|
||||||
} {
|
} {
|
||||||
event_handler(
|
event_handler(
|
||||||
event::Event::RedrawRequested(RootWindowId(window_id)),
|
event::Event::WindowEvent {
|
||||||
|
window_id: RootWindowId(window_id),
|
||||||
|
event: event::WindowEvent::RedrawRequested,
|
||||||
|
},
|
||||||
&self.window_target,
|
&self.window_target,
|
||||||
&mut control_flow,
|
&mut control_flow,
|
||||||
);
|
);
|
||||||
|
|
|
@ -567,7 +567,13 @@ impl<T: 'static> Shared<T> {
|
||||||
// Collect all of the redraw events to avoid double-locking the RefCell
|
// Collect all of the redraw events to avoid double-locking the RefCell
|
||||||
let redraw_events: Vec<WindowId> = self.0.redraw_pending.borrow_mut().drain().collect();
|
let redraw_events: Vec<WindowId> = self.0.redraw_pending.borrow_mut().drain().collect();
|
||||||
for window_id in redraw_events {
|
for window_id in redraw_events {
|
||||||
self.handle_event(Event::RedrawRequested(window_id), &mut control);
|
self.handle_event(
|
||||||
|
Event::WindowEvent {
|
||||||
|
window_id,
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
},
|
||||||
|
&mut control,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.handle_event(Event::AboutToWait, &mut control);
|
self.handle_event(Event::AboutToWait, &mut control);
|
||||||
|
|
|
@ -1152,7 +1152,10 @@ unsafe fn public_window_callback_inner<T: 'static>(
|
||||||
// redraw the window outside the normal flow of the event loop.
|
// redraw the window outside the normal flow of the event loop.
|
||||||
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
|
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
|
||||||
} else {
|
} else {
|
||||||
userdata.send_event(Event::RedrawRequested(RootWindowId(WindowId(window))));
|
userdata.send_event(Event::WindowEvent {
|
||||||
|
window_id: RootWindowId(WindowId(window)),
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
result = ProcResult::DefWindowProc(wparam);
|
result = ProcResult::DefWindowProc(wparam);
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,11 @@ impl<T> EventLoopRunner<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn send_event(&self, event: Event<T>) {
|
pub(crate) fn send_event(&self, event: Event<T>) {
|
||||||
if let Event::RedrawRequested(_) = event {
|
if let Event::WindowEvent {
|
||||||
|
event: WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} = event
|
||||||
|
{
|
||||||
self.call_event_handler(event);
|
self.call_event_handler(event);
|
||||||
// As a rule, to ensure that `pump_events` can't block an external event loop
|
// As a rule, to ensure that `pump_events` can't block an external event loop
|
||||||
// for too long, we always guarantee that `pump_events` will return control to
|
// for too long, we always guarantee that `pump_events` will return control to
|
||||||
|
|
|
@ -539,7 +539,7 @@ impl Window {
|
||||||
self.window.maybe_wait_on_main(|w| w.scale_factor())
|
self.window.maybe_wait_on_main(|w| w.scale_factor())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Queues a [`Event::RedrawRequested`] event to be emitted that aligns with the windowing
|
/// Queues a [`WindowEvent::RedrawRequested`] event to be emitted that aligns with the windowing
|
||||||
/// system drawing loop.
|
/// system drawing loop.
|
||||||
///
|
///
|
||||||
/// This is the **strongly encouraged** method of redrawing windows, as it can integrate with
|
/// This is the **strongly encouraged** method of redrawing windows, as it can integrate with
|
||||||
|
@ -562,9 +562,9 @@ impl Window {
|
||||||
/// - **iOS:** Can only be called on the main thread.
|
/// - **iOS:** Can only be called on the main thread.
|
||||||
/// - **Wayland:** The events are aligned with the frame callbacks when [`Window::pre_present_notify`]
|
/// - **Wayland:** The events are aligned with the frame callbacks when [`Window::pre_present_notify`]
|
||||||
/// is used.
|
/// is used.
|
||||||
/// - **Web:** [`Event::RedrawRequested`] will be aligned with the `requestAnimationFrame`.
|
/// - **Web:** [`WindowEvent::RedrawRequested`] will be aligned with the `requestAnimationFrame`.
|
||||||
///
|
///
|
||||||
/// [`Event::RedrawRequested`]: crate::event::Event::RedrawRequested
|
/// [`WindowEvent::RedrawRequested`]: crate::event::WindowEvent::RedrawRequested
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn request_redraw(&self) {
|
pub fn request_redraw(&self) {
|
||||||
self.window.maybe_queue_on_main(|w| w.request_redraw())
|
self.window.maybe_queue_on_main(|w| w.request_redraw())
|
||||||
|
@ -575,7 +575,7 @@ impl Window {
|
||||||
/// You should call this event after you've done drawing operations, but before you submit
|
/// You should call this event after you've done drawing operations, but before you submit
|
||||||
/// the buffer to the display or commit your drawings. Doing so will help winit to properly
|
/// the buffer to the display or commit your drawings. Doing so will help winit to properly
|
||||||
/// schedule and do assumptions about its internal state. For example, it could properly
|
/// schedule and do assumptions about its internal state. For example, it could properly
|
||||||
/// throttle [`Event::RedrawRequested`].
|
/// throttle [`WindowEvent::RedrawRequested`].
|
||||||
///
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
|
@ -599,9 +599,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// ## Platform-specific
|
/// ## Platform-specific
|
||||||
///
|
///
|
||||||
/// **Wayland:** - schedules a frame callback to throttle [`Event::RedrawRequested`].
|
/// **Wayland:** - schedules a frame callback to throttle [`WindowEvent::RedrawRequested`].
|
||||||
///
|
///
|
||||||
/// [`Event::RedrawRequested`]: crate::event::Event::RedrawRequested
|
/// [`WindowEvent::RedrawRequested`]: crate::event::WindowEvent::RedrawRequested
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn pre_present_notify(&self) {
|
pub fn pre_present_notify(&self) {
|
||||||
self.window.maybe_queue_on_main(|w| w.pre_present_notify());
|
self.window.maybe_queue_on_main(|w| w.pre_present_notify());
|
||||||
|
|
Loading…
Reference in a new issue