Add integration to log out from COSMIC session
This commit is contained in:
parent
73d2107dc9
commit
d03966ae42
3 changed files with 29 additions and 3 deletions
11
applets/cosmic-applet-power/src/cosmic_session.rs
Normal file
11
applets/cosmic-applet-power/src/cosmic_session.rs
Normal 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<()>;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue