state/lid-inhibit: Take current lid state into account
This commit is contained in:
parent
de43fb1f0e
commit
74e90f793f
4 changed files with 83 additions and 37 deletions
|
|
@ -1,9 +1,10 @@
|
|||
use std::os::fd::OwnedFd;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use logind_zbus::manager::{InhibitType::HandleLidSwitch, ManagerProxyBlocking};
|
||||
use zbus::blocking::Connection;
|
||||
|
||||
pub fn inhibit_lid() -> anyhow::Result<OwnedFd> {
|
||||
pub fn inhibit_lid() -> Result<OwnedFd> {
|
||||
let conn = Connection::system()?;
|
||||
let proxy = ManagerProxyBlocking::new(&conn)?;
|
||||
let fd = proxy.inhibit(
|
||||
|
|
@ -15,3 +16,9 @@ pub fn inhibit_lid() -> anyhow::Result<OwnedFd> {
|
|||
|
||||
Ok(fd.into())
|
||||
}
|
||||
|
||||
pub fn lid_closed() -> Result<bool> {
|
||||
let conn = Connection::system()?;
|
||||
let proxy = ManagerProxyBlocking::new(&conn)?;
|
||||
proxy.lid_closed().context("Failed to talk to logind")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue