Install battery applet, and make it work in the panel
This commit is contained in:
parent
ad1707a541
commit
14101dc7db
13 changed files with 89 additions and 5 deletions
88
applets/cosmic-applet-battery/src/backlight.rs
Normal file
88
applets/cosmic-applet-battery/src/backlight.rs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// TODO: use udev to monitor for brightness changes?
|
||||
// How should key bindings be handled? Need something like gnome-settings-daemon?
|
||||
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::{self, Read},
|
||||
os::unix::ffi::OsStrExt,
|
||||
path::Path,
|
||||
str::{self, FromStr},
|
||||
};
|
||||
|
||||
const BACKLIGHT_SYSDIR: &str = "/sys/class/backlight";
|
||||
|
||||
#[zbus::dbus_proxy(
|
||||
default_service = "org.freedesktop.login1",
|
||||
interface = "org.freedesktop.login1.Session",
|
||||
default_path = "/org/freedesktop/login1/session/auto"
|
||||
)]
|
||||
trait LogindSession {
|
||||
fn set_brightness(&self, subsystem: &str, name: &str, brightness: u32) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Backlight(String);
|
||||
|
||||
impl Backlight {
|
||||
pub fn brightness(&self) -> Option<u32> {
|
||||
self.prop("brightness")
|
||||
}
|
||||
|
||||
// XXX cache value. Async?
|
||||
pub fn max_brightness(&self) -> Option<u32> {
|
||||
self.prop("max_brightness")
|
||||
}
|
||||
|
||||
pub async fn set_brightness(
|
||||
&self,
|
||||
session: &LogindSessionProxy<'_>,
|
||||
value: u32,
|
||||
) -> zbus::Result<()> {
|
||||
session.set_brightness("backlight", &self.0, value).await
|
||||
}
|
||||
|
||||
fn prop<T: FromStr>(&self, name: &str) -> Option<T> {
|
||||
let path = Path::new(BACKLIGHT_SYSDIR).join(&self.0).join(name);
|
||||
let mut file = File::open(path).ok()?;
|
||||
let mut s = String::new();
|
||||
file.read_to_string(&mut s).ok()?;
|
||||
s.trim().parse().ok()
|
||||
}
|
||||
}
|
||||
|
||||
// Choose backlight with most "precision". This is what `light` does.
|
||||
pub fn backlight() -> io::Result<Option<Backlight>> {
|
||||
let mut best_backlight = None;
|
||||
let mut best_max_brightness = 0;
|
||||
for i in fs::read_dir(BACKLIGHT_SYSDIR)? {
|
||||
if let Ok(filename) = str::from_utf8(i?.file_name().as_bytes()) {
|
||||
let backlight = Backlight(filename.to_string());
|
||||
if let Some(max_brightness) = backlight.max_brightness() {
|
||||
if max_brightness > best_max_brightness {
|
||||
best_backlight = Some(backlight);
|
||||
best_max_brightness = max_brightness;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(best_backlight)
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: Cache device, max_brightness, etc.
|
||||
async fn set_display_brightness(brightness: f64) -> io::Result<()> {
|
||||
if let Some(backlight) = backlight()? {
|
||||
if let Some(max_brightness) = backlight.max_brightness() {
|
||||
let value = brightness.clamp(0., 1.) * (max_brightness as f64);
|
||||
let value = value.round() as u32;
|
||||
let connection = zbus::Connection::system().await?;
|
||||
if let Ok(session) = LogindSessionProxy::builder(&connection).build().await {
|
||||
backlight.set_brightness(&session, value).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: keyboard backlight
|
||||
432
applets/cosmic-applet-battery/src/main.rs
Normal file
432
applets/cosmic-applet-battery/src/main.rs
Normal file
|
|
@ -0,0 +1,432 @@
|
|||
// TODO: don't allow brightness 0?
|
||||
// TODO: handle dbus service start/stop?
|
||||
|
||||
use futures::prelude::*;
|
||||
use gtk4::{glib, prelude::*};
|
||||
use relm4::{ComponentParts, ComponentSender, RelmApp, SimpleComponent, WidgetPlus};
|
||||
use std::{process::Command, time::Duration};
|
||||
|
||||
mod backlight;
|
||||
use backlight::{backlight, Backlight, LogindSessionProxy};
|
||||
mod power_daemon;
|
||||
use power_daemon::PowerDaemonProxy;
|
||||
mod upower;
|
||||
use upower::UPowerProxy;
|
||||
mod upower_device;
|
||||
use upower_device::DeviceProxy;
|
||||
mod upower_kbdbacklight;
|
||||
use upower_kbdbacklight::KbdBacklightProxy;
|
||||
|
||||
async fn display_device() -> zbus::Result<DeviceProxy<'static>> {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
let upower = UPowerProxy::new(&connection).await?;
|
||||
let device_path = upower.get_display_device().await?;
|
||||
DeviceProxy::builder(&connection)
|
||||
.path(device_path)?
|
||||
.cache_properties(zbus::CacheProperties::Yes)
|
||||
.build()
|
||||
.await
|
||||
}
|
||||
|
||||
// XXX improve
|
||||
// TODO: time to empty varies? needs averaging?
|
||||
fn format_duration(duration: Duration) -> String {
|
||||
let secs = duration.as_secs();
|
||||
if secs > 60 {
|
||||
let min = secs / 60;
|
||||
if min > 60 {
|
||||
format!("{}:{:02}", min / 60, min % 60)
|
||||
} else {
|
||||
format!("{}m", min)
|
||||
}
|
||||
} else {
|
||||
format!("{}s", secs)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum Graphics {
|
||||
Compute,
|
||||
Hybrid,
|
||||
Integrated,
|
||||
Nvidia,
|
||||
}
|
||||
|
||||
impl Graphics {
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
match s {
|
||||
"compute" => Some(Self::Compute),
|
||||
"hybrid" => Some(Self::Hybrid),
|
||||
"integrated" => Some(Self::Integrated),
|
||||
"nvidia" => Some(Self::Nvidia),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Compute => "compute",
|
||||
Self::Hybrid => "hybrid",
|
||||
Self::Integrated => "integrated",
|
||||
Self::Nvidia => "nvidia",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct AppModel {
|
||||
icon_name: String,
|
||||
battery_percent: f64,
|
||||
time_remaining: Duration,
|
||||
display_brightness: f64,
|
||||
keyboard_brightness: f64,
|
||||
device: Option<DeviceProxy<'static>>,
|
||||
session: Option<LogindSessionProxy<'static>>,
|
||||
backlight: Option<Backlight>,
|
||||
kbd_backlight: Option<KbdBacklightProxy<'static>>,
|
||||
power_daemon: Option<PowerDaemonProxy<'static>>,
|
||||
}
|
||||
|
||||
enum AppMsg {
|
||||
SetDisplayBrightness(f64),
|
||||
SetKeyboardBrightness(f64),
|
||||
SetDevice(DeviceProxy<'static>),
|
||||
SetSession(LogindSessionProxy<'static>),
|
||||
SetKbdBacklight(KbdBacklightProxy<'static>),
|
||||
SetPowerDaemon(PowerDaemonProxy<'static>),
|
||||
UpdateProperties,
|
||||
UpdateKbdBrightness(f64),
|
||||
}
|
||||
|
||||
#[relm4::component]
|
||||
impl SimpleComponent for AppModel {
|
||||
type Widgets = AppWidgets;
|
||||
|
||||
type InitParams = ();
|
||||
|
||||
type Input = AppMsg;
|
||||
type Output = ();
|
||||
|
||||
view! {
|
||||
gtk4::Window {
|
||||
set_decorated: false,
|
||||
set_resizable: false,
|
||||
set_width_request: 1,
|
||||
set_height_request: 1,
|
||||
gtk4::MenuButton {
|
||||
set_has_frame: false,
|
||||
#[watch]
|
||||
set_icon_name: &model.icon_name,
|
||||
#[wrap(Some)]
|
||||
set_popover = >k4::Popover {
|
||||
#[wrap(Some)]
|
||||
set_child = >k4::Box {
|
||||
set_orientation: gtk4::Orientation::Vertical,
|
||||
|
||||
// Battery
|
||||
gtk4::Box {
|
||||
set_orientation: gtk4::Orientation::Horizontal,
|
||||
gtk4::Image {
|
||||
#[watch]
|
||||
set_icon_name: Some(&model.icon_name),
|
||||
},
|
||||
gtk4::Box {
|
||||
set_orientation: gtk4::Orientation::Vertical,
|
||||
gtk4::Label {
|
||||
set_halign: gtk4::Align::Start,
|
||||
set_label: "Battery",
|
||||
},
|
||||
gtk4::Label {
|
||||
set_halign: gtk4::Align::Start,
|
||||
// XXX time to full, fully changed, etc.
|
||||
#[watch]
|
||||
set_label: &format!("{} until empty ({:.0}%)", format_duration(model.time_remaining), model.battery_percent),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
gtk4::Separator {
|
||||
},
|
||||
|
||||
// Profiles
|
||||
|
||||
gtk4::Separator {
|
||||
},
|
||||
|
||||
// Limit charging
|
||||
gtk4::Box {
|
||||
set_orientation: gtk4::Orientation::Horizontal,
|
||||
gtk4::Box {
|
||||
set_orientation: gtk4::Orientation::Vertical,
|
||||
gtk4::Label {
|
||||
set_halign: gtk4::Align::Start,
|
||||
set_label: "Limit Battery Charging",
|
||||
},
|
||||
gtk4::Label {
|
||||
set_halign: gtk4::Align::Start,
|
||||
set_label: "Increase the lifespan of your battery by setting a maximum charge value of 80%."
|
||||
},
|
||||
},
|
||||
gtk4::Switch {
|
||||
set_valign: gtk4::Align::Center,
|
||||
},
|
||||
},
|
||||
|
||||
gtk4::Separator {
|
||||
},
|
||||
|
||||
// Brightness
|
||||
gtk4::Box {
|
||||
#[watch]
|
||||
set_visible: model.backlight.is_some(),
|
||||
set_orientation: gtk4::Orientation::Horizontal,
|
||||
gtk4::Image {
|
||||
set_icon_name: Some("display-brightness-symbolic"),
|
||||
},
|
||||
gtk4::Scale {
|
||||
set_hexpand: true,
|
||||
set_adjustment: >k4::Adjustment::new(0., 0., 1., 1., 1., 0.),
|
||||
#[watch]
|
||||
set_value: model.display_brightness,
|
||||
connect_change_value[sender] => move |_, _, value| {
|
||||
sender.input(AppMsg::SetDisplayBrightness(value));
|
||||
gtk4::Inhibit(false)
|
||||
},
|
||||
},
|
||||
gtk4::Label {
|
||||
#[watch]
|
||||
set_label: &format!("{:.0}%", model.display_brightness * 100.),
|
||||
},
|
||||
},
|
||||
gtk4::Box {
|
||||
#[watch]
|
||||
set_visible: model.kbd_backlight.is_some(),
|
||||
set_orientation: gtk4::Orientation::Horizontal,
|
||||
gtk4::Image {
|
||||
set_icon_name: Some("keyboard-brightness-symbolic"),
|
||||
},
|
||||
gtk4::Scale {
|
||||
set_hexpand: true,
|
||||
set_adjustment: >k4::Adjustment::new(0., 0., 1., 1., 1., 0.),
|
||||
#[watch]
|
||||
set_value: model.keyboard_brightness,
|
||||
connect_change_value[sender] => move |_, _, value| {
|
||||
sender.input(AppMsg::SetKeyboardBrightness(value));
|
||||
gtk4::Inhibit(false)
|
||||
},
|
||||
},
|
||||
gtk4::Label {
|
||||
#[watch]
|
||||
set_label: &format!("{:.0}%", model.keyboard_brightness * 100.),
|
||||
},
|
||||
},
|
||||
|
||||
gtk4::Separator {
|
||||
},
|
||||
|
||||
gtk4::Button {
|
||||
set_label: "Power Settings...",
|
||||
connect_clicked => move |_| {
|
||||
// XXX open subpanel
|
||||
let _ = Command::new("cosmic-settings").spawn();
|
||||
// TODO hide
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init(
|
||||
_params: Self::InitParams,
|
||||
root: &Self::Root,
|
||||
sender: &ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let mut model = AppModel {
|
||||
icon_name: "battery-symbolic".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let widgets = view_output!();
|
||||
|
||||
match backlight() {
|
||||
Ok(Some(backlight)) => {
|
||||
if let (Some(brightness), Some(max_brightness)) =
|
||||
(backlight.brightness(), backlight.max_brightness())
|
||||
{
|
||||
model.display_brightness = brightness as f64 / max_brightness as f64;
|
||||
}
|
||||
model.backlight = Some(backlight);
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(err) => eprintln!("Error finding backlight: {}", err),
|
||||
};
|
||||
|
||||
glib::MainContext::default().spawn(glib::clone!(@strong sender => async move {
|
||||
match display_device().await {
|
||||
Ok(device) => sender.input(AppMsg::SetDevice(device)),
|
||||
Err(err) => eprintln!("Failed to open UPower display device: {}", err),
|
||||
}
|
||||
}));
|
||||
|
||||
glib::MainContext::default().spawn(glib::clone!(@strong sender => async move {
|
||||
// XXX avoid multiple connections?
|
||||
let proxy = async {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
LogindSessionProxy::builder(&connection).build().await
|
||||
}.await;
|
||||
match proxy {
|
||||
Ok(session) => sender.input(AppMsg::SetSession(session)),
|
||||
Err(err) => eprintln!("Failed to open logind session: {}", err),
|
||||
}
|
||||
}));
|
||||
|
||||
glib::MainContext::default().spawn(glib::clone!(@strong sender => async move {
|
||||
let proxy = async {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
KbdBacklightProxy::builder(&connection).build().await
|
||||
}.await;
|
||||
match proxy {
|
||||
Ok(kbd_backlight) => sender.input(AppMsg::SetKbdBacklight(kbd_backlight)),
|
||||
Err(err) => eprintln!("Failed to open kbd_backlight: {}", err),
|
||||
}
|
||||
}));
|
||||
|
||||
glib::MainContext::default().spawn(glib::clone!(@strong sender => async move {
|
||||
let proxy = async {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
PowerDaemonProxy::builder(&connection).build().await
|
||||
}.await;
|
||||
match proxy {
|
||||
Ok(power_daemon) => sender.input(AppMsg::SetPowerDaemon(power_daemon)),
|
||||
Err(err) => eprintln!("Failed to open power daemon: {}", err),
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
fn update(&mut self, msg: Self::Input, sender: &ComponentSender<Self>) {
|
||||
match msg {
|
||||
AppMsg::SetDisplayBrightness(value) => {
|
||||
self.display_brightness = value;
|
||||
// XXX clone
|
||||
if let Some(backlight) = self.backlight.clone() {
|
||||
if let Some(session) = self.session.clone() {
|
||||
// XXX cache max brightness
|
||||
if let Some(max_brightness) = backlight.max_brightness() {
|
||||
let value = value.clamp(0., 1.) * (max_brightness as f64);
|
||||
let value = value.round() as u32;
|
||||
// XXX limit queueing?
|
||||
glib::MainContext::default().spawn(async move {
|
||||
if let Err(err) = backlight.set_brightness(&session, value).await {
|
||||
eprintln!("Failed to set backlight: {}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AppMsg::SetKeyboardBrightness(value) => {
|
||||
self.keyboard_brightness = value;
|
||||
|
||||
if let Some(kbd_backlight) = self.kbd_backlight.clone() {
|
||||
glib::MainContext::default().spawn(async move {
|
||||
let res = async {
|
||||
// XXX cache
|
||||
let max_brightness = kbd_backlight.get_max_brightness().await?;
|
||||
let value = value.clamp(0., 1.) * (max_brightness as f64);
|
||||
let value = value.round() as i32;
|
||||
kbd_backlight.set_brightness(value).await
|
||||
}
|
||||
.await;
|
||||
if let Err(err) = res {
|
||||
eprintln!("Failed to set keyboard backlight: {}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
AppMsg::SetDevice(device) => {
|
||||
self.device = Some(device.clone());
|
||||
|
||||
let sender = sender.clone();
|
||||
glib::MainContext::default().spawn(async move {
|
||||
let mut stream = futures::stream_select!(
|
||||
device.receive_icon_name_changed().await.map(|_| ()),
|
||||
device.receive_percentage_changed().await.map(|_| ()),
|
||||
device.receive_time_to_empty_changed().await.map(|_| ()),
|
||||
);
|
||||
|
||||
sender.input(AppMsg::UpdateProperties);
|
||||
while let Some(()) = stream.next().await {
|
||||
sender.input(AppMsg::UpdateProperties);
|
||||
}
|
||||
});
|
||||
}
|
||||
AppMsg::SetSession(session) => {
|
||||
self.session = Some(session);
|
||||
}
|
||||
AppMsg::SetKbdBacklight(kbd_backlight) => {
|
||||
self.kbd_backlight = Some(kbd_backlight.clone());
|
||||
|
||||
glib::MainContext::default().spawn(glib::clone!(@strong sender => async move {
|
||||
let res = async {
|
||||
let stream = kbd_backlight.receive_brightness_changed().await?;
|
||||
let brightness = kbd_backlight.get_brightness().await?;
|
||||
let max_brightness = kbd_backlight.get_max_brightness().await?;
|
||||
zbus::Result::Ok((brightness, max_brightness, stream))
|
||||
}.await;
|
||||
match res {
|
||||
Ok((brightness, max_brightness, mut stream)) => {
|
||||
let value = (brightness as f64) / (max_brightness as f64);
|
||||
sender.input(AppMsg::UpdateKbdBrightness(value));
|
||||
while let Some(evt) = stream.next().await {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
AppMsg::SetPowerDaemon(power_daemon) => {
|
||||
self.power_daemon = Some(power_daemon.clone());
|
||||
|
||||
// XXX detect change?
|
||||
glib::MainContext::default().spawn(glib::clone!(@strong sender => async move {
|
||||
async {
|
||||
zbus::Result::Ok(if power_daemon.get_switchable().await? {
|
||||
Some(power_daemon.get_graphics().await?)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
};
|
||||
}));
|
||||
// XXX
|
||||
}
|
||||
AppMsg::UpdateProperties => {
|
||||
if let Some(device) = self.device.as_ref() {
|
||||
if let Ok(Some(percentage)) = device.cached_percentage() {
|
||||
self.battery_percent = percentage;
|
||||
}
|
||||
if let Ok(Some(icon_name)) = device.cached_icon_name() {
|
||||
self.icon_name = icon_name;
|
||||
}
|
||||
if let Ok(Some(secs)) = device.cached_time_to_empty() {
|
||||
self.time_remaining = Duration::from_secs(secs as u64);
|
||||
}
|
||||
}
|
||||
}
|
||||
AppMsg::UpdateKbdBrightness(value) => {
|
||||
self.keyboard_brightness = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app: RelmApp<AppModel> = RelmApp::new("com.system76.CosmicAppletBattery");
|
||||
app.run(());
|
||||
}
|
||||
65
applets/cosmic-applet-battery/src/power_daemon.rs
Normal file
65
applets/cosmic-applet-battery/src/power_daemon.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//! # 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`.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "com.system76.PowerDaemon",
|
||||
interface = "com.system76.PowerDaemon",
|
||||
default_path = "/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<Vec<std::collections::HashMap<String, zbus::zvariant::OwnedValue>>>;
|
||||
|
||||
/// GetChargeThresholds method
|
||||
fn get_charge_thresholds(&self) -> zbus::Result<(u8, u8)>;
|
||||
|
||||
/// GetDefaultGraphics method
|
||||
fn get_default_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetExternalDisplaysRequireDGPU method
|
||||
fn get_external_displays_require_dgpu(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetGraphics method
|
||||
fn get_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetGraphicsPower method
|
||||
fn get_graphics_power(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetProfile method
|
||||
fn get_profile(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetSwitchable method
|
||||
fn get_switchable(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// 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<()>;
|
||||
}
|
||||
45
applets/cosmic-applet-battery/src/upower.rs
Normal file
45
applets/cosmic-applet-battery/src/upower.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower' from service 'org.freedesktop.UPower' on system bus`.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.UPower",
|
||||
interface = "org.freedesktop.UPower"
|
||||
)]
|
||||
trait UPower {
|
||||
/// EnumerateDevices method
|
||||
fn enumerate_devices(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
|
||||
|
||||
/// GetCriticalAction method
|
||||
fn get_critical_action(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetDisplayDevice method
|
||||
fn get_display_device(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
||||
|
||||
/// DeviceAdded signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// DeviceRemoved signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
||||
|
||||
/// DaemonVersion property
|
||||
#[dbus_proxy(property)]
|
||||
fn daemon_version(&self) -> zbus::Result<String>;
|
||||
|
||||
/// LidIsClosed property
|
||||
#[dbus_proxy(property)]
|
||||
fn lid_is_closed(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// LidIsPresent property
|
||||
#[dbus_proxy(property)]
|
||||
fn lid_is_present(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// OnBattery property
|
||||
#[dbus_proxy(property)]
|
||||
fn on_battery(&self) -> zbus::Result<bool>;
|
||||
}
|
||||
146
applets/cosmic-applet-battery/src/upower_device.rs
Normal file
146
applets/cosmic-applet-battery/src/upower_device.rs
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower.Device`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower/devices/DisplayDevice' from service 'org.freedesktop.UPower' on system bus`.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.UPower",
|
||||
interface = "org.freedesktop.UPower.Device"
|
||||
)]
|
||||
trait Device {
|
||||
/// GetHistory method
|
||||
fn get_history(
|
||||
&self,
|
||||
type_: &str,
|
||||
timespan: u32,
|
||||
resolution: u32,
|
||||
) -> zbus::Result<Vec<(u32, f64, u32)>>;
|
||||
|
||||
/// GetStatistics method
|
||||
fn get_statistics(&self, type_: &str) -> zbus::Result<Vec<(f64, f64)>>;
|
||||
|
||||
/// Refresh method
|
||||
fn refresh(&self) -> zbus::Result<()>;
|
||||
|
||||
/// BatteryLevel property
|
||||
#[dbus_proxy(property)]
|
||||
fn battery_level(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Capacity property
|
||||
#[dbus_proxy(property)]
|
||||
fn capacity(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// ChargeCycles property
|
||||
#[dbus_proxy(property)]
|
||||
fn charge_cycles(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// Energy property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyEmpty property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_empty(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyFull property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_full(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyFullDesign property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_full_design(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// EnergyRate property
|
||||
#[dbus_proxy(property)]
|
||||
fn energy_rate(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// HasHistory property
|
||||
#[dbus_proxy(property)]
|
||||
fn has_history(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// HasStatistics property
|
||||
#[dbus_proxy(property)]
|
||||
fn has_statistics(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// IconName property
|
||||
#[dbus_proxy(property)]
|
||||
fn icon_name(&self) -> zbus::Result<String>;
|
||||
|
||||
/// IsPresent property
|
||||
#[dbus_proxy(property)]
|
||||
fn is_present(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// IsRechargeable property
|
||||
#[dbus_proxy(property)]
|
||||
fn is_rechargeable(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Luminosity property
|
||||
#[dbus_proxy(property)]
|
||||
fn luminosity(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// Model property
|
||||
#[dbus_proxy(property)]
|
||||
fn model(&self) -> zbus::Result<String>;
|
||||
|
||||
/// NativePath property
|
||||
#[dbus_proxy(property)]
|
||||
fn native_path(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Online property
|
||||
#[dbus_proxy(property)]
|
||||
fn online(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Percentage property
|
||||
#[dbus_proxy(property)]
|
||||
fn percentage(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// PowerSupply property
|
||||
#[dbus_proxy(property)]
|
||||
fn power_supply(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Serial property
|
||||
#[dbus_proxy(property)]
|
||||
fn serial(&self) -> zbus::Result<String>;
|
||||
|
||||
/// State property
|
||||
#[dbus_proxy(property)]
|
||||
fn state(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Technology property
|
||||
#[dbus_proxy(property)]
|
||||
fn technology(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Temperature property
|
||||
#[dbus_proxy(property)]
|
||||
fn temperature(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// TimeToEmpty property
|
||||
#[dbus_proxy(property)]
|
||||
fn time_to_empty(&self) -> zbus::Result<i64>;
|
||||
|
||||
/// TimeToFull property
|
||||
#[dbus_proxy(property)]
|
||||
fn time_to_full(&self) -> zbus::Result<i64>;
|
||||
|
||||
/// Type property
|
||||
#[dbus_proxy(property)]
|
||||
fn type_(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// UpdateTime property
|
||||
#[dbus_proxy(property)]
|
||||
fn update_time(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// Vendor property
|
||||
#[dbus_proxy(property)]
|
||||
fn vendor(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Voltage property
|
||||
#[dbus_proxy(property)]
|
||||
fn voltage(&self) -> zbus::Result<f64>;
|
||||
|
||||
/// WarningLevel property
|
||||
#[dbus_proxy(property)]
|
||||
fn warning_level(&self) -> zbus::Result<u32>;
|
||||
}
|
||||
30
applets/cosmic-applet-battery/src/upower_kbdbacklight.rs
Normal file
30
applets/cosmic-applet-battery/src/upower_kbdbacklight.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//! # DBus interface proxy for: `org.freedesktop.UPower.KbdBacklight`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/UPower/KbdBacklight' from service 'org.freedesktop.UPower' on system bus`.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(
|
||||
default_service = "org.freedesktop.UPower",
|
||||
interface = "org.freedesktop.UPower.KbdBacklight",
|
||||
default_path = "/org/freedesktop/UPower/KbdBacklight"
|
||||
)]
|
||||
trait KbdBacklight {
|
||||
/// GetBrightness method
|
||||
fn get_brightness(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// GetMaxBrightness method
|
||||
fn get_max_brightness(&self) -> zbus::Result<i32>;
|
||||
|
||||
/// SetBrightness method
|
||||
fn set_brightness(&self, value: i32) -> zbus::Result<()>;
|
||||
|
||||
/// BrightnessChanged signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn brightness_changed(&self, value: i32) -> zbus::Result<()>;
|
||||
|
||||
/// BrightnessChangedWithSource signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn brightness_changed_with_source(&self, value: i32, source: &str) -> zbus::Result<()>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue