Description
Repro
- Apply the following patch
- Run
cargo run --example window
- Before a window is opened, move focus to another window
- winit window is opened without focus
- Click somewhere on the winit window to move focus to the window
Window focus changed: true is expected to be printed but actually it is not printed. The winit window is actually focused but its internal state is still focused == false.
diff --git a/winit/examples/window.rs b/winit/examples/window.rs
index 7d9fc59f..1e22f893 100644
--- a/winit/examples/window.rs
+++ b/winit/examples/window.rs
@@ -23,12 +23,16 @@ struct App {
impl ApplicationHandler for App {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
#[cfg(not(web_platform))]
- let window_attributes = WindowAttributes::default();
+ let window_attributes =
+ WindowAttributes::default().with_maximized(true).with_visible(false);
#[cfg(web_platform)]
let window_attributes = WindowAttributes::default()
.with_platform_attributes(Box::new(WindowAttributesWeb::default().with_append(true)));
self.window = match event_loop.create_window(window_attributes) {
- Ok(window) => Some(window),
+ Ok(window) => {
+ window.set_visible(true);
+ Some(window)
+ },
Err(err) => {
error!("error creating window: {err}");
event_loop.exit();
@@ -38,8 +42,11 @@ impl ApplicationHandler for App {
}
fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _: WindowId, event: WindowEvent) {
- info!("{event:?}");
+ // info!("{event:?}");
match event {
+ WindowEvent::Focused(focused) => {
+ println!("Window focus changed: {focused}");
+ },
WindowEvent::CloseRequested => {
info!("Close was requested; stopping");
event_loop.exit();
Windows version
Microsoft Windows [Version 10.0.26200.8457]
Winit version
HEAD (c4afadb)
Description
Repro
cargo run --example windowWindow focus changed: trueis expected to be printed but actually it is not printed. The winit window is actually focused but its internal state is stillfocused == false.Windows version
Winit version
HEAD (c4afadb)