Debian Codegraph @

backlight.sh

raw symbols SCIP
1 #!/bin/bash
2 # backlight.sh
3 # reldate 02dec2011
4
5 # A bug in Fedora Core 16/17 messes up the keyboard backlight controls.
6 # This script is a quick-n-dirty workaround, essentially a shell wrapper
7 #+ for xrandr. It gives more control than on-screen sliders and widgets.
8
9 OUTPUT=$(xrandr | grep LV | awk '{print $1}') # Get display name!
10 INCR=.05 # For finer-grained control, set INCR to .03 or .02.
11
12 old_brightness=$(xrandr --verbose | grep rightness | awk '{ print $2 }')
13
14
15 if [ -z "$1" ]
16 then
17 bright=1 # If no command-line arg, set brightness to 1.0 (default).
18
19 else
20 if [ "$1" = "+" ]
21 then
22 bright=$(echo "scale=2; $old_brightness + $INCR" | bc) # +.05
23
24 else
25 if [ "$1" = "-" ]
26 then
27 bright=$(echo "scale=2; $old_brightness - $INCR" | bc) # -.05
28
29 else
30 if [ "$1" = "#" ] # Echoes current brightness; does not change it.
31 then
32 bright=$old_brightness
33
34 else
35 if [[ "$1" = "h" || "$1" = "H" ]]
36 then
37 echo
38 echo "Usage:"
39 echo "$0 [No args] Sets/resets brightness to default (1.0)."
40 echo "$0 + Increments brightness by 0.5."
41 echo "$0 - Decrements brightness by 0.5."
42 echo "$0 # Echoes current brightness without changing it."
43 echo "$0 N (number) Sets brightness to N (useful range .7 - 1.2)."
44 echo "$0 h [H] Echoes this help message."
45 echo "$0 any-other Gives xrandr usage message."
46
47 bright=$old_brightness
48
49 else
50 bright="$1"
51
52 fi
53 fi
54 fi
55 fi
56 fi
57
58
59 xrandr --output "$OUTPUT" --brightness "$bright" # See xrandr manpage.
60 # As root!
61 E_CHANGE0=$?
62 echo "Current brightness = $bright"
63
64 exit $E_CHANGE0
65
66
67 # =========== Or, alternately . . . ==================== #
68
69 #!/bin/bash
70 # backlight2.sh
71 # reldate 20jun2012
72
73 # A bug in Fedora Core 16/17 messes up the keyboard backlight controls.
74 # This is a quick-n-dirty workaround, an alternate to backlight.sh.
75
76 target_dir=\
77 /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/backlight/acpi_video0
78 # Hardware directory.
79
80 actual_brightness=$(cat $target_dir/actual_brightness)
81 max_brightness=$(cat $target_dir/max_brightness)
82 Brightness=$target_dir/brightness
83
84 let "req_brightness = actual_brightness" # Requested brightness.
85
86 if [ "$1" = "-" ]
87 then # Decrement brightness 1 notch.
88 let "req_brightness = $actual_brightness - 1"
89 else
90 if [ "$1" = "+" ]
91 then # Increment brightness 1 notch.
92 let "req_brightness = $actual_brightness + 1"
93 fi
94 fi
95
96 if [ $req_brightness -gt $max_brightness ]
97 then
98 req_brightness=$max_brightness
99 fi # Do not exceed max. hardware design brightness.
100
101 echo
102
103 echo "Old brightness = $actual_brightness"
104 echo "Max brightness = $max_brightness"
105 echo "Requested brightness = $req_brightness"
106 echo
107
108 # =====================================
109 echo $req_brightness > $Brightness
110 # Must be root for this to take effect.
111 E_CHANGE1=$? # Successful?
112 # =====================================
113
114 if [ "$?" -eq 0 ]
115 then
116 echo "Changed brightness!"
117 else
118 echo "Failed to change brightness!"
119 fi
120
121 act_brightness=$(cat $Brightness)
122 echo "Actual brightness = $act_brightness"
123
124 scale0=2
125 sf=100 # Scale factor.
126 pct=$(echo "scale=$scale0; $act_brightness / $max_brightness * $sf" | bc)
127 echo "Percentage brightness = $pct%"
128
129 exit $E_CHANGE1