Add integration to log out from COSMIC session

This commit is contained in:
Lucy 2022-08-01 13:18:24 -04:00
parent 73d2107dc9
commit d03966ae42
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
3 changed files with 29 additions and 3 deletions

View file

@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use zbus::dbus_proxy;
#[dbus_proxy(
interface = "com.system76.CosmicSession",
default_service = "com.system76.CosmicSession",
default_path = "/com/system76/CosmicSession"
)]
trait CosmicSession {
fn exit(&self) -> zbus::Result<()>;
}

View file

@ -5,6 +5,7 @@ extern crate relm4_macros;
pub mod session_manager;
pub mod ui;
pub mod cosmic_session;
use gtk4::{gio::ApplicationFlags, prelude::*, Align, Button, Label, Orientation, Separator};
use once_cell::sync::Lazy;

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use crate::{session_manager::SessionManagerProxy, RT};
use crate::{cosmic_session::CosmicSessionProxy, session_manager::SessionManagerProxy, RT};
use gtk4::{prelude::*, Align, Button, Image, Label, Orientation};
use logind_zbus::{
manager::ManagerProxy,
@ -35,9 +35,23 @@ async fn lock_screen() -> zbus::Result<()> {
}
async fn log_out() -> zbus::Result<()> {
let session_type = std::env::var("XDG_CURRENT_DESKTOP").ok();
let connection = Connection::session().await?;
let manager_proxy = SessionManagerProxy::new(&connection).await?;
manager_proxy.logout(0).await
match session_type.as_ref().map(|s| s.trim()) {
Some("pop:COSMIC") => {
let cosmic_session = CosmicSessionProxy::new(&connection).await?;
cosmic_session.exit().await?;
}
Some("pop:GNOME") => {
let manager_proxy = SessionManagerProxy::new(&connection).await?;
manager_proxy.logout(0).await?;
}
Some(desktop) => {
eprintln!("unknown XDG_CURRENT_DESKTOP: {desktop}")
}
None => {}
}
Ok(())
}
pub fn build() -> gtk4::Box {