Module ashpd::desktop::inhibit

source ·
Expand description

Inhibit the session from being restarted or the user from logging out.

§Examples

How to inhibit logout/user switch

use std::{thread, time};

use ashpd::{
    desktop::inhibit::{InhibitFlags, InhibitProxy, SessionState},
    WindowIdentifier,
};
use futures_util::StreamExt;

async fn run() -> ashpd::Result<()> {
    let proxy = InhibitProxy::new().await?;
    let identifier = WindowIdentifier::default();

    let session = proxy.create_monitor(&identifier).await?;

    let state = proxy.receive_state_changed().await?.next().await.unwrap();
    match state.session_state() {
        SessionState::Running => (),
        SessionState::QueryEnd => {
            proxy
                .inhibit(
                    &identifier,
                    InhibitFlags::Logout | InhibitFlags::UserSwitch,
                    "please save the opened project first",
                )
                .await?;
            thread::sleep(time::Duration::from_secs(1));
            proxy.query_end_response(&session).await?;
        }
        SessionState::Ending => {
            println!("ending the session");
        }
    }
    Ok(())
}

Structs§

  • The interface lets sandboxed applications inhibit the user session from ending, suspending, idling or getting switched away.
  • A response received when the state_changed signal is received.

Enums§

  • The actions to inhibit that can end the user’s session
  • The current state of the user’s session.