diff --git a/Cargo.lock b/Cargo.lock index 2612fff1..fdeee0c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -218,6 +218,17 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "cosmic-applet-graphics" +version = "0.1.0" +dependencies = [ + "gtk4", + "once_cell", + "relm4-macros", + "tokio", + "zbus", +] + [[package]] name = "cosmic-applet-network" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index bfb21636..bb49bd6d 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-network"] +members = ["applets/cosmic-applet-graphics", "applets/cosmic-applet-network"] diff --git a/applets/cosmic-applet-graphics/Cargo.toml b/applets/cosmic-applet-graphics/Cargo.toml new file mode 100644 index 00000000..472298aa --- /dev/null +++ b/applets/cosmic-applet-graphics/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "cosmic-applet-graphics" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +gtk4 = "0.4.6" +once_cell = "1.9.0" +relm4-macros = "0.4.2" +tokio = { version = "1.16.1", features = ["full"] } +zbus = "2.1.1" diff --git a/applets/cosmic-applet-graphics/src/dbus.rs b/applets/cosmic-applet-graphics/src/dbus.rs new file mode 100644 index 00000000..90a898b5 --- /dev/null +++ b/applets/cosmic-applet-graphics/src/dbus.rs @@ -0,0 +1,75 @@ +//! # DBus interface proxy for: `com.system76.PowerDaemon` +//! +//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data. +//! Source: `Interface '/com/system76/PowerDaemon' from service 'com.system76.PowerDaemon' on system 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::IntrospectableProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use zbus::dbus_proxy; + +#[dbus_proxy(interface = "com.system76.PowerDaemon")] +trait PowerDaemon { + /// Balanced method + fn balanced(&self) -> zbus::Result<()>; + + /// Battery method + fn battery(&self) -> zbus::Result<()>; + + /// GetChargeProfiles method + fn get_charge_profiles( + &self, + ) -> zbus::Result>>; + + /// GetChargeThresholds method + fn get_charge_thresholds(&self) -> zbus::Result<(u8, u8)>; + + /// GetDefaultGraphics method + fn get_default_graphics(&self) -> zbus::Result; + + /// GetExternalDisplaysRequireDGPU method + fn get_external_displays_require_dgpu(&self) -> zbus::Result; + + /// GetGraphics method + fn get_graphics(&self) -> zbus::Result; + + /// GetGraphicsPower method + fn get_graphics_power(&self) -> zbus::Result; + + /// GetProfile method + fn get_profile(&self) -> zbus::Result; + + /// GetSwitchable method + fn get_switchable(&self) -> zbus::Result; + + /// Performance method + fn performance(&self) -> zbus::Result<()>; + + /// SetChargeThresholds method + fn set_charge_thresholds(&self, thresholds: &(u8, u8)) -> zbus::Result<()>; + + /// SetGraphics method + fn set_graphics(&self, vendor: &str) -> zbus::Result<()>; + + /// SetGraphicsPower method + fn set_graphics_power(&self, power: bool) -> zbus::Result<()>; + + /// HotPlugDetect signal + #[dbus_proxy(signal)] + fn hot_plug_detect(&self, port: u64) -> zbus::Result<()>; + + /// PowerProfileSwitch signal + #[dbus_proxy(signal)] + fn power_profile_switch(&self, profile: &str) -> zbus::Result<()>; +} diff --git a/applets/cosmic-applet-graphics/src/main.rs b/applets/cosmic-applet-graphics/src/main.rs new file mode 100644 index 00000000..f816defa --- /dev/null +++ b/applets/cosmic-applet-graphics/src/main.rs @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +#[macro_use] +extern crate relm4_macros; + +pub mod dbus; +use gtk4::{gio::ApplicationFlags, prelude::*, Orientation}; +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.graphics"), + ApplicationFlags::default(), + ); + application.connect_activate(build_ui); + application.run(); +} + +fn build_ui(application: >k4::Application) { + let window = gtk4::ApplicationWindow::builder() + .application(application) + .title("COSMIC Graphics 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.show(); +}