Allow backlight device to be specified

This commit is contained in:
Kenny Levinsen
2020-01-01 17:18:42 +01:00
parent 9233128b7c
commit 2ba19f9e64
4 changed files with 14 additions and 14 deletions
+1 -1
View File
@@ -23,7 +23,7 @@
},{
"margin": {
"margins": [0,0,0,8],
"widget": {"backlight": {"font_size": 24.0,"length": 600}}
"widget": {"backlight": {"device": "intel_backlight", "font_size": 24.0,"length": 600}}
}
},{
"margin": {
+1
View File
@@ -30,6 +30,7 @@ widget:
margins: [0, 0, 0, 8]
widget:
backlight:
device: "intel_backlight"
font_size: 24.0
length: 600
- margin:
+10 -2
View File
@@ -45,6 +45,8 @@ pub enum Widget {
length: u32,
},
Backlight {
#[serde(default)]
device: String,
font_size: f32,
length: u32,
},
@@ -121,8 +123,13 @@ impl Widget {
Err(_) => None,
}
}
Widget::Backlight { font_size, length } => {
match widgets::backlight::Backlight::new(font_size, length) {
Widget::Backlight { device, font_size, length } => {
let d = if device == "" {
"intel_backlight"
} else {
&device
};
match widgets::backlight::Backlight::new(d, font_size, length) {
Ok(w) => Some(w),
Err(_) => None,
}
@@ -192,6 +199,7 @@ impl Default for Config {
Box::new(Widget::Margin {
margins: (0, 0, 0, 8),
widget: Box::new(Widget::Backlight {
device: "intel_backlight".to_string(),
font_size: 24.0,
length: 600,
}),
+2 -11
View File
@@ -71,18 +71,9 @@ impl Backlight {
Ok(())
}
pub fn new(font_size: f32, length: u32) -> Result<Box<BarWidget>, Error> {
let devices = Path::new("/sys/class/backlight").read_dir()?;
let first_device = match devices.take(1).next() {
Some(v) => match v {
Ok(v) => v,
Err(_) => return Err(Error::new(ErrorKind::Other, "no backlight device")),
},
None => return Err(Error::new(ErrorKind::Other, "no backlight device")),
};
pub fn new(path: &str, font_size: f32, length: u32) -> Result<Box<BarWidget>, Error> {
let mut dev = Backlight {
device_path: first_device.path(),
device_path: Path::new("/sys/class/backlight").to_path_buf().join(path),
cur_brightness: 0,
max_brightness: 0,
};