diff --git a/applets/cosmic-applet-graphics/src/dbus.rs b/applets/cosmic-applet-graphics/src/dbus.rs index 90a898b5..f6c4b853 100644 --- a/applets/cosmic-applet-graphics/src/dbus.rs +++ b/applets/cosmic-applet-graphics/src/dbus.rs @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later //! # DBus interface proxy for: `com.system76.PowerDaemon` //! //! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data. diff --git a/applets/cosmic-applet-graphics/src/graphics.rs b/applets/cosmic-applet-graphics/src/graphics.rs new file mode 100644 index 00000000..762642fd --- /dev/null +++ b/applets/cosmic-applet-graphics/src/graphics.rs @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +use crate::dbus::PowerDaemonProxy; +use zbus::Result; + +pub enum Graphics { + Integrated, + Hybrid, + External, + Compute, +} + +pub async fn get_current_graphics(daemon: &PowerDaemonProxy<'_>) -> Result { + let graphics = daemon.get_graphics().await?; + match graphics.as_str() { + "integrated" => Ok(Graphics::Integrated), + "hybrid" => Ok(Graphics::Hybrid), + "external" => Ok(Graphics::External), + "compute" => Ok(Graphics::Compute), + _ => panic!("Unknown graphics profile: {}", graphics), + } +} + +pub async fn get_default_graphics(daemon: &PowerDaemonProxy<'_>) -> Result { + let graphics = daemon.get_default_graphics().await?; + match graphics.as_str() { + "integrated" => Ok(Graphics::Integrated), + "hybrid" => Ok(Graphics::Hybrid), + "external" => Ok(Graphics::External), + "compute" => Ok(Graphics::Compute), + _ => panic!("Unknown graphics profile: {}", graphics), + } +} + +pub async fn set_graphics(daemon: &PowerDaemonProxy<'_>, graphics: Graphics) -> Result<()> { + let graphics_str = match graphics { + Graphics::Integrated => "integrated", + Graphics::Hybrid => "hybrid", + Graphics::External => "external", + Graphics::Compute => "compute", + }; + daemon.set_graphics(graphics_str).await +} diff --git a/applets/cosmic-applet-graphics/src/main.rs b/applets/cosmic-applet-graphics/src/main.rs index 1f1cf47f..dc59d6d9 100644 --- a/applets/cosmic-applet-graphics/src/main.rs +++ b/applets/cosmic-applet-graphics/src/main.rs @@ -4,6 +4,7 @@ extern crate relm4_macros; pub mod dbus; +pub mod graphics; pub mod profile; use gtk4::{gio::ApplicationFlags, prelude::*, Orientation}; diff --git a/applets/cosmic-applet-graphics/src/profile.rs b/applets/cosmic-applet-graphics/src/profile.rs index 6f819640..6fef433d 100644 --- a/applets/cosmic-applet-graphics/src/profile.rs +++ b/applets/cosmic-applet-graphics/src/profile.rs @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later use crate::dbus::PowerDaemonProxy; use zbus::Result;