diff --git a/src/app/core.rs b/src/app/core.rs index 8ffe8ecd..c805188b 100644 --- a/src/app/core.rs +++ b/src/app/core.rs @@ -372,12 +372,14 @@ impl Core { } /// The [`Id`] of the main window + #[must_use] pub fn main_window_id(&self) -> Option { self.main_window.filter(|id| iced::window::Id::NONE != *id) } /// Reset the tracked main window to a new value - pub fn set_main_window_id(&mut self, id: window::Id) -> Option { - self.main_window.replace(id) + pub fn set_main_window_id(&mut self, mut id: Option) -> Option { + std::mem::swap(&mut self.main_window, &mut id); + id } } diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index 14dc96d0..a2b229e6 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -78,8 +78,6 @@ pub enum Message { /// Tracks updates to window suggested size. #[cfg(feature = "applet")] SuggestedBounds(Option), - /// Window Created - WindowCreated(window::Id), } #[derive(Default)] @@ -92,7 +90,7 @@ where T::Message: Send + 'static, { pub fn init( - (mut core, flags, window_settings): (Core, T::Flags, iced::window::Settings), + (mut core, flags): (Core, T::Flags), ) -> (Self, iced::Task>) { #[cfg(feature = "dbus-config")] { @@ -100,7 +98,7 @@ where core.settings_daemon = block_on(cosmic_config::dbus::settings_daemon_proxy()).ok(); } - let (model, mut command) = T::init(core, flags); + let (model, command) = T::init(core, flags); (Self::new(model), command) } @@ -166,9 +164,6 @@ where } iced::Event::Window(window::Event::Focused) => return Some(Message::Focus(id)), iced::Event::Window(window::Event::Unfocused) => return Some(Message::Unfocus(id)), - iced::Event::Window(window::Event::Opened { .. }) => { - return Some(Message::WindowCreated(id)); - } #[cfg(feature = "wayland")] iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(event)) => { match event { @@ -660,13 +655,6 @@ impl Cosmic { core.focused_window = None; } } - Message::WindowCreated(id) => { - let core = self.app.core_mut(); - // Set the main window if it was not set to something else - if core.main_window.is_none() { - core.main_window = Some(id); - } - } #[cfg(feature = "applet")] Message::SuggestedBounds(b) => { tracing::info!("Suggested bounds: {b:?}"); diff --git a/src/app/mod.rs b/src/app/mod.rs index 1cf419d2..eb65747b 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -72,7 +72,7 @@ use { pub(crate) fn iced_settings( settings: Settings, flags: App::Flags, -) -> (iced::Settings, (Core, App::Flags, iced::window::Settings)) { +) -> (iced::Settings, (Core, App::Flags), iced::window::Settings) { preload_fonts(); let mut core = Core::default(); @@ -126,7 +126,7 @@ pub(crate) fn iced_settings( } window_settings.transparent = settings.transparent; - (iced, (core, flags, window_settings)) + (iced, (core, flags), window_settings) } /// Launch a COSMIC application with the given [`Settings`]. @@ -136,7 +136,7 @@ pub(crate) fn iced_settings( /// Returns error on application failure. pub fn run(settings: Settings, flags: App::Flags) -> iced::Result { let default_font = settings.default_font; - let (settings, mut flags) = iced_settings::(settings, flags); + let (settings, mut flags, window_settings) = iced_settings::(settings, flags); #[cfg(not(feature = "multi-window"))] { iced::application( @@ -149,7 +149,7 @@ pub fn run(settings: Settings, flags: App::Flags) -> iced::Res .theme(cosmic::Cosmic::theme) .window_size((500.0, 800.0)) .settings(settings) - .window(flags.2.clone()) + .window(window_settings) .run_with(move || cosmic::Cosmic::::init(flags)) } #[cfg(feature = "multi-window")] @@ -160,7 +160,7 @@ pub fn run(settings: Settings, flags: App::Flags) -> iced::Res cosmic::Cosmic::view, ); if flags.0.main_window.is_none() { - app = app.window(flags.2.clone()); + app = app.window(window_settings); flags.0.main_window = Some(iced_core::window::Id::RESERVED); } app.subscription(cosmic::Cosmic::subscription) @@ -370,7 +370,7 @@ where tracing::info!("Another instance is running"); Ok(()) } else { - let (settings, mut flags) = iced_settings::(settings, flags); + let (settings, mut flags, window_settings) = iced_settings::(settings, flags); flags.0.single_instance = true; #[cfg(not(feature = "multi-window"))] @@ -385,7 +385,7 @@ where .theme(cosmic::Cosmic::theme) .window_size((500.0, 800.0)) .settings(settings) - .window(flags.2.clone()) + .window(window_settings) .run_with(move || cosmic::Cosmic::::init(flags)) } #[cfg(feature = "multi-window")] @@ -396,8 +396,8 @@ where cosmic::Cosmic::view, ); if flags.0.main_window.is_none() { - app = app.window(flags.2.clone()); - _ = flags.0.main_window = Some(iced_core::window::Id::RESERVED); + app = app.window(window_settings); + flags.0.main_window = Some(iced_core::window::Id::RESERVED); } app.subscription(cosmic::Cosmic::subscription) .style(cosmic::Cosmic::style) diff --git a/src/applet/mod.rs b/src/applet/mod.rs index bff90489..b6e741fb 100644 --- a/src/applet/mod.rs +++ b/src/applet/mod.rs @@ -399,7 +399,7 @@ pub fn run(flags: App::Flags) -> iced::Result { .unwrap() .set_theme(settings.theme.theme_type.clone()); - let (iced_settings, (mut core, flags, mut window_settings)) = + let (iced_settings, (mut core, flags), mut window_settings) = iced_settings::(settings, flags); core.window.show_headerbar = false; core.window.sharp_corners = true; @@ -427,7 +427,7 @@ pub fn run(flags: App::Flags) -> iced::Result { .style(cosmic::Cosmic::style) .theme(cosmic::Cosmic::theme) .settings(iced_settings) - .run_with(move || cosmic::Cosmic::::init((core, flags, window_settings))) + .run_with(move || cosmic::Cosmic::::init((core, flags))) } #[must_use]