Yogesh Ashok Powar

Personal Blogs

  • Feed Subscribe
  • i3 - screen brightness control

    i3 hack for screen brightness control

    Tags: GNU/Linux OS i3

    i3: screen brightness control

    i3 is improved tiling window manager. Its FOSS and targeted to advanced user and developer community. It uses xcb (The X protocol C-language Binding) than xlib. Details can be found at https://i3wm.org/

    Screen brightness:

    There are on keyboard special function keys which control brightness and on heavier window managers these things are auto configured but on i3 we need to configure it. One way to control screen brightness on Intel based systems is by updating `/sys/class` file

    echo "<num>" > /sys/class/backlight/intel\_backlight/brightness
    

    scripts

    upbrightness
    $ which upbrightness
    
    /usr/bin/upbrightness
    
    $ cat /usr/bin/upbrightness
    
    #!bin/bash
    set -x
    id
    max=\`cat /sys/class/backlight/intel\_backlight/max\_brightness\`
    current=\`cat /sys/class/backlight/intel\_backlight/brightness\`
    newCurrent=$(($current + 50))
    if \[ $current -eq $max \]
    then
        exit
    fi
    if \[ $newCurrent -gt $max \]
    then
        newCurrent=$max
    fi
    echo $newCurrent > /sys/class/backlight/intel\_backlight/brightness
    
    downbrightness
    $ which downbrightness
    
    /usr/bin/downbrightness
    
    $ cat /usr/bin/downbrightness
    
    #!/bin/bash
    set -x
    id
    min=50
    current=\`cat /sys/class/backlight/intel\_backlight/brightness\`
    newCurrent=$(($current - 50))
    if \[ $current -eq $min \]
    then
        exit
    fi
    if \[ $newCurrent -lt $min \]
    then
        newCurrent=$min
    fi
    echo $newCurrent > /sys/class/backlight/intel\_backlight/brightness
    
    Add sudo access
    $ cat /etc/sudoers | grep down
    
    <user> ALL=NOPASSWD:/usr/bin/upbrightness,/usr/bin/downbrightness
    
    

    Configure i3 key bindings

    $ cat ~/.config/i3/config | grep brigh
    
    bindsym XF86MonBrightnessUp exec sudo upbrightness
    bindsym XF86MonBrightnessDown exec sudo downbrightness
    

    Tags: GNU/Linux OS i3
    Updated on: 2020-06-20