Add support for logging out via gnome session manager
This commit is contained in:
parent
dc92340774
commit
0881eb4fa8
3 changed files with 144 additions and 5 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#[macro_use]
|
||||
extern crate relm4_macros;
|
||||
|
||||
pub mod session_manager;
|
||||
pub mod ui;
|
||||
|
||||
use gtk4::{gio::ApplicationFlags, prelude::*, Orientation, Separator};
|
||||
|
|
|
|||
139
applets/cosmic-applet-power/src/session_manager.rs
Normal file
139
applets/cosmic-applet-power/src/session_manager.rs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
//! # DBus interface proxy for: `org.gnome.SessionManager`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/gnome/SessionManager' from service 'org.gnome.SessionManager' on session bus`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the
|
||||
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
|
||||
//! section of the zbus documentation.
|
||||
//!
|
||||
//! This DBus object implements
|
||||
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
|
||||
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
|
||||
//!
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(interface = "org.gnome.SessionManager")]
|
||||
trait SessionManager {
|
||||
/// CanRebootToFirmwareSetup method
|
||||
fn can_reboot_to_firmware_setup(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// CanShutdown method
|
||||
fn can_shutdown(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetClients method
|
||||
fn get_clients(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
|
||||
|
||||
/// GetInhibitors method
|
||||
fn get_inhibitors(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
|
||||
|
||||
/// GetLocale method
|
||||
fn get_locale(&self, category: i32) -> zbus::Result<String>;
|
||||
|
||||
/// Inhibit method
|
||||
fn inhibit(
|
||||
&self,
|
||||
app_id: &str,
|
||||
toplevel_xid: u32,
|
||||
reason: &str,
|
||||
flags: u32,
|
||||
) -> zbus::Result<u32>;
|
||||
|
||||
/// InitializationError method
|
||||
fn initialization_error(&self, message: &str, fatal: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Initialized method
|
||||
fn initialized(&self) -> zbus::Result<()>;
|
||||
|
||||
/// IsAutostartConditionHandled method
|
||||
fn is_autostart_condition_handled(&self, condition: &str) -> zbus::Result<bool>;
|
||||
|
||||
/// IsInhibited method
|
||||
fn is_inhibited(&self, flags: u32) -> zbus::Result<bool>;
|
||||
|
||||
/// IsSessionRunning method
|
||||
fn is_session_running(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Logout method
|
||||
fn logout(&self, mode: u32) -> zbus::Result<()>;
|
||||
|
||||
/// Reboot method
|
||||
fn reboot(&self) -> zbus::Result<()>;
|
||||
|
||||
/// RegisterClient method
|
||||
fn register_client(
|
||||
&self,
|
||||
app_id: &str,
|
||||
client_startup_id: &str,
|
||||
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// RequestReboot method
|
||||
fn request_reboot(&self) -> zbus::Result<()>;
|
||||
|
||||
/// RequestShutdown method
|
||||
fn request_shutdown(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SetRebootToFirmwareSetup method
|
||||
fn set_reboot_to_firmware_setup(&self, enable: bool) -> zbus::Result<()>;
|
||||
|
||||
/// Setenv method
|
||||
fn setenv(&self, variable: &str, value: &str) -> zbus::Result<()>;
|
||||
|
||||
/// Shutdown method
|
||||
fn shutdown(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Uninhibit method
|
||||
fn uninhibit(&self, inhibit_cookie: u32) -> zbus::Result<()>;
|
||||
|
||||
/// UnregisterClient method
|
||||
fn unregister_client(&self, client_id: &zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// ClientAdded signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn client_added(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// ClientRemoved signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn client_removed(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// InhibitorAdded signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn inhibitor_added(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// InhibitorRemoved signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn inhibitor_removed(&self, id: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// SessionOver signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn session_over(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SessionRunning signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn session_running(&self) -> zbus::Result<()>;
|
||||
|
||||
/// InhibitedActions property
|
||||
#[dbus_proxy(property)]
|
||||
fn inhibited_actions(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Renderer property
|
||||
#[dbus_proxy(property)]
|
||||
fn renderer(&self) -> zbus::Result<String>;
|
||||
|
||||
/// SessionIsActive property
|
||||
#[dbus_proxy(property)]
|
||||
fn session_is_active(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// SessionName property
|
||||
#[dbus_proxy(property)]
|
||||
fn session_name(&self) -> zbus::Result<String>;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
use crate::RT;
|
||||
use crate::{session_manager::SessionManagerProxy, RT};
|
||||
use gtk4::{prelude::*, Align, Button, Image, Label, Orientation};
|
||||
use logind_zbus::{
|
||||
manager::ManagerProxy,
|
||||
|
|
@ -35,10 +35,9 @@ async fn lock_screen() -> zbus::Result<()> {
|
|||
}
|
||||
|
||||
async fn log_out() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
// TODO: figure out what function logs the current user out
|
||||
manager_proxy.lock_sessions().await
|
||||
let connection = Connection::session().await?;
|
||||
let manager_proxy = SessionManagerProxy::new(&connection).await?;
|
||||
manager_proxy.logout(0).await
|
||||
}
|
||||
|
||||
pub fn build() -> gtk4::Box {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue