Allow backlight device to be specified
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@
|
|||||||
},{
|
},{
|
||||||
"margin": {
|
"margin": {
|
||||||
"margins": [0,0,0,8],
|
"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": {
|
"margin": {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ widget:
|
|||||||
margins: [0, 0, 0, 8]
|
margins: [0, 0, 0, 8]
|
||||||
widget:
|
widget:
|
||||||
backlight:
|
backlight:
|
||||||
|
device: "intel_backlight"
|
||||||
font_size: 24.0
|
font_size: 24.0
|
||||||
length: 600
|
length: 600
|
||||||
- margin:
|
- margin:
|
||||||
|
|||||||
+10
-2
@@ -45,6 +45,8 @@ pub enum Widget {
|
|||||||
length: u32,
|
length: u32,
|
||||||
},
|
},
|
||||||
Backlight {
|
Backlight {
|
||||||
|
#[serde(default)]
|
||||||
|
device: String,
|
||||||
font_size: f32,
|
font_size: f32,
|
||||||
length: u32,
|
length: u32,
|
||||||
},
|
},
|
||||||
@@ -121,8 +123,13 @@ impl Widget {
|
|||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Widget::Backlight { font_size, length } => {
|
Widget::Backlight { device, font_size, length } => {
|
||||||
match widgets::backlight::Backlight::new(font_size, length) {
|
let d = if device == "" {
|
||||||
|
"intel_backlight"
|
||||||
|
} else {
|
||||||
|
&device
|
||||||
|
};
|
||||||
|
match widgets::backlight::Backlight::new(d, font_size, length) {
|
||||||
Ok(w) => Some(w),
|
Ok(w) => Some(w),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
@@ -192,6 +199,7 @@ impl Default for Config {
|
|||||||
Box::new(Widget::Margin {
|
Box::new(Widget::Margin {
|
||||||
margins: (0, 0, 0, 8),
|
margins: (0, 0, 0, 8),
|
||||||
widget: Box::new(Widget::Backlight {
|
widget: Box::new(Widget::Backlight {
|
||||||
|
device: "intel_backlight".to_string(),
|
||||||
font_size: 24.0,
|
font_size: 24.0,
|
||||||
length: 600,
|
length: 600,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -71,18 +71,9 @@ impl Backlight {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(font_size: f32, length: u32) -> Result<Box<BarWidget>, Error> {
|
pub fn new(path: &str, 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")),
|
|
||||||
};
|
|
||||||
let mut dev = Backlight {
|
let mut dev = Backlight {
|
||||||
device_path: first_device.path(),
|
device_path: Path::new("/sys/class/backlight").to_path_buf().join(path),
|
||||||
cur_brightness: 0,
|
cur_brightness: 0,
|
||||||
max_brightness: 0,
|
max_brightness: 0,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user