Ignore idle if inhibitor is active
This commit is contained in:
parent
d6d811e1f8
commit
f1537b1a92
2 changed files with 21 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ use std::sync::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Inhibitor {
|
pub struct Inhibitor {
|
||||||
cookie: u32,
|
cookie: u32,
|
||||||
application_name: String,
|
application_name: String,
|
||||||
reason_for_inhibit: String,
|
reason_for_inhibit: String,
|
||||||
|
|
@ -62,9 +62,10 @@ impl Screensaver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn serve(conn: &zbus::Connection) -> zbus::Result<()> {
|
pub async fn serve(
|
||||||
let inhibitors = Arc::new(Mutex::new(Vec::new()));
|
conn: &zbus::Connection,
|
||||||
|
inhibitors: Arc<Mutex<Vec<Inhibitor>>>,
|
||||||
|
) -> zbus::Result<()> {
|
||||||
conn.request_name_with_flags(
|
conn.request_name_with_flags(
|
||||||
"org.freedesktop.ScreenSaver",
|
"org.freedesktop.ScreenSaver",
|
||||||
zbus::fdo::RequestNameFlags::ReplaceExisting.into(),
|
zbus::fdo::RequestNameFlags::ReplaceExisting.into(),
|
||||||
|
|
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -8,6 +8,7 @@ use futures_lite::stream::StreamExt;
|
||||||
use keyframe::{ease, functions::EaseInOut};
|
use keyframe::{ease, functions::EaseInOut};
|
||||||
use std::{
|
use std::{
|
||||||
process::Command,
|
process::Command,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
use upower_dbus::UPowerProxy;
|
use upower_dbus::UPowerProxy;
|
||||||
|
|
@ -148,6 +149,7 @@ struct Output {
|
||||||
global_name: u32,
|
global_name: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Immutate references to globals, needed for calls
|
||||||
struct StateInner {
|
struct StateInner {
|
||||||
output_power_manager: zwlr_output_power_manager_v1::ZwlrOutputPowerManagerV1,
|
output_power_manager: zwlr_output_power_manager_v1::ZwlrOutputPowerManagerV1,
|
||||||
compositor: wl_compositor::WlCompositor,
|
compositor: wl_compositor::WlCompositor,
|
||||||
|
|
@ -166,10 +168,14 @@ struct State {
|
||||||
screen_off_idle_notification: Option<IdleNotification>,
|
screen_off_idle_notification: Option<IdleNotification>,
|
||||||
suspend_idle_notification: Option<IdleNotification>,
|
suspend_idle_notification: Option<IdleNotification>,
|
||||||
on_battery: bool,
|
on_battery: bool,
|
||||||
|
screensaver_inhibitors: Arc<Mutex<Vec<freedesktop_screensaver::Inhibitor>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
fn update_screen_off_idle(&mut self, is_idle: bool) {
|
fn update_screen_off_idle(&mut self, is_idle: bool) {
|
||||||
|
if !self.screensaver_inhibitors.lock().unwrap().is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for output in &mut self.outputs {
|
for output in &mut self.outputs {
|
||||||
if is_idle {
|
if is_idle {
|
||||||
output.fade_surface = Some(FadeBlackSurface::new(&self.inner, &output.output));
|
output.fade_surface = Some(FadeBlackSurface::new(&self.inner, &output.output));
|
||||||
|
|
@ -181,6 +187,9 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_suspend_idle(&mut self, is_idle: bool) {
|
fn update_suspend_idle(&mut self, is_idle: bool) {
|
||||||
|
if !self.screensaver_inhibitors.lock().unwrap().is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if is_idle {
|
if is_idle {
|
||||||
// TODO: Make command configurable
|
// TODO: Make command configurable
|
||||||
match Command::new("systemctl").arg("suspend").status() {
|
match Command::new("systemctl").arg("suspend").status() {
|
||||||
|
|
@ -288,6 +297,8 @@ fn main() {
|
||||||
conf
|
conf
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let screensaver_inhibitors = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
inner: StateInner {
|
inner: StateInner {
|
||||||
compositor,
|
compositor,
|
||||||
|
|
@ -304,6 +315,7 @@ fn main() {
|
||||||
outputs,
|
outputs,
|
||||||
conf,
|
conf,
|
||||||
on_battery: false,
|
on_battery: false,
|
||||||
|
screensaver_inhibitors: screensaver_inhibitors.clone(),
|
||||||
};
|
};
|
||||||
state.recreate_notification();
|
state.recreate_notification();
|
||||||
|
|
||||||
|
|
@ -333,9 +345,11 @@ fn main() {
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
scheduler
|
scheduler
|
||||||
.schedule(async {
|
.schedule(async move {
|
||||||
if let Ok(connection) = zbus::Connection::session().await {
|
if let Ok(connection) = zbus::Connection::session().await {
|
||||||
if let Err(err) = freedesktop_screensaver::serve(&connection).await {
|
if let Err(err) =
|
||||||
|
freedesktop_screensaver::serve(&connection, screensaver_inhibitors).await
|
||||||
|
{
|
||||||
log::error!("failed to serve FreeDesktop screensaver interface: {}", err);
|
log::error!("failed to serve FreeDesktop screensaver interface: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue