From 277b848ad8df1e8d038e33707548a45d63a601db Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 18 Jul 2022 18:37:41 +0200 Subject: Remove `window::Mode` and introduce `Settings::visible` Additionally, only show the window once one frame has been rendered to avoid blank flashes on Windows. --- winit/src/application.rs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 3a5c3dac..23364209 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -9,7 +9,7 @@ use crate::mouse; use crate::renderer; use crate::widget::operation; use crate::{ - Command, Debug, Error, Executor, Mode, Proxy, Runtime, Settings, Size, + Command, Debug, Error, Executor, Proxy, Runtime, Settings, Size, Subscription, }; @@ -81,16 +81,6 @@ where Subscription::none() } - /// Returns the current [`Application`] mode. - /// - /// The runtime will automatically transition your application if a new mode - /// is returned. - /// - /// By default, an application will run in windowed mode. - fn mode(&self) -> Mode { - Mode::Windowed - } - /// Returns the scale factor of the [`Application`]. /// /// It can be used to dynamically control the size of the UI at runtime @@ -147,12 +137,15 @@ where runtime.enter(|| A::new(flags)) }; - let builder = settings.window.into_builder( - &application.title(), - application.mode(), - event_loop.primary_monitor(), - settings.id, - ); + let should_be_visible = settings.window.visible; + let builder = settings + .window + .into_builder( + &application.title(), + event_loop.primary_monitor(), + settings.id, + ) + .with_visible(false); log::info!("Window builder: {:#?}", builder); @@ -189,6 +182,7 @@ where receiver, init_command, window, + should_be_visible, settings.exit_on_close_request, )); @@ -239,6 +233,7 @@ async fn run_instance( mut receiver: mpsc::UnboundedReceiver>, init_command: Command, window: winit::window::Window, + should_be_visible: bool, exit_on_close_request: bool, ) where A: Application + 'static, @@ -252,6 +247,7 @@ async fn run_instance( let mut clipboard = Clipboard::connect(&window); let mut cache = user_interface::Cache::default(); let mut surface = compositor.create_surface(&window); + let mut visible = false; let mut state = State::new(&application, &window); let mut viewport_version = state.viewport_version(); @@ -383,6 +379,7 @@ async fn run_instance( event::MacOS::ReceivedUrl(url), )) => { use iced_native::event; + events.push(iced_native::Event::PlatformSpecific( event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl( url, @@ -450,6 +447,12 @@ async fn run_instance( Ok(()) => { debug.render_finished(); + if !visible && should_be_visible { + window.set_visible(true); + + visible = true; + } + // TODO: Handle animations! // Maybe we can use `ControlFlow::WaitUntil` for this. } -- cgit From 11f5527d7645619f49b030e30485f24ac637efbd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 18 Aug 2022 14:39:15 +0200 Subject: Implement `SetMode` and `FetchMode` window actions --- winit/src/application.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 23364209..ecec6043 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -640,6 +640,20 @@ pub fn run_command( y, }); } + window::Action::SetMode(mode) => { + window.set_visible(conversion::visible(mode)); + window.set_fullscreen(conversion::fullscreen( + window.primary_monitor(), + mode, + )); + } + window::Action::FetchMode(tag) => { + let mode = conversion::mode(window.fullscreen()); + + proxy + .send_event(tag(mode)) + .expect("Send message to event loop"); + } }, command::Action::System(action) => match action { system::Action::QueryInformation(_tag) => { -- cgit