dbus: Take lid-inhibitor-locks on systemd systems

This commit is contained in:
Victoria Brekenfeld 2025-07-29 15:57:38 +02:00 committed by Victoria Brekenfeld
parent 8648d4450e
commit f2fc1e9480
5 changed files with 70 additions and 1 deletions

17
src/dbus/logind.rs Normal file
View file

@ -0,0 +1,17 @@
use std::os::fd::OwnedFd;
use logind_zbus::manager::{InhibitType::HandleLidSwitch, ManagerProxyBlocking};
use zbus::blocking::Connection;
pub fn inhibit_lid() -> anyhow::Result<OwnedFd> {
let conn = Connection::system()?;
let proxy = ManagerProxyBlocking::new(&conn)?;
let fd = proxy.inhibit(
HandleLidSwitch,
"cosmic-comp",
"External output connected",
"block",
)?;
Ok(fd.into())
}

View file

@ -4,6 +4,8 @@ use calloop::{InsertError, LoopHandle, RegistrationToken};
use std::collections::HashMap;
use zbus::blocking::{fdo::DBusProxy, Connection};
#[cfg(feature = "systemd")]
pub mod logind;
mod power;
pub fn init(evlh: &LoopHandle<'static, State>) -> Result<Vec<RegistrationToken>> {