2025-07-29 15:57:38 +02:00
|
|
|
use std::os::fd::OwnedFd;
|
|
|
|
|
|
2025-08-11 16:51:57 +02:00
|
|
|
use anyhow::{Context, Result};
|
2025-07-29 15:57:38 +02:00
|
|
|
use logind_zbus::manager::{InhibitType::HandleLidSwitch, ManagerProxyBlocking};
|
|
|
|
|
use zbus::blocking::Connection;
|
|
|
|
|
|
2025-08-11 16:51:57 +02:00
|
|
|
pub fn inhibit_lid() -> Result<OwnedFd> {
|
2025-07-29 15:57:38 +02:00
|
|
|
let conn = Connection::system()?;
|
|
|
|
|
let proxy = ManagerProxyBlocking::new(&conn)?;
|
|
|
|
|
let fd = proxy.inhibit(
|
|
|
|
|
HandleLidSwitch,
|
|
|
|
|
"cosmic-comp",
|
|
|
|
|
"External output connected",
|
|
|
|
|
"block",
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
Ok(fd.into())
|
|
|
|
|
}
|
2025-08-11 16:51:57 +02:00
|
|
|
|
|
|
|
|
pub fn lid_closed() -> Result<bool> {
|
|
|
|
|
let conn = Connection::system()?;
|
|
|
|
|
let proxy = ManagerProxyBlocking::new(&conn)?;
|
|
|
|
|
proxy.lid_closed().context("Failed to talk to logind")
|
|
|
|
|
}
|