diff --git a/applets/cosmic-applet-power/src/main.rs b/applets/cosmic-applet-power/src/main.rs index 91dd5b4e..ef7623e5 100644 --- a/applets/cosmic-applet-power/src/main.rs +++ b/applets/cosmic-applet-power/src/main.rs @@ -3,6 +3,7 @@ #[macro_use] extern crate relm4_macros; +pub mod session_manager; pub mod ui; use gtk4::{gio::ApplicationFlags, prelude::*, Orientation, Separator}; diff --git a/applets/cosmic-applet-power/src/session_manager.rs b/applets/cosmic-applet-power/src/session_manager.rs new file mode 100644 index 00000000..70fb4f29 --- /dev/null +++ b/applets/cosmic-applet-power/src/session_manager.rs @@ -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; + + /// CanShutdown method + fn can_shutdown(&self) -> zbus::Result; + + /// GetClients method + fn get_clients(&self) -> zbus::Result>; + + /// GetInhibitors method + fn get_inhibitors(&self) -> zbus::Result>; + + /// GetLocale method + fn get_locale(&self, category: i32) -> zbus::Result; + + /// Inhibit method + fn inhibit( + &self, + app_id: &str, + toplevel_xid: u32, + reason: &str, + flags: u32, + ) -> zbus::Result; + + /// 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; + + /// IsInhibited method + fn is_inhibited(&self, flags: u32) -> zbus::Result; + + /// IsSessionRunning method + fn is_session_running(&self) -> zbus::Result; + + /// 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; + + /// 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; + + /// Renderer property + #[dbus_proxy(property)] + fn renderer(&self) -> zbus::Result; + + /// SessionIsActive property + #[dbus_proxy(property)] + fn session_is_active(&self) -> zbus::Result; + + /// SessionName property + #[dbus_proxy(property)] + fn session_name(&self) -> zbus::Result; +} diff --git a/applets/cosmic-applet-power/src/ui/session.rs b/applets/cosmic-applet-power/src/ui/session.rs index 0ce50260..426b47e2 100644 --- a/applets/cosmic-applet-power/src/ui/session.rs +++ b/applets/cosmic-applet-power/src/ui/session.rs @@ -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 {