diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fff3b3..bb58cca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Window`'s `Clone` implementation no longer requires its generic parameter to implement `Clone`. +- `WindowAttributes::active` is now honored when using `delay_visible`. ### Added @@ -34,6 +35,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 current size including decorations. - `App::prevent_shutdown()` returns a guard that prevents the application from closing automatically when the final window is closed. +- `WindowBehavior::initialized` is called once when the window has been fully + initialized. This happens after the `delay_visible` logic has been executed. ### Changed diff --git a/src/window.rs b/src/window.rs index 6107a29..78d928c 100644 --- a/src/window.rs +++ b/src/window.rs @@ -231,8 +231,10 @@ where let (sender, receiver) = mpsc::sync_channel(65536); let sender = Arc::new(sender); let app = self.owner.as_application().app(); - let show_after_init = - self.attributes.delay_visible && std::mem::replace(&mut self.attributes.visible, false); + let show_after_init = (self.attributes.delay_visible + && std::mem::replace(&mut self.attributes.visible, false)) + .then_some(self.attributes.active); + let Some(winit) = self.owner.as_application_mut().open( self.attributes, sender.clone(), @@ -313,7 +315,7 @@ where focused: bool, theme: Theme, modifiers: Modifiers, - show_after_init: bool, + show_after_init: Option, } impl RunningWindow @@ -487,12 +489,17 @@ where // avoid showing a blank window due to our multi-threaded event // handling by not showing the window until the graphics stack has // been initialized. - if self.show_after_init { + if let Some(activate) = dbg!(self.show_after_init) { self.next_redraw_target = None; behavior.redraw(&mut self); self.window.set_visible(true); + if activate { + self.window.focus_window(); + } } + behavior.initialized(&mut self); + while !self.close { match self.process_messages_until_redraw(&mut behavior) { Ok(guard) => { @@ -985,6 +992,13 @@ where /// Displays the contents of the window. fn redraw(&mut self, window: &mut RunningWindow); + /// Invoked once a window is fully initialized. + /// + /// This is invoked after the window has been presented to the user, if it + /// is initially visible. + #[allow(unused_variables)] + fn initialized(&mut self, window: &mut RunningWindow) {} + /// The window has been requested to be closed. This can happen as a result /// of the user clicking the close button. ///