]> gitweb.fluxo.info Git - utils-x11.git/commitdiff
Fix: xbrightness: misc fixes
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 30 Dec 2022 21:14:56 +0000 (18:14 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 30 Dec 2022 21:14:56 +0000 (18:14 -0300)
xbrightness

index c15c131ccb89ba570d362b16f1c4aabb99b52341..f86f72f1f0367c2f90e93d2571855dd3f305c76a 100755 (executable)
@@ -1,18 +1,23 @@
 #!/usr/bin/env bash
 # Change the screen brightness.
 # See the output of "$0 -h" for details.
+#
+# Script obtained at https://unix.stackexchange.com/questions/61256/how-to-change-lcd-intensivity-brightness
+# Minor fixes by rhatto
 
 # Exit immediately on each error and unset variable;
 # see: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
 #set -Eeuo pipefail
 set -Eeu
 
+# This script is locale-dependent
+export LC_ALL=C
+
 APP_NAME="Screen Brightness Changer"
 cmd=${1:-get}
 bl_dir=/sys/class/backlight/intel_backlight
 
 function print_help() {
-
     script_name="$(basename "$0")"
     echo "${APP_NAME} - Allows to change the screen brightness."
     echo "It may do so using the hardware backlight or through software manipulation of pixel values sent to the screen."
@@ -146,7 +151,7 @@ then
     mth_bare=true
 elif which xrandr > /dev/null 2>&1
 then
-    echo "Using xrandr (software) ..."
+    #echo "Using xrandr (software) ..."
     # This has no prerequisite; it should always work.
     # This method only manipulates the pixel values sent to the screen, imitating more/less brightness (software).
     mth_xrandr=true
@@ -167,7 +172,7 @@ then
     val_cur=$(printf "%.3f" "$(awk "BEGIN { print(1.0 * $val_cur_abs / $val_max) }")")
 elif $mth_xrandr
 then
-    val_cur=$(xrandr --verbose | grep -i "brightness" | sed -e 's|.*: ||')
+    val_cur=$(xrandr --verbose | grep -i "brightness" | sed -e 's|.*: ||' | head -1)
 else
     >&2 echo "No low-level-method chosen!"
     exit 1
@@ -195,8 +200,11 @@ then
     echo -n "$val_new_abs" | tee "$bl_dir/brightness"> /dev/null
 elif $mth_xrandr
 then
-    display=$(xrandr -q | grep " connected" | sed -e 's| .*||')
-    xrandr --output "$display" --brightness "$val_new"
+    displays=$(xrandr -q | grep " connected" | sed -e 's| .*||')
+
+    for display in $displays; do
+      xrandr --output "$display" --brightness "$val_new"
+    done
 else
     >&2 echo "No low-level-method chosen!"
     exit 1