Move Cosmic Applets into new Dir & remove old applets
This commit is contained in:
parent
813e6c0aff
commit
a682b8deb0
134 changed files with 0 additions and 1354 deletions
11
cosmic-applet-power/src/cosmic_session.rs
Normal file
11
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<()>;
|
||||
}
|
||||
295
cosmic-applet-power/src/main.rs
Normal file
295
cosmic-applet-power/src/main.rs
Normal file
|
|
@ -0,0 +1,295 @@
|
|||
use std::process;
|
||||
|
||||
use iced::widget::Space;
|
||||
|
||||
use cosmic::applet::CosmicAppletHelper;
|
||||
use cosmic::widget::{horizontal_rule, icon};
|
||||
use cosmic::Renderer;
|
||||
|
||||
use cosmic::iced::{
|
||||
executor,
|
||||
widget::{button, column, row},
|
||||
window, Alignment, Application, Command, Length, Subscription,
|
||||
};
|
||||
use cosmic::iced_style::application::{self, Appearance};
|
||||
use cosmic::iced_style::svg;
|
||||
use cosmic::theme::{self, Svg};
|
||||
use cosmic::{Element, Theme};
|
||||
|
||||
use iced_sctk::application::SurfaceIdWrapper;
|
||||
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
||||
use iced_sctk::widget::Row;
|
||||
use iced_sctk::Color;
|
||||
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use logind_zbus::session::{SessionProxy, SessionType};
|
||||
use logind_zbus::user::UserProxy;
|
||||
use nix::unistd::getuid;
|
||||
use zbus::Connection;
|
||||
|
||||
pub mod cosmic_session;
|
||||
pub mod session_manager;
|
||||
|
||||
use crate::cosmic_session::CosmicSessionProxy;
|
||||
use crate::session_manager::SessionManagerProxy;
|
||||
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
Power::run(helper.window_settings())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Power {
|
||||
applet_helper: CosmicAppletHelper,
|
||||
icon_name: String,
|
||||
theme: Theme,
|
||||
popup: Option<window::Id>,
|
||||
id_ctr: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
Lock,
|
||||
LogOut,
|
||||
Suspend,
|
||||
Restart,
|
||||
Shutdown,
|
||||
TogglePopup,
|
||||
Settings,
|
||||
Ignore,
|
||||
Zbus(Result<(), zbus::Error>),
|
||||
}
|
||||
|
||||
impl Application for Power {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Power, Command<Message>) {
|
||||
(
|
||||
Power {
|
||||
icon_name: "system-shutdown-symbolic".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Power")
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
self.theme
|
||||
}
|
||||
|
||||
fn close_requested(&self, _id: iced_sctk::application::SurfaceIdWrapper) -> Self::Message {
|
||||
Message::Ignore
|
||||
}
|
||||
|
||||
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
|
||||
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
|
||||
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
|
||||
text_color: theme.cosmic().on_bg_color().into(),
|
||||
})
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
Subscription::none()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
match message {
|
||||
Message::TogglePopup => {
|
||||
if let Some(p) = self.popup.take() {
|
||||
destroy_popup(p)
|
||||
} else {
|
||||
self.id_ctr += 1;
|
||||
let new_id = window::Id::new(self.id_ctr);
|
||||
self.popup.replace(new_id);
|
||||
|
||||
let popup_settings = self.applet_helper.get_popup_settings(
|
||||
window::Id::new(0),
|
||||
new_id,
|
||||
(400, 300),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
get_popup(popup_settings)
|
||||
}
|
||||
}
|
||||
Message::Settings => {
|
||||
let _ = process::Command::new("cosmic-settings").spawn();
|
||||
Command::none()
|
||||
}
|
||||
Message::Lock => Command::perform(lock(), Message::Zbus),
|
||||
Message::LogOut => Command::perform(log_out(), Message::Zbus),
|
||||
Message::Suspend => Command::perform(suspend(), Message::Zbus),
|
||||
Message::Restart => Command::perform(restart(), Message::Zbus),
|
||||
Message::Shutdown => Command::perform(shutdown(), Message::Zbus),
|
||||
Message::Zbus(result) => {
|
||||
if let Err(e) = result {
|
||||
eprintln!("cosmic-applet-power ERROR: '{}'", e);
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
Message::Ignore => Command::none(),
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
|
||||
match id {
|
||||
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
|
||||
SurfaceIdWrapper::Window(_) => self
|
||||
.applet_helper
|
||||
.icon_button(&self.icon_name)
|
||||
.on_press(Message::TogglePopup)
|
||||
.into(),
|
||||
SurfaceIdWrapper::Popup(_) => {
|
||||
let settings = row_button(vec!["Settings...".into()])
|
||||
.on_press(Message::Settings);
|
||||
|
||||
let session = column![
|
||||
row_button(vec![
|
||||
text_icon("system-lock-screen-symbolic", 24).into(),
|
||||
"Lock Screen".into(),
|
||||
Space::with_width(Length::Fill).into(),
|
||||
"Super + Escape".into(),
|
||||
])
|
||||
.on_press(Message::Lock),
|
||||
row_button(vec![
|
||||
text_icon("system-log-out-symbolic", 24).into(),
|
||||
"Log Out".into(),
|
||||
Space::with_width(Length::Fill).into(),
|
||||
"Ctrl + Alt + Delete".into(),
|
||||
])
|
||||
.on_press(Message::LogOut),
|
||||
];
|
||||
|
||||
let power = row![
|
||||
power_buttons("system-lock-screen-symbolic", "Suspend")
|
||||
.on_press(Message::Suspend),
|
||||
power_buttons("system-restart-symbolic", "Restart").on_press(Message::Restart),
|
||||
power_buttons("system-shutdown-symbolic", "Shutdown")
|
||||
.on_press(Message::Shutdown),
|
||||
]
|
||||
.spacing(24)
|
||||
.padding([0, 24]);
|
||||
|
||||
let content = column![]
|
||||
.align_items(Alignment::Start)
|
||||
.spacing(12)
|
||||
.padding([24, 0])
|
||||
.push(settings)
|
||||
.push(horizontal_rule(1))
|
||||
.push(session)
|
||||
.push(horizontal_rule(1))
|
||||
.push(power);
|
||||
|
||||
self.applet_helper.popup_container(content).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ### UI Helplers
|
||||
|
||||
// todo put into libcosmic doing so will fix the row_button's boarder radius
|
||||
fn row_button(mut content: Vec<Element<Message>>) -> iced_sctk::widget::Button<Message, Renderer> {
|
||||
content.insert(0, Space::with_width(Length::Units(24)).into());
|
||||
content.push(Space::with_width(Length::Units(24)).into());
|
||||
|
||||
button(
|
||||
Row::with_children(content)
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Units(35))
|
||||
.style(theme::Button::Text)
|
||||
}
|
||||
|
||||
fn power_buttons<'a>(
|
||||
name: &'a str,
|
||||
text: &'a str,
|
||||
) -> iced_sctk::widget::Button<'a, Message, Renderer> {
|
||||
button(
|
||||
column![text_icon(name, 40), text]
|
||||
.spacing(5)
|
||||
.align_items(Alignment::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Units(75))
|
||||
.style(theme::Button::Text)
|
||||
}
|
||||
|
||||
fn text_icon(name: &str, size: u16) -> cosmic::widget::Icon {
|
||||
icon(name, size).style(Svg::Custom(|theme| svg::Appearance {
|
||||
fill: Some(theme.palette().text),
|
||||
}))
|
||||
}
|
||||
|
||||
// ### System helpers
|
||||
|
||||
async fn restart() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
manager_proxy.reboot(true).await
|
||||
}
|
||||
|
||||
async fn shutdown() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
manager_proxy.power_off(true).await
|
||||
}
|
||||
|
||||
async fn suspend() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
manager_proxy.suspend(true).await
|
||||
}
|
||||
|
||||
async fn lock() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
// Get the session this current process is running in
|
||||
let our_uid = getuid().as_raw() as u32;
|
||||
let user_path = manager_proxy.get_user(our_uid).await?;
|
||||
let user = UserProxy::builder(&connection)
|
||||
.path(user_path)?
|
||||
.build()
|
||||
.await?;
|
||||
// Lock all non-TTY sessions of this user
|
||||
let sessions = user.sessions().await?;
|
||||
for (_, session_path) in sessions {
|
||||
let session = SessionProxy::builder(&connection)
|
||||
.path(session_path)?
|
||||
.build()
|
||||
.await?;
|
||||
if session.type_().await? != SessionType::TTY {
|
||||
session.lock().await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn log_out() -> zbus::Result<()> {
|
||||
let session_type = std::env::var("XDG_CURRENT_DESKTOP").ok();
|
||||
let connection = Connection::session().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(())
|
||||
}
|
||||
139
cosmic-applet-power/src/session_manager.rs
Normal file
139
cosmic-applet-power/src/session_manager.rs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
// SPDX-License-Identifier: GPL-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", assume_defaults = true)]
|
||||
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>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue