config: Generate configs

This commit is contained in:
Kenny Levinsen
2023-02-12 17:02:44 +01:00
parent db085168dc
commit 9e48eb053d
7 changed files with 179 additions and 104 deletions
+8
View File
@@ -39,6 +39,14 @@ impl Backlight {
dev.update();
BarWidget::new(Box::new(dev), fm, font, size)
}
pub fn detect(path: &str) -> bool {
let path = Path::new("/sys/class/backlight").to_path_buf().join(path);
match read_file_as_u64(path.join("brightness").as_path()) {
Ok(_) => true,
Err(_) => false,
}
}
}
impl BarWidgetImpl for Backlight {
+21
View File
@@ -2,6 +2,7 @@ use std::{
sync::{Arc, Mutex},
thread,
time::Duration,
error::Error,
};
use dbus::blocking::{
@@ -46,6 +47,19 @@ struct InnerBattery {
dirty: bool,
}
fn get_battery_state() -> Result<UpowerBatteryState, Box<dyn Error>> {
let conn = LocalConnection::new_system()?;
let device_path = "/org/freedesktop/UPower/devices/DisplayDevice";
let proxy = conn.with_proxy(
"org.freedesktop.UPower",
device_path,
Duration::from_millis(500),
);
let state: u32 = proxy
.get("org.freedesktop.UPower.Device", "State")?;
Ok(UpowerBatteryState::from_dbus(state as u64))
}
fn start_monitor(inner: Arc<Mutex<InnerBattery>>, events: Arc<Mutex<Events>>) {
thread::Builder::new()
.name("battmon".to_string())
@@ -131,6 +145,13 @@ impl Battery {
start_monitor(battery.inner.clone(), events);
BarWidget::new(Box::new(battery), fm, font, size)
}
pub fn detect() -> bool {
match get_battery_state() {
Ok(_) => true,
Err(_) => false,
}
}
}
impl BarWidgetImpl for Battery {