Skip to content

Commit

Permalink
Fix bug related to blight and add a feature for brightness (#67)
Browse files Browse the repository at this point in the history
* Fixed blight returning previous brightness level instead of current

* Interpret the sign of the argument when changing brightness

* Refactor switch case

* Improve sign checking for brightness steps
  • Loading branch information
Albert24GG committed Apr 15, 2024
1 parent a0709bc commit ac6c376
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ bindsym XF86MonBrightnessUp exec swayosd-client --brightness raise
# Brightness lower
bindsym XF86MonBrightnessDown exec swayosd-client --brightness lower

# Brightness raise with custom value
bindsym XF86MonBrightnessUp exec swayosd-client --brightness 10
# Brightness lower with custom value
# Brightness raise with custom value('+' sign needed)
bindsym XF86MonBrightnessUp exec swayosd-client --brightness +10
# Brightness lower with custom value('-' sign needed)
bindsym XF86MonBrightnessDown exec swayosd-client --brightness -10
```

Expand Down
1 change: 1 addition & 0 deletions src/brightness_backend/blight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl BrightnessBackendConstructor for Blight {

impl BrightnessBackend for Blight {
fn get_current(&mut self) -> u32 {
self.device.reload();
self.device.current()
}

Expand Down
14 changes: 13 additions & 1 deletion src/global_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,21 @@ pub(crate) fn handle_application_args(
}
"brightness" => {
let value = child.value().str().unwrap_or("");

let coef: i32 = match value.get(..1) {
Some("+") => 1,
Some("-") => -1,
_ => 0,
};

match (value, value.parse::<i8>()) {
// Parse custom step values
(_, Ok(num)) => (ArgTypes::BrightnessSet, Some(num.abs().to_string())),
(_, Ok(num)) => match coef {
1 => (ArgTypes::BrightnessRaise, Some(num.to_string())),
-1 => (ArgTypes::BrightnessLower, Some(num.abs().to_string())),
_ => (ArgTypes::BrightnessSet, Some(num.to_string())),
},

("raise", _) => (ArgTypes::BrightnessRaise, None),
("lower", _) => (ArgTypes::BrightnessLower, None),
(e, _) => {
Expand Down

0 comments on commit ac6c376

Please sign in to comment.