5

I'm currently migrating to openbox without gnome session. In unity i can use the vendor keys to set the screen brightness, but in openbox I'm on my own.

  • /sys/class/backlight/acpi_video0/brightness works fine, the problem is that I need sudo to set the brightness and that wouldn't work with keyboard mappings.
  • xbacklight -get/set doesn't do or output anything.
  • I don't really want to use xrandr --brightness.

Are there any other options or a way to fix the problems with xbacklight or acpi_video0 ?

3 Answers3

3

The command GNOME and Unity use is:

pkexec /usr/lib/gnome-settings-daemon/gsd-backlight-helper --set-brightness 5

It does not require a GNOME session to be running, just PolicyKit – which is almost always present in Ubuntu.


You can use ordinary sudo in key bindings; it can be configured to run certain commands without a password by editing the sudoers file. For example:

zls     ALL=(root) NOPASSWD: /usr/lib/gnome-settings-daemon/gsd-backlight-helper

or

zls     ALL=(root) NOPASSWD: /usr/local/bin/my-custom-brightness-script
grawity
  • 501,077
1

My solution was to add the following line to etc/rc.local:

chmod a+w /proc/acpi/video/VID/LCD/brightness

I don't know if permissions can also be changed in the /sys filesystem.

0

I just wrote a POSIX-compliant script to set backlight (much like xbacklight but directly manipulating /sys/class/backlight/... ) that works in X and the console.

The script has an --install option that when run as root sets the permissions of the /sys/class/backlight/*/brigtness so a specified group can write to it and also to make it last over reboots installs a systemd service which sets the permissions at every system startup.

promt% backlight --help

USAGE: backlight [ -g | --get ] Get the current brightness value in percent of MAX brightness.

backlight { -s | --set | -i | --increase | -d | --decrease } percent
   Set the brightness to 'percent' of max brightness or change it
   (increase / decrease) 'percent'. 'percent' is a integer with or
   without a trailing % sign.  Even though -s 0 will usually give
   a darker screen than -s 1, these options will never completely
   turn the brightness off as it might have unexpected
   consequences (see -off).

backlight { -0 | -o | --off }
   Set the brightness to 0 (on some systems, 'xset dpms force off'
   also sets the brightness to 0 so it may make 'xset dpms force
   on' unexpectantly turn up the brightness under some
   circumstances).

backlight --install [ groupname ]
   Allow the specified group (or the video group if none
   specified) to set the brighness forth on.

   Must be run by root.

   If systemd is in use 'backlight --install' will also install,
   enable and run a systemd service making 'brightness' writeable
   by the specified group at system startup.

   'backlight --install' will replace the
   /etc/systemd/system/backlightgroup.service it if it already exists.

Take a look at it on githup, where I will keep it updated if I do any changes: https://github.com/fraxflax/backlight

Right now it just picks the first backlight-device it finds and manipulates that, if you have several folders in sys/class/backlight/ and want to manipulate a certain one you might want to replace the

SYS="/sys/class/backlight/`ls -1 /sys/class/backlight/ | head -1`"

line with something like

#SYS="/sys/class/backlight/`ls -1 /sys/class/backlight/ | head -1`"
SYS=/sys/class/backlight/acpi_video0

Here's the full script:

#!/bin/sh
# 
# backlight is a POSIX-compliant (pure bourne shell) script that
# allows you to get and set the brightness of the screen via
# /sys/backlight if supported by your system.
# 
# This is free software created by frax@axnet.nu,
# feel free to use, modify and/or distribute as you see fit.
# 
# TODO:
# - Handle multiple backlight devices 
#   (currently only the first one found is used)
#

Set LOWEST to 0 to be able to completely turn the backlight off with

-set and -dec or to a higher value (e.g. 1) to prevent turning the

light completely off as this might be considered turning the screen

off and "xset dpms force on" on some systems will turn up the light

if brighness is 0.

LOWEST=1

SYS="/sys/class/backlight/ls -1 /sys/class/backlight/ | head -1"

USAGE() { backlight=basename $0 || backlight=backlight test -n "$1" && /bin/echo -e "\n###\n$@\n###" cat>/dev/stderr<<EOF

USAGE: $backlight [ -g | --get ] Get the current brightness value in percent of MAX brightness.

$backlight { -s | --set | -i | --increase | -d | --decrease } percent
   Set the brightness to 'percent' of max brightness or change it
   (increase / decrease) 'percent'. 'percent' is a integer with or
   without a trailing % sign.  Even though -s 0 will usually give
   a darker screen than -s 1, these options will never completely
   turn the brightness off as it might have unexpected
   consequences (see -off).

$backlight { -0 | -o | --off }
   Set the brightness to 0 (on some systems, 'xset dpms force off'
   also sets the brightness to 0 so it may make 'xset dpms force
   on' unexpectantly turn up the brightness under some
   circumstances).

$backlight --install [ groupname ]
   Allow the specified group (or the video group if none
   specified) to set the brighness forth on.

   Must be run by root.

   If systemd is in use '$backlight --install' will also install,
   enable and run a systemd service making 'brightness' writeable
   by the specified group at system startup.

   '$backlight --install' will replace the
   /etc/systemd/system/backlightgroup.service it if it already exists.

EOF exit 1 }

[ -e "$SYS/brightness" -a -e "$SYS/max_brightness" ] || USAGE "# No supported backlight system in /sys/class/backlight"

[ "--install" = "$1" ] && { test id -u -eq 0 || USAGE "# 'backlight -install' must be run as root" GRP=video test -n "$2" && GRP=$2 chgrp $GRP /sys/class/backlight//brightness ; chmod g+w /sys/class/backlight//brightness echo ls -l /sys/class/backlight/*/brightness echo test -d /etc/systemd/system && { grep -E "^$GRP:" /etc/group >/dev/null || USAGE "# group '$GRP' not found in /etc/group" cat>/etc/systemd/system/backlightgroup.service<<EOF [Unit] Description=Permission for group $GRP to set backlight brightness After=syslog.target

[Service] Type=oneshot ExecStart=/bin/sh -c '/bin/chgrp $GRP /sys/class/backlight//brightness ; /bin/chmod g+w /sys/class/backlight//brightness' RemainAfterExit=no

[Install] WantedBy=sysinit.target EOF systemctl enable backlightgroup.service || USAGE "# failed to enable the backlightgroup.service" systemctl start backlightgroup.service || USAGE "# failed to start the backlightgroup.service" systemctl status --no-pager backlightgroup.service } exit 0 } MAX=cat &quot;$SYS/max_brightness&quot; CUR=cat &quot;$SYS/brightness&quot;

[ "-g" = "$1" -o "--get" = "$1" -o -z "$1" ] && { echo $(($CUR*100/$MAX))% exit 0 }

if [ "-0" = "$1" -o "-o" = "$1" -o "--off" = "$1" ]; then NVAL=0 LOWEST=0 else VAL=echo $2 | sed 's/[^0-9]*\([0-9][0-9]*\).*/\1/' # just keep the first found consecutive digits ISNUM=echo $VAL | sed 's/[0-9]*//' # if there was no digits at all this will be nonempty test -z "$VAL" -o -n "$ISNUM" && USAGE

OP=$1    
case &quot;$OP&quot; in
    -s|--set)
        NVAL=$(($VAL*$MAX/100))
        ;;
    -i|--increase)
        NVAL=$(($CUR+$VAL*$MAX/100))
        ;;
    -d|--decrease)
        NVAL=$(($CUR-$VAL*$MAX/100))
        ;;
    *)
        USAGE
        ;;
esac

fi test $NVAL -gt $MAX && NVAL=$MAX test $NVAL -lt $LOWEST && NVAL=$LOWEST echo $NVAL > "$SYS/brightness"

#echo $(($NVAL*100/$MAX))"% ($NVAL/$MAX)" >/dev/stderr exit 0

fraxflax
  • 131
  • 8