diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 83 |
1 files changed, 57 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs index 8c9a72e..51dd23a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,13 @@ use futures_util::StreamExt; default_path = "/org/freedesktop/login1" )] trait LoginManager { - fn inhibit(&self, what: &str, who: &str, why: &str, mode: &str) -> zbus::Result<zvariant::OwnedFd>; + fn inhibit( + &self, + what: &str, + who: &str, + why: &str, + mode: &str, + ) -> zbus::Result<zvariant::OwnedFd>; } #[zbus::proxy( @@ -23,7 +29,7 @@ trait LoginSession { #[derive(zvariant::DeserializeDict, zvariant::SerializeDict, zvariant::Type, PartialEq, Eq)] #[zvariant(signature = "dict")] struct InhibitOptions { - reason: zvariant::Optional<String> + reason: zvariant::Optional<String>, } #[derive(zvariant::Type, serde::Serialize, serde::Deserialize)] @@ -31,7 +37,7 @@ struct InhibitOptions { enum SessionState { Running, QueryEnd, - Ending + Ending, } #[derive(zvariant::DeserializeDict, zvariant::SerializeDict, zvariant::Type)] @@ -44,15 +50,20 @@ struct State { struct Request { app_id: String, path: zvariant::OwnedObjectPath, - inhibitor: Option<zvariant::OwnedFd> + inhibitor: Option<zvariant::OwnedFd>, } #[zbus::interface(name = "org.freedesktop.impl.portal.Request")] impl Request { - async fn close(&mut self, #[zbus(object_server)] object_server: &zbus::ObjectServer) -> zbus::fdo::Result<()> { + async fn close( + &mut self, + #[zbus(object_server)] object_server: &zbus::ObjectServer, + ) -> zbus::fdo::Result<()> { // Drop the file descriptor that represents the inhibitions. self.inhibitor.take(); // This might not actually deadlock if I'm lucky. - object_server.remove::<Self, zvariant::ObjectPath<'_>>(self.path.as_ref()).await?; + object_server + .remove::<Self, zvariant::ObjectPath<'_>>(self.path.as_ref()) + .await?; Ok(()) } } @@ -71,11 +82,13 @@ impl Session { async fn close( &mut self, #[zbus(object_server)] object_server: &zbus::ObjectServer, - #[zbus(signal_emitter)] signal_emitter: zbus::object_server::SignalEmitter<'_> + #[zbus(signal_emitter)] signal_emitter: zbus::object_server::SignalEmitter<'_>, ) -> zbus::fdo::Result<()> { Self::closed(&signal_emitter).await?; // This might not actually deadlock if I'm lucky. - object_server.remove::<Self, zvariant::ObjectPath<'_>>(self.path.as_ref()).await?; + object_server + .remove::<Self, zvariant::ObjectPath<'_>>(self.path.as_ref()) + .await?; Ok(()) } @@ -86,7 +99,7 @@ impl Session { struct InhibitService { logind: LoginManagerProxy<'static>, - sessions: Vec<zvariant::ObjectPath<'static>> + sessions: Vec<zvariant::ObjectPath<'static>>, } #[zbus::interface(name = "org.freedesktop.impl.portal.Inhibit")] @@ -122,16 +135,25 @@ impl InhibitService { if (flags & 8) == 8 { what.push("idle"); } - object_server.at(handle.clone(), Request { - app_id: app_id.to_owned(), - inhibitor: Some(self.logind.inhibit( - &what.join(":"), - app_id, - options.reason.as_deref().unwrap_or_default(), - "block" - ).await?), - path: handle.to_owned().into() - }).await?; + object_server + .at( + handle.clone(), + Request { + app_id: app_id.to_owned(), + inhibitor: Some( + self.logind + .inhibit( + &what.join(":"), + app_id, + options.reason.as_deref().unwrap_or_default(), + "block", + ) + .await?, + ), + path: handle.to_owned().into(), + }, + ) + .await?; Ok(()) } @@ -149,7 +171,7 @@ impl InhibitService { ) -> zbus::fdo::Result<u32> { let session = Session { app_id: app_id.to_owned(), - path: session_handle.clone().into_owned().into() + path: session_handle.clone().into_owned().into(), }; object_server.at(&session_handle, session).await?; self.sessions.push(session_handle.clone().into_owned()); @@ -193,18 +215,27 @@ async fn main() -> Result<(), zbus::Error> { .build() .await?; dbg!(&session); - let mut lock_changes: zbus::proxy::PropertyStream<'_, bool> = session.receive_locked_hint_changed().await; + let mut lock_changes: zbus::proxy::PropertyStream<'_, bool> = + session.receive_locked_hint_changed().await; loop { let change = lock_changes.next().await.expect("property stream broke"); - let service = _conn.object_server().interface::<_, InhibitService>("/").await?; + let service = _conn + .object_server() + .interface::<_, InhibitService>("/") + .await?; let locked = dbg!(change.get().await?); let sessions = dbg!(service.get().await.sessions.clone()); for session in sessions { - InhibitService::state_changed(service.signal_emitter(), session, State { - screensaver_active: locked, - session_state: SessionState::Running, - }).await?; + InhibitService::state_changed( + service.signal_emitter(), + session, + State { + screensaver_active: locked, + session_state: SessionState::Running, + }, + ) + .await?; } eprintln!("finished processing lock/unlock event"); } |