cosmic-applets/cosmic-applet-graphics/src/graphics.rs

33 lines
982 B
Rust
Raw Normal View History

2022-05-26 11:59:09 -04:00
// SPDX-License-Identifier: GPL-3.0-or-later
2022-02-15 10:59:57 -05:00
use crate::dbus::PowerDaemonProxy;
use zbus::Result;
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
2022-02-15 10:59:57 -05:00
pub enum Graphics {
Integrated,
Hybrid,
2022-02-15 17:41:01 -05:00
Nvidia,
2022-02-15 10:59:57 -05:00
Compute,
}
pub async fn get_current_graphics(daemon: PowerDaemonProxy<'_>) -> Result<Graphics> {
2022-02-15 10:59:57 -05:00
let graphics = daemon.get_graphics().await?;
match graphics.as_str() {
"integrated" => Ok(Graphics::Integrated),
"hybrid" => Ok(Graphics::Hybrid),
2022-02-15 17:41:01 -05:00
"nvidia" => Ok(Graphics::Nvidia),
2022-02-15 10:59:57 -05:00
"compute" => Ok(Graphics::Compute),
_ => panic!("Unknown graphics profile: {}", graphics),
}
}
pub async fn set_graphics(daemon: PowerDaemonProxy<'_>, graphics: Graphics) -> Result<()> {
2022-02-15 10:59:57 -05:00
let graphics_str = match graphics {
Graphics::Integrated => "integrated",
Graphics::Hybrid => "hybrid",
2022-02-15 17:41:01 -05:00
Graphics::Nvidia => "nvidia",
2022-02-15 10:59:57 -05:00
Graphics::Compute => "compute",
};
daemon.set_graphics(graphics_str).await
}