diff --git a/iced_examples/zbus_invoked_widget/src/main.rs b/iced_examples/zbus_invoked_widget/src/main.rs index c4bc32d..5d9827a 100644 --- a/iced_examples/zbus_invoked_widget/src/main.rs +++ b/iced_examples/zbus_invoked_widget/src/main.rs @@ -9,7 +9,7 @@ use iced_runtime::window::Action as WindowAction; use iced_runtime::Action; use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; -use iced_layershell::settings::Settings; +use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; use iced_layershell::MultiApplication; use zbus::{interface, ConnectionBuilder}; @@ -23,7 +23,13 @@ struct Counter { text: String, } pub fn main() -> Result<(), iced_layershell::Error> { - Counter::run(Settings::default()) + Counter::run(Settings { + layer_settings: LayerShellSettings { + start_mode: StartMode::Background, + ..Default::default() + }, + ..Default::default() + }) } #[derive(Debug, Clone)] @@ -64,8 +70,6 @@ impl MultiApplication for Counter { type Executor = iced::executor::Default; type WindowInfo = (); - const BACKGROUND_MODE: bool = true; - fn set_id_info(&mut self, _id: iced_runtime::core::window::Id, _info: Self::WindowInfo) { self.window_shown = true; } diff --git a/iced_layershell/src/lib.rs b/iced_layershell/src/lib.rs index fd3fe70..81a9b40 100644 --- a/iced_layershell/src/lib.rs +++ b/iced_layershell/src/lib.rs @@ -260,8 +260,6 @@ pub trait MultiApplication: Sized { type Theme: Default + DefaultStyle; - const BACKGROUND_MODE: bool = false; - /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -409,8 +407,6 @@ where type WindowInfo = A::WindowInfo; - const BACKGROUND_MODE: bool = A::BACKGROUND_MODE; - fn new(flags: Self::Flags) -> (Self, Task) { let (app, command) = A::new(flags); diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index 32ef4d7..22c25bb 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -63,8 +63,6 @@ where type WindowInfo; - const BACKGROUND_MODE: bool; - /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -187,9 +185,9 @@ where runtime.enter(|| application.subscription().map(Action::Output)), )); + let is_background_mode = settings.layer_settings.start_mode.is_background(); let ev: WindowState = layershellev::WindowState::new(&application.namespace()) .with_start_mode(settings.layer_settings.start_mode) - .with_background_or_not(A::BACKGROUND_MODE) .with_use_display_handle(true) .with_option_size(settings.layer_settings.size) .with_layer(settings.layer_settings.layer) @@ -215,6 +213,7 @@ where event_receiver, control_sender, window, + is_background_mode, )); let mut context = task::Context::from_waker(task::noop_waker_ref()); @@ -461,6 +460,7 @@ async fn run_instance( >, mut control_sender: mpsc::UnboundedSender>, window: Arc, + is_background_mode: bool, ) where A: Application + 'static, E: Executor + 'static, @@ -746,7 +746,7 @@ async fn run_instance( // HACK: this logic is just from iced, but seems if there is no main window, // any window will not get Outdated state. // So here just check if there is window_events - if A::BACKGROUND_MODE && has_window_event { + if is_background_mode && has_window_event { custom_actions.push(LayerShellActions::RedrawAll); } @@ -765,7 +765,7 @@ async fn run_instance( window.state.synchronize(&application); } - if !A::BACKGROUND_MODE { + if !is_background_mode { custom_actions.push(LayerShellActions::RedrawAll); } diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index f9e3f77..d3ac426 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -659,17 +659,16 @@ pub enum StartMode { } impl StartMode { - #[allow(unused)] - fn is_current_active(&self) -> bool { + pub fn is_current_active(&self) -> bool { matches!(self, Self::CurrentActive) } - fn is_background(&self) -> bool { + pub fn is_background(&self) -> bool { matches!(self, Self::Background) } - fn is_allscreen(&self) -> bool { + pub fn is_allscreen(&self) -> bool { matches!(self, Self::AllScreen) } - fn is_with_target(&self) -> bool { + pub fn is_with_target(&self) -> bool { matches!(self, Self::TargetScreen(_)) } }