From dd790468ad6bb88c88ecf257f78ebfb6ee1ca018 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 11 Jan 2023 23:54:39 +0100 Subject: [PATCH] battery: Minor cleanup --- src/widgets/bar_widget.rs | 1 - src/widgets/battery.rs | 24 ++++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/widgets/bar_widget.rs b/src/widgets/bar_widget.rs index 67164ba..f281d9c 100644 --- a/src/widgets/bar_widget.rs +++ b/src/widgets/bar_widget.rs @@ -17,7 +17,6 @@ const BAR_SIZE: f32 = 24.; pub trait BarWidgetImpl { fn get_dirty(&self) -> bool; fn set_dirty(&mut self, dirty: bool); - fn update(&mut self); fn name(&self) -> &'static str; fn value(&self) -> f32; fn color(&self) -> Color; diff --git a/src/widgets/battery.rs b/src/widgets/battery.rs index 57fb3fd..862df51 100644 --- a/src/widgets/battery.rs +++ b/src/widgets/battery.rs @@ -6,6 +6,14 @@ use std::{ use calloop::ping::Ping; +use dbus::blocking::{ + LocalConnection, + stdintf::org_freedesktop_dbus::{ + Properties, + PropertiesPropertiesChanged, + }, +}; + use crate::{ color::Color, widgets::bar_widget::{ @@ -29,10 +37,9 @@ struct InnerBattery { } fn start_monitor(inner: Arc>, ping: Ping) { - thread::spawn(move || { - use dbus::blocking::LocalConnection; - use dbus::blocking::stdintf::org_freedesktop_dbus::Properties; - use dbus::blocking::stdintf::org_freedesktop_dbus::PropertiesPropertiesChanged; + thread::Builder::new() + .name("battmon".to_string()) + .spawn(move || { let conn = LocalConnection::new_system().unwrap(); let device_path = "/org/freedesktop/UPower/devices/DisplayDevice"; let proxy = conn.with_proxy("org.freedesktop.UPower", device_path, Duration::from_millis(500)); @@ -85,7 +92,7 @@ fn start_monitor(inner: Arc>, ping: Ping) { }).unwrap(); loop { conn.process(Duration::from_millis(60000)).unwrap(); } - }); + }).unwrap(); } pub struct Battery { @@ -109,7 +116,6 @@ impl Battery { impl BarWidgetImpl for Battery { - fn update(&mut self) {} fn get_dirty(&self) -> bool { self.dirty } @@ -127,10 +133,12 @@ impl BarWidgetImpl for Battery { let inner = self.inner.lock().unwrap(); match inner.state { UpowerBatteryState::Discharging | UpowerBatteryState::Unknown => { - if inner.value > 0.1 { + if inner.value > 0.25 { Color::new(1.0, 1.0, 1.0, 1.0) - } else { + } else if inner.value > 0.1 { Color::new(1.0, 0.5, 0.0, 1.0) + } else { + Color::new(1.0, 0.0, 0.0, 1.0) } } UpowerBatteryState::Charging | UpowerBatteryState::Full => {