Use Option for time, and set DPMS on start
This commit is contained in:
parent
f2c83714c0
commit
90249780a5
2 changed files with 16 additions and 14 deletions
|
|
@ -4,13 +4,13 @@ use serde::{Deserialize, Serialize};
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone, CosmicConfigEntry)]
|
#[derive(Debug, Deserialize, Serialize, Clone, CosmicConfigEntry)]
|
||||||
pub struct CosmicIdleConfig {
|
pub struct CosmicIdleConfig {
|
||||||
/// Screen off idle time, in ms
|
/// Screen off idle time, in ms
|
||||||
pub screen_off_time: u32,
|
pub screen_off_time: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CosmicIdleConfig {
|
impl Default for CosmicIdleConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
screen_off_time: 10 * 60 * 1000,
|
screen_off_time: Some(10 * 60 * 1000),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
src/main.rs
26
src/main.rs
|
|
@ -120,7 +120,7 @@ struct State {
|
||||||
inner: StateInner,
|
inner: StateInner,
|
||||||
outputs: Vec<Output>,
|
outputs: Vec<Output>,
|
||||||
conf: CosmicIdleConfig,
|
conf: CosmicIdleConfig,
|
||||||
idle_notification: ext_idle_notification_v1::ExtIdleNotificationV1,
|
idle_notification: Option<ext_idle_notification_v1::ExtIdleNotificationV1>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
|
@ -136,13 +136,17 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recreate_notification(&mut self) {
|
fn recreate_notification(&mut self) {
|
||||||
self.idle_notification.destroy();
|
if let Some(idle_notification) = self.idle_notification.take() {
|
||||||
self.idle_notification = self.inner.idle_notifier.get_idle_notification(
|
idle_notification.destroy();
|
||||||
self.conf.screen_off_time,
|
}
|
||||||
&self.inner.seat,
|
if let Some(time) = self.conf.screen_off_time {
|
||||||
&self.inner.qh,
|
self.idle_notification = Some(self.inner.idle_notifier.get_idle_notification(
|
||||||
(),
|
time,
|
||||||
);
|
&self.inner.seat,
|
||||||
|
&self.inner.qh,
|
||||||
|
(),
|
||||||
|
));
|
||||||
|
}
|
||||||
self.update_idle(false);
|
self.update_idle(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -206,9 +210,6 @@ fn main() {
|
||||||
let config = cosmic_config::Config::new("com.system76.CosmicIdle", 1).unwrap();
|
let config = cosmic_config::Config::new("com.system76.CosmicIdle", 1).unwrap();
|
||||||
let conf = CosmicIdleConfig::get_entry(&config).unwrap_or_else(|(_, conf)| conf);
|
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 {
|
let mut state = State {
|
||||||
inner: StateInner {
|
inner: StateInner {
|
||||||
compositor,
|
compositor,
|
||||||
|
|
@ -220,10 +221,11 @@ fn main() {
|
||||||
seat,
|
seat,
|
||||||
qh,
|
qh,
|
||||||
},
|
},
|
||||||
idle_notification,
|
idle_notification: None,
|
||||||
outputs,
|
outputs,
|
||||||
conf,
|
conf,
|
||||||
};
|
};
|
||||||
|
state.recreate_notification();
|
||||||
|
|
||||||
let mut event_loop: EventLoop<State> = EventLoop::try_new().unwrap();
|
let mut event_loop: EventLoop<State> = EventLoop::try_new().unwrap();
|
||||||
WaylandSource::new(connection, event_queue)
|
WaylandSource::new(connection, event_queue)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue