diff --git a/Cargo.lock b/Cargo.lock index fdeee0c1..e3813ad1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,6 +244,19 @@ dependencies = [ "zbus", ] +[[package]] +name = "cosmic-applet-power" +version = "0.1.0" +dependencies = [ + "futures-util", + "gtk4", + "logind-zbus", + "once_cell", + "relm4-macros", + "tokio", + "zbus", +] + [[package]] name = "cosmic-dbus-networkmanager" version = "0.1.0" @@ -939,6 +952,17 @@ 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", + "zvariant", +] + [[package]] name = "memchr" version = "2.4.1" diff --git a/Cargo.toml b/Cargo.toml index bb49bd6d..b6c309e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,4 @@ zvariant = "3" layer-shell = ["gdk4-wayland", "libcosmic/layer-shell"] [workspace] -members = ["applets/cosmic-applet-graphics", "applets/cosmic-applet-network"] +members = ["applets/cosmic-applet-graphics", "applets/cosmic-applet-network", "applets/cosmic-applet-power"] diff --git a/applets/cosmic-applet-power/Cargo.toml b/applets/cosmic-applet-power/Cargo.toml new file mode 100644 index 00000000..e28922aa --- /dev/null +++ b/applets/cosmic-applet-power/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "cosmic-applet-power" +version = "0.1.0" +edition = "2021" +license = "LGPL-3.0-or-later" + +[dependencies] +futures-util = "0.3.21" +gtk4 = "0.4.6" +logind-zbus = "3.0.1" +once_cell = "1.9.0" +relm4-macros = "0.4.1" +tokio = { version = "1.15.0", features = ["full"] } +zbus = "2.0.1" diff --git a/applets/cosmic-applet-power/src/main.rs b/applets/cosmic-applet-power/src/main.rs new file mode 100644 index 00000000..6c4a7776 --- /dev/null +++ b/applets/cosmic-applet-power/src/main.rs @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +#[macro_use] +extern crate relm4_macros; + +use gtk4::{gio::ApplicationFlags, prelude::*, Orientation, Separator}; +use once_cell::sync::Lazy; +use tokio::runtime::Runtime; + +static RT: Lazy = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime")); + +fn main() { + let application = gtk4::Application::new( + Some("com.system76.cosmic.applets.power"), + ApplicationFlags::default(), + ); + application.connect_activate(build_ui); + application.run(); +} + +fn build_ui(application: >k4::Application) { + let window = gtk4::ApplicationWindow::builder() + .application(application) + .title("COSMIC Power Applet") + .default_width(400) + .default_height(300) + .build(); + + view! { + main_box = gtk4::Box { + set_orientation: Orientation::Vertical, + set_spacing: 10, + set_margin_top: 20, + set_margin_bottom: 20, + set_margin_start: 24, + set_margin_end: 24 + } + } + window.set_child(Some(&main_box)); + + window.show(); +}