battery: Minor cleanup
This commit is contained in:
@@ -17,7 +17,6 @@ const BAR_SIZE: f32 = 24.;
|
|||||||
pub trait BarWidgetImpl {
|
pub trait BarWidgetImpl {
|
||||||
fn get_dirty(&self) -> bool;
|
fn get_dirty(&self) -> bool;
|
||||||
fn set_dirty(&mut self, dirty: bool);
|
fn set_dirty(&mut self, dirty: bool);
|
||||||
fn update(&mut self);
|
|
||||||
fn name(&self) -> &'static str;
|
fn name(&self) -> &'static str;
|
||||||
fn value(&self) -> f32;
|
fn value(&self) -> f32;
|
||||||
fn color(&self) -> Color;
|
fn color(&self) -> Color;
|
||||||
|
|||||||
+16
-8
@@ -6,6 +6,14 @@ use std::{
|
|||||||
|
|
||||||
use calloop::ping::Ping;
|
use calloop::ping::Ping;
|
||||||
|
|
||||||
|
use dbus::blocking::{
|
||||||
|
LocalConnection,
|
||||||
|
stdintf::org_freedesktop_dbus::{
|
||||||
|
Properties,
|
||||||
|
PropertiesPropertiesChanged,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
color::Color,
|
color::Color,
|
||||||
widgets::bar_widget::{
|
widgets::bar_widget::{
|
||||||
@@ -29,10 +37,9 @@ struct InnerBattery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_monitor(inner: Arc<Mutex<InnerBattery>>, ping: Ping) {
|
fn start_monitor(inner: Arc<Mutex<InnerBattery>>, ping: Ping) {
|
||||||
thread::spawn(move || {
|
thread::Builder::new()
|
||||||
use dbus::blocking::LocalConnection;
|
.name("battmon".to_string())
|
||||||
use dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
|
.spawn(move || {
|
||||||
use dbus::blocking::stdintf::org_freedesktop_dbus::PropertiesPropertiesChanged;
|
|
||||||
let conn = LocalConnection::new_system().unwrap();
|
let conn = LocalConnection::new_system().unwrap();
|
||||||
let device_path = "/org/freedesktop/UPower/devices/DisplayDevice";
|
let device_path = "/org/freedesktop/UPower/devices/DisplayDevice";
|
||||||
let proxy = conn.with_proxy("org.freedesktop.UPower", device_path, Duration::from_millis(500));
|
let proxy = conn.with_proxy("org.freedesktop.UPower", device_path, Duration::from_millis(500));
|
||||||
@@ -85,7 +92,7 @@ fn start_monitor(inner: Arc<Mutex<InnerBattery>>, ping: Ping) {
|
|||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
loop { conn.process(Duration::from_millis(60000)).unwrap(); }
|
loop { conn.process(Duration::from_millis(60000)).unwrap(); }
|
||||||
});
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Battery {
|
pub struct Battery {
|
||||||
@@ -109,7 +116,6 @@ impl Battery {
|
|||||||
|
|
||||||
|
|
||||||
impl BarWidgetImpl for Battery {
|
impl BarWidgetImpl for Battery {
|
||||||
fn update(&mut self) {}
|
|
||||||
fn get_dirty(&self) -> bool {
|
fn get_dirty(&self) -> bool {
|
||||||
self.dirty
|
self.dirty
|
||||||
}
|
}
|
||||||
@@ -127,10 +133,12 @@ impl BarWidgetImpl for Battery {
|
|||||||
let inner = self.inner.lock().unwrap();
|
let inner = self.inner.lock().unwrap();
|
||||||
match inner.state {
|
match inner.state {
|
||||||
UpowerBatteryState::Discharging | UpowerBatteryState::Unknown => {
|
UpowerBatteryState::Discharging | UpowerBatteryState::Unknown => {
|
||||||
if inner.value > 0.1 {
|
if inner.value > 0.25 {
|
||||||
Color::new(1.0, 1.0, 1.0, 1.0)
|
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)
|
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 => {
|
UpowerBatteryState::Charging | UpowerBatteryState::Full => {
|
||||||
|
|||||||
Reference in New Issue
Block a user