diff --git a/cosmic-idle-config/src/lib.rs b/cosmic-idle-config/src/lib.rs index ce1ae96..508059a 100644 --- a/cosmic-idle-config/src/lib.rs +++ b/cosmic-idle-config/src/lib.rs @@ -4,13 +4,13 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize, Clone, CosmicConfigEntry)] pub struct CosmicIdleConfig { /// Screen off idle time, in ms - pub screen_off_time: u32, + pub screen_off_time: Option, } impl Default for CosmicIdleConfig { fn default() -> Self { Self { - screen_off_time: 10 * 60 * 1000, + screen_off_time: Some(10 * 60 * 1000), } } } diff --git a/src/main.rs b/src/main.rs index 5ceeb7d..e4d3b2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,7 +120,7 @@ struct State { inner: StateInner, outputs: Vec, conf: CosmicIdleConfig, - idle_notification: ext_idle_notification_v1::ExtIdleNotificationV1, + idle_notification: Option, } impl State { @@ -136,13 +136,17 @@ impl State { } fn recreate_notification(&mut self) { - self.idle_notification.destroy(); - self.idle_notification = self.inner.idle_notifier.get_idle_notification( - self.conf.screen_off_time, - &self.inner.seat, - &self.inner.qh, - (), - ); + if let Some(idle_notification) = self.idle_notification.take() { + idle_notification.destroy(); + } + if let Some(time) = self.conf.screen_off_time { + self.idle_notification = Some(self.inner.idle_notifier.get_idle_notification( + time, + &self.inner.seat, + &self.inner.qh, + (), + )); + } self.update_idle(false); } } @@ -206,9 +210,6 @@ fn main() { let config = cosmic_config::Config::new("com.system76.CosmicIdle", 1).unwrap(); let conf = CosmicIdleConfig::get_entry(&config).unwrap_or_else(|(_, conf)| conf); - let idle_notification = - idle_notifier.get_idle_notification(conf.screen_off_time, &seat, &qh, ()); - let mut state = State { inner: StateInner { compositor, @@ -220,10 +221,11 @@ fn main() { seat, qh, }, - idle_notification, + idle_notification: None, outputs, conf, }; + state.recreate_notification(); let mut event_loop: EventLoop = EventLoop::try_new().unwrap(); WaylandSource::new(connection, event_queue)