Power: Replace gtk applet with iced applet (#32)
* Power: Replace gtk applet with iced applet No functionality yet, but the layout is nearly done. Only small tweaks needed to font and svg backgrounds. * Power: Add suspend+restart+shutdown functionality * Power: Add lock + log out + settings * Fix build. * Fix window placement
This commit is contained in:
parent
fd17241bcf
commit
31bea66801
12 changed files with 3975 additions and 390 deletions
97
Cargo.lock
generated
97
Cargo.lock
generated
|
|
@ -201,12 +201,6 @@ version = "1.4.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
|
||||
|
||||
[[package]]
|
||||
name = "cache-padded"
|
||||
version = "1.2.0"
|
||||
|
|
@ -358,23 +352,6 @@ dependencies = [
|
|||
"zvariant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cosmic-applet-power"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"gtk4",
|
||||
"libadwaita",
|
||||
"libcosmic",
|
||||
"libcosmic-applet",
|
||||
"logind-zbus",
|
||||
"nix 0.24.2",
|
||||
"once_cell",
|
||||
"relm4-macros",
|
||||
"tokio",
|
||||
"zbus 2.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cosmic-applet-status-area"
|
||||
version = "0.1.0"
|
||||
|
|
@ -1294,17 +1271,6 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "logind-zbus"
|
||||
version = "3.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c03958f20018a20963daf0c16ada4f271ae2da3e0017fb40caa8b0e3dc5b0226"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"zbus 2.3.2",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
|
|
@ -1329,18 +1295,6 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.23.1"
|
||||
|
|
@ -1399,16 +1353,6 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc"
|
||||
version = "0.2.7"
|
||||
|
|
@ -1983,15 +1927,6 @@ dependencies = [
|
|||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.10"
|
||||
|
|
@ -2134,38 +2069,6 @@ version = "0.3.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29738eedb4388d9ea620eeab9384884fc3f06f586a2eddb56bedc5885126c7c1"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bytes",
|
||||
"libc",
|
||||
"memchr",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.9"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"applets/cosmic-applet-notifications",
|
||||
"applets/cosmic-applet-power",
|
||||
"applets/cosmic-applet-status-area",
|
||||
"applets/cosmic-applet-time",
|
||||
"applets/cosmic-app-list",
|
||||
|
|
@ -14,6 +13,7 @@ exclude = [
|
|||
"applets/cosmic-applet-workspaces",
|
||||
"applets/cosmic-applet-battery",
|
||||
"applets/cosmic-applet-audio",
|
||||
"applets/cosmic-applet-power",
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
|
|
|
|||
3644
applets/cosmic-applet-power/Cargo.lock
generated
Normal file
3644
applets/cosmic-applet-power/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -5,14 +5,39 @@ edition = "2021"
|
|||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
futures-util = "0.3.21"
|
||||
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" }
|
||||
adw = { git = "https://gitlab.gnome.org/World/Rust/libadwaita-rs", package = "libadwaita"}
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false }
|
||||
libcosmic-applet = { path = "../../libcosmic-applet" }
|
||||
logind-zbus = "3.0.1"
|
||||
icon-loader = { version = "0.3.6", features = ["gtk"] }
|
||||
libpulse-binding = "2.26.0"
|
||||
libpulse-glib-binding = "2.25.0"
|
||||
tokio = { version = "1.20.1", features=["full"] }
|
||||
libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "master", default-features = false, features = ["wayland", "applet"] }
|
||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" }
|
||||
nix = "0.24.1"
|
||||
once_cell = "1.9.0"
|
||||
relm4-macros = { git = "https://github.com/Relm4/Relm4.git", branch = "next" }
|
||||
tokio = { version = "1.15.0", features = ["full"] }
|
||||
zbus = "2.0.1"
|
||||
|
||||
[workspace]
|
||||
resolved = "2"
|
||||
|
||||
[dependencies.iced]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
# path = "../iced"
|
||||
default-features = false
|
||||
features = ["image", "svg", "tokio", "wayland"]
|
||||
|
||||
[dependencies.iced_native]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
|
||||
[dependencies.iced_futures]
|
||||
git = "https://github.com/pop-os/iced.git"
|
||||
branch = "sctk-cosmic"
|
||||
|
||||
# Until the 3.6.3 release, need the implementation of clone on zbus::Error
|
||||
[dependencies.zbus]
|
||||
git = "https://gitlab.freedesktop.org/dbus/zbus"
|
||||
branch = "main"
|
||||
|
||||
# Until zbus 3.6.3 is released
|
||||
[dependencies.logind-zbus]
|
||||
git = "https://github.com/pop-os/logind-zbus"
|
||||
branch = "main"
|
||||
|
|
|
|||
|
|
@ -1,62 +1,295 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
use std::process;
|
||||
|
||||
#[macro_use]
|
||||
extern crate relm4_macros;
|
||||
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;
|
||||
pub mod ui;
|
||||
|
||||
use gtk4::{gio::ApplicationFlags, prelude::*, Align, Button, Label, Orientation, Separator};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::process::Command;
|
||||
use tokio::runtime::Runtime;
|
||||
use crate::cosmic_session::CosmicSessionProxy;
|
||||
use crate::session_manager::SessionManagerProxy;
|
||||
|
||||
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
|
||||
|
||||
fn main() {
|
||||
let _monitors = libcosmic::init();
|
||||
|
||||
let application = gtk4::Application::new(None, ApplicationFlags::default());
|
||||
application.connect_activate(build_ui);
|
||||
application.run();
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
Audio::run(helper.window_settings())
|
||||
}
|
||||
|
||||
fn build_ui(application: >k4::Application) {
|
||||
view! {
|
||||
window = libcosmic_applet::AppletWindow {
|
||||
set_title: Some("COSMIC Power Applet"),
|
||||
set_application: Some(application),
|
||||
// TODO adjust battery icon based on charge
|
||||
#[wrap(Some)]
|
||||
set_child = &libcosmic_applet::AppletButton {
|
||||
set_button_icon_name: "system-shutdown-symbolic",
|
||||
#[wrap(Some)]
|
||||
set_popover_child: main_box = >k4::Box {
|
||||
set_orientation: Orientation::Vertical,
|
||||
set_spacing: 10,
|
||||
set_margin_top: 20,
|
||||
set_margin_bottom: 20,
|
||||
set_margin_start: 24,
|
||||
set_margin_end: 24,
|
||||
append: settings_button = &Button {
|
||||
#[wrap(Some)]
|
||||
set_child = &Label {
|
||||
set_label: "Settings...",
|
||||
set_halign: Align::Start,
|
||||
set_hexpand: true
|
||||
},
|
||||
connect_clicked => move |_| {
|
||||
let _ = Command::new("cosmic-settings").spawn();
|
||||
}
|
||||
},
|
||||
append = &Separator {},
|
||||
append: &ui::session::build(),
|
||||
append: second_separator = &Separator {},
|
||||
append: &ui::system::build(),
|
||||
#[derive(Default)]
|
||||
struct Audio {
|
||||
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 Audio {
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Executor = executor::Default;
|
||||
type Flags = ();
|
||||
|
||||
fn new(_flags: ()) -> (Audio, Command<Message>) {
|
||||
(
|
||||
Audio {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
window.show();
|
||||
}
|
||||
|
||||
// ### 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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(interface = "org.gnome.SessionManager")]
|
||||
#[dbus_proxy(interface = "org.gnome.SessionManager", assume_defaults = true)]
|
||||
trait SessionManager {
|
||||
/// CanRebootToFirmwareSetup method
|
||||
fn can_reboot_to_firmware_setup(&self) -> zbus::Result<bool>;
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
image.panel_icon {
|
||||
padding-left: 0px;
|
||||
padding-right: 0px;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
button.panel_icon {
|
||||
border-radius: 12px;
|
||||
transition: 100ms;
|
||||
padding: 4px;
|
||||
border-color: transparent;
|
||||
background: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
||||
button.panel_icon:hover {
|
||||
border-radius: 12px;
|
||||
transition: 100ms;
|
||||
padding: 4px;
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
outline-color: rgba(255, 255, 255, 0.1);
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
window.root_window {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
box.icon_box {
|
||||
padding: 0px;
|
||||
border-color: transparent;
|
||||
background: transparent;
|
||||
outline-color: transparent;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
pub mod session;
|
||||
pub mod system;
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use crate::{cosmic_session::CosmicSessionProxy, session_manager::SessionManagerProxy, RT};
|
||||
use gtk4::{prelude::*, Align, Button, Image, Label, Orientation};
|
||||
use logind_zbus::{
|
||||
manager::ManagerProxy,
|
||||
session::{SessionProxy, SessionType},
|
||||
user::UserProxy,
|
||||
};
|
||||
use nix::unistd::getuid;
|
||||
use zbus::Connection;
|
||||
|
||||
async fn lock_screen() -> 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(())
|
||||
}
|
||||
|
||||
pub fn build() -> gtk4::Box {
|
||||
view! {
|
||||
inner_box = gtk4::Box {
|
||||
set_orientation: Orientation::Vertical,
|
||||
set_spacing: 5,
|
||||
append: lock_screen_button = &Button {
|
||||
#[wrap(Some)]
|
||||
set_child: lock_screen_box = >k4::Box {
|
||||
set_orientation: Orientation::Horizontal,
|
||||
set_spacing: 10,
|
||||
append: lock_screen_icon = &Image {
|
||||
set_icon_name: Some("system-lock-screen-symbolic"),
|
||||
},
|
||||
append: lock_screen_label = &Label {
|
||||
set_label: "Lock Screen",
|
||||
set_halign: Align::Start,
|
||||
set_hexpand: true
|
||||
},
|
||||
append: lock_screen_hotkey_label = &Label {
|
||||
set_label: "Super + Escape",
|
||||
set_halign: Align::End
|
||||
}
|
||||
}
|
||||
},
|
||||
append: log_out_button = &Button {
|
||||
#[wrap(Some)]
|
||||
set_child: log_out_box = >k4::Box {
|
||||
set_orientation: Orientation::Horizontal,
|
||||
set_spacing: 10,
|
||||
append: log_out_icon = &Image {
|
||||
set_icon_name: Some("system-log-out-symbolic"),
|
||||
},
|
||||
append: log_out_label = &Label {
|
||||
set_label: "Log Out",
|
||||
set_halign: Align::Start,
|
||||
set_hexpand: true
|
||||
},
|
||||
append: log_out_hotkey_label = &Label {
|
||||
set_label: "Ctrl + Alt + Delete",
|
||||
set_halign: Align::End
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lock_screen_button.connect_clicked(|_| {
|
||||
RT.spawn(async move {
|
||||
lock_screen().await.expect("failed to lock screen");
|
||||
});
|
||||
});
|
||||
log_out_button.connect_clicked(|_| {
|
||||
RT.spawn(async move {
|
||||
log_out().await.expect("failed to log out");
|
||||
});
|
||||
});
|
||||
inner_box
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use crate::RT;
|
||||
use gtk4::{prelude::*, Button, IconSize, Image, Label, Orientation};
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use zbus::Connection;
|
||||
|
||||
async fn restart() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||
manager_proxy.reboot(true).await
|
||||
}
|
||||
|
||||
async fn shut_down() -> 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
|
||||
}
|
||||
|
||||
pub fn build() -> gtk4::Box {
|
||||
let suspend_button = create_button("Suspend", "system-suspend-symbolic");
|
||||
let restart_button = create_button("Restart", "system-reboot-symbolic");
|
||||
let shut_down_button = create_button("Shut Down", "system-shutdown-symbolic");
|
||||
suspend_button.connect_clicked(|_| {
|
||||
RT.spawn(async move {
|
||||
suspend().await.expect("failed to suspend system");
|
||||
});
|
||||
});
|
||||
restart_button.connect_clicked(|_| {
|
||||
RT.spawn(async move {
|
||||
restart().await.expect("failed to reboot system");
|
||||
});
|
||||
});
|
||||
shut_down_button.connect_clicked(|_| {
|
||||
RT.spawn(async move {
|
||||
shut_down().await.expect("failed to shut down system");
|
||||
});
|
||||
});
|
||||
view! {
|
||||
inner_box = gtk4::Box {
|
||||
set_orientation: Orientation::Horizontal,
|
||||
set_spacing: 24,
|
||||
append: &suspend_button,
|
||||
append: &restart_button,
|
||||
append: &shut_down_button,
|
||||
}
|
||||
}
|
||||
inner_box
|
||||
}
|
||||
|
||||
pub fn create_button(name: &str, icon_name: &str) -> Button {
|
||||
view! {
|
||||
button = Button {
|
||||
#[wrap(Some)]
|
||||
set_child: inner_box = >k4::Box {
|
||||
set_orientation: Orientation::Vertical,
|
||||
set_spacing: 8,
|
||||
set_margin_start: 8,
|
||||
set_margin_end: 8,
|
||||
set_margin_top: 8,
|
||||
set_margin_bottom: 8,
|
||||
append: icon = &Image {
|
||||
set_icon_name: Some(icon_name),
|
||||
set_icon_size: IconSize::Large
|
||||
},
|
||||
append: label = &Label {
|
||||
set_label: name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
button
|
||||
}
|
||||
7
debian/rules
vendored
7
debian/rules
vendored
|
|
@ -51,6 +51,13 @@ override_dh_auto_clean:
|
|||
tar pcf vendor.tar vendor; \
|
||||
rm -rf vendor; \
|
||||
cd ../..; \
|
||||
cd applets/cosmic-applet-power/; \
|
||||
mkdir -p .cargo; \
|
||||
cargo vendor --sync Cargo.toml | head -n -1 > .cargo/config; \
|
||||
echo 'directory = "vendor"' >> .cargo/config; \
|
||||
tar pcf vendor.tar vendor; \
|
||||
rm -rf vendor; \
|
||||
cd ../..; \
|
||||
cd applets/cosmic-applet-network/; \
|
||||
mkdir -p .cargo; \
|
||||
cargo vendor --sync Cargo.toml | head -n -1 > .cargo/config; \
|
||||
|
|
|
|||
6
justfile
6
justfile
|
|
@ -40,6 +40,9 @@ build: _extract_vendor
|
|||
pushd applets/cosmic-applet-battery/
|
||||
cargo build {{cargo_args}}
|
||||
popd
|
||||
pushd applets/cosmic-applet-power/
|
||||
cargo build {{cargo_args}}
|
||||
popd
|
||||
pushd applets/cosmic-applet-workspaces/
|
||||
cargo build {{cargo_args}}
|
||||
popd
|
||||
|
|
@ -72,7 +75,7 @@ install:
|
|||
# power
|
||||
install -Dm0644 applets/cosmic-applet-power/data/icons/{{power_id}}.svg {{iconsdir}}/{{power_id}}.svg
|
||||
install -Dm0644 applets/cosmic-applet-power/data/{{power_id}}.desktop {{sharedir}}/applications/{{power_id}}.desktop
|
||||
install -Dm0755 target/release/cosmic-applet-power {{bindir}}/cosmic-applet-power
|
||||
install -Dm0755 applets/cosmic-applet-power/target/release/cosmic-applet-power {{bindir}}/cosmic-applet-power
|
||||
|
||||
# status area
|
||||
install -Dm0644 applets/cosmic-applet-status-area/data/icons/{{status_area_id}}.svg {{iconsdir}}/{{status_area_id}}.svg
|
||||
|
|
@ -119,5 +122,6 @@ _extract_vendor:
|
|||
rm -rf applets/cosmic-applet-workspaces/vendor; tar xf applets/cosmic-applet-workspaces/vendor.tar --directory applets/cosmic-applet-workspaces
|
||||
rm -rf applets/cosmic-applet-battery/vendor; tar xf applets/cosmic-applet-battery/vendor.tar --directory applets/cosmic-applet-battery
|
||||
rm -rf applets/cosmic-applet-audio/vendor; tar xf applets/cosmic-applet-audio/vendor.tar --directory applets/cosmic-applet-audio
|
||||
rm -rf applets/cosmic-applet-power/vendor; tar xf applets/cosmic-applet-power/vendor.tar --directory applets/cosmic-applet-power
|
||||
rm -rf applets/cosmic-applet-network/vendor; tar xf applets/cosmic-applet-network/vendor.tar --directory applets/cosmic-applet-network
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue