From d6b20d3e796951e6b42726fddc78fbb1b9aaa094 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 16 Jan 2020 04:54:48 +0100 Subject: Add `Application::mode` to `iced_winit` --- winit/src/application.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index a712632e..3de0476f 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -72,6 +72,18 @@ pub trait Application: Sized { /// [`Application`]: trait.Application.html fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer>; + /// 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. + /// + /// [`Application`]: trait.Application.html + fn mode(&self) -> window::Mode { + window::Mode::Windowed + } + /// Runs the [`Application`]. /// /// This method will take control of the current thread and __will NOT @@ -110,6 +122,7 @@ pub trait Application: Sized { subscription_pool.update(subscription, &mut thread_pool, &proxy); let mut title = application.title(); + let mut mode = application.mode(); let window = { let mut window_builder = WindowBuilder::new(); @@ -123,7 +136,11 @@ pub trait Application: Sized { height: f64::from(height), }) .with_resizable(settings.window.resizable) - .with_decorations(settings.window.decorations); + .with_decorations(settings.window.decorations) + .with_fullscreen(conversion::fullscreen( + event_loop.primary_monitor(), + mode, + )); #[cfg(target_os = "windows")] { @@ -244,6 +261,18 @@ pub trait Application: Sized { title = new_title; } + // Update window mode + let new_mode = application.mode(); + + if mode != new_mode { + window.set_fullscreen(conversion::fullscreen( + window.current_monitor(), + new_mode, + )); + + mode = new_mode; + } + let user_interface = build_user_interface( &mut application, temp_cache, -- cgit