From 67340e53ba628dfbe841979aefe8e21386c3687f Mon Sep 17 00:00:00 2001 From: Albert24GG Date: Fri, 15 Dec 2023 22:55:39 +0200 Subject: [PATCH 1/4] Fixed blight returning previous brightness level instead of current --- src/brightness_backend/blight.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/brightness_backend/blight.rs b/src/brightness_backend/blight.rs index c1cc14f..9d3c1c8 100644 --- a/src/brightness_backend/blight.rs +++ b/src/brightness_backend/blight.rs @@ -16,6 +16,7 @@ impl BrightnessBackendConstructor for Blight { impl BrightnessBackend for Blight { fn get_current(&mut self) -> u32 { + self.device.reload(); self.device.current() } From 82e270f7529bcf55fc1044685112ffccf1d95e9c Mon Sep 17 00:00:00 2001 From: Albert24GG Date: Fri, 15 Dec 2023 23:01:03 +0200 Subject: [PATCH 2/4] Interpret the sign of the argument when changing brightness --- README.md | 6 +++--- src/global_utils.rs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 46f9b7b..a717998 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/src/global_utils.rs b/src/global_utils.rs index 8552b11..d75684e 100644 --- a/src/global_utils.rs +++ b/src/global_utils.rs @@ -68,9 +68,22 @@ pub(crate) fn handle_application_args( } "brightness" => { let value = child.value().str().unwrap_or(""); + let coef = if value.starts_with('+') { + 1 + } else if value.starts_with('-') { + -1 + } else { + 0 + }; + match (value, value.parse::()) { // Parse custom step values - (_, Ok(num)) => (ArgTypes::BrightnessSet, Some(num.abs().to_string())), + (_, Ok(num)) if coef == 1 => (ArgTypes::BrightnessRaise, Some(num.to_string())), + (_, Ok(num)) if coef == -1 => { + (ArgTypes::BrightnessLower, Some(num.abs().to_string())) + } + (_, Ok(num)) if coef == 0 => (ArgTypes::BrightnessSet, Some(num.to_string())), + ("raise", _) => (ArgTypes::BrightnessRaise, None), ("lower", _) => (ArgTypes::BrightnessLower, None), (e, _) => { From 728508e444875c48c7a5d20a17ac1402cedfe77d Mon Sep 17 00:00:00 2001 From: Albert24GG Date: Tue, 13 Feb 2024 11:33:17 +0200 Subject: [PATCH 3/4] Refactor switch case --- src/global_utils.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/global_utils.rs b/src/global_utils.rs index d75684e..f24d3ed 100644 --- a/src/global_utils.rs +++ b/src/global_utils.rs @@ -78,11 +78,11 @@ pub(crate) fn handle_application_args( match (value, value.parse::()) { // Parse custom step values - (_, Ok(num)) if coef == 1 => (ArgTypes::BrightnessRaise, Some(num.to_string())), - (_, Ok(num)) if coef == -1 => { - (ArgTypes::BrightnessLower, Some(num.abs().to_string())) - } - (_, Ok(num)) if coef == 0 => (ArgTypes::BrightnessSet, Some(num.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), From e0c7090b9dc7f3e756ad7235d4e898b22d45d6a4 Mon Sep 17 00:00:00 2001 From: Albert24GG Date: Tue, 26 Mar 2024 15:04:49 +0200 Subject: [PATCH 4/4] Improve sign checking for brightness steps --- src/global_utils.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/global_utils.rs b/src/global_utils.rs index f24d3ed..0be55cb 100644 --- a/src/global_utils.rs +++ b/src/global_utils.rs @@ -68,12 +68,11 @@ pub(crate) fn handle_application_args( } "brightness" => { let value = child.value().str().unwrap_or(""); - let coef = if value.starts_with('+') { - 1 - } else if value.starts_with('-') { - -1 - } else { - 0 + + let coef: i32 = match value.get(..1) { + Some("+") => 1, + Some("-") => -1, + _ => 0, }; match (value, value.parse::()) {