Wednesday 4 November 2015

Brightness controls

Although the brightness controls work, they operate in rather large steps. If you use your laptop at night, like I do, then you might want to get the screen darker without turning off completely.

You can do this by writing a value directly to:

/sys/class/backlight/intel_backlight/brightness

as the root user.

I adapted a previous script I wrote to do this and bound this to a shortcut key which now gives an additional 3 steps between the current darkest setting and 'off'. I will upload the script and associated polkit later.

$ cat set-brightness
#!/bin/sh
echo "$1" > /sys/class/backlight/intel_backlight/brightness

$ cat brightness
#!/bin/sh
# Control screen brightness on Acer V3-372
#
# Adjusts brightness between 0 and 187
# Usage: brightness [u|d]

PKEXEC=/usr/bin/pkexec
#GSDBL=/usr/lib/gnome-settings-daemon/gsd-backlight-helper
#GSDBL=/usr/lib/xserver-xorg-video-intel/xf86-video-intel-backlight-helper
GSDBL=/usr/local/bin/set-brightness
#BRIGHTNESS=$( ${PKEXEC} ${GSDBL} --get-brightness )
BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/brightness )
case "$1" in
   u* ) 
${PKEXEC} ${GSDBL} $(($BRIGHTNESS*2))  
if [ "$BRIGHTNESS" -ge "90" ]
then ${PKEXEC} ${GSDBL} "187"  
elif [ "$BRIGHTNESS" -eq "0" ] 
then ${PKEXEC} ${GSDBL} "1"  
#else 
# ${PKEXEC} ${GSDBL} $(($BRIGHTNESS*2))  
fi
;;
   d* ) 
if [ "$BRIGHTNESS" -gt "186" ]
then ${PKEXEC} ${GSDBL} "128"  
elif [ "$BRIGHTNESS" -eq "1" ] 
then ${PKEXEC} ${GSDBL} "0"  
else 
${PKEXEC} ${GSDBL} $(($BRIGHTNESS/2))  
fi
;;
esac
BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/brightness )
echo "Screen brightness = " $BRIGHTNESS "/187"
/usr/bin/notify-send -t 500 $BRIGHTNESS"/187"
exit 0

$ cat org.freedesktop.policykit.exec.policy 
<?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
   <policyconfig>

<vendor>Examples for the PolicyKit Project</vendor>
<vendor_url>http://hal.freedesktop.org/docs/PolicyKit/</vendor_url>

<action id="org.freedesktop.policykit.exec.run.set-brightness">
  <description>Run the PolicyKit example program Frobnicate</description>
  <description xml:lang="da">Kør PolicyKit eksemplet Frobnicate</description>
  <message>Authentication is required to run the PolicyKit example program Frobnicate (user=$(user), program=$(program), command_line=$(command_line))</message>
  <message xml:lang="da">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate (user=$(user), program=$(program), command_line=$(command_line))</message>
  <icon_name>audio-x-generic</icon_name>
  <defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
  </defaults>
  <annotate key="org.freedesktop.policykit.exec.path">/usr/local/bin/set-brightness</annotate>
</action>

</policyconfig>

No comments:

Post a Comment