Pages

Wednesday, September 28, 2016

Refined brightness with i3-WM and i3blocks

I'm a picky person and it decided it was high time to clean up the display for my brightness in i3blocks.


In order to control my brightness via the keyboard, I found that I needed to create a bindsym using xbacklight to reflect this in my ~/.config/i3/config. I chose to increase and decrease xbacklight by 10%.

Initial bindsym:


#Brightness controls
bindsym XF86MonBrightnessUp exec "xbacklight -inc 10 ; pkill -RTMIN+1 i3blocks"
bindsym XF86MonBrightnessDown exec "xbacklight -dec 10 ; pkill -RTMIN+1 i3blocks"


The problem I found with this is that xbacklight increases and decreases based on percentage values of the total maximum brightness for the screen, which on my system is 937. This meant that if i3blocks displayed my brightness at 100% and then I decreased it by 10%, the next value displayed was 89%. This bothered me for no other reason than I am pretty neurotic.

The other problem is that at night-time, I wanted to be able to easily set my brightness to just slightly above 0% to reduce strain on my eyes while using my laptop in total darkness. I also wanted to be able to turn my screen off using the brightness controls because my partner enjoys listening to netflix shows with the screen off while she's trying to sleep. At the settings I had initially, I could turn the screen off but once I increased the brightness, it increased to a value of 9, which is too bright for an initial value in my opinion. To solve this, I wrote two bash scripts to handle the brightness and ensure the output of multiples of ten.

To increase screen brightness:


#!/bin/bash
#Created by Brian Winkler

#This script is free to use and modify as your own

#Check out my blog at https://nuxview.blogspot.com/


STATUS="$(xbacklight -get)"
CHECK="${STATUS}"

if [[ $CHECK == 0.000000 ]]

then
 xbacklight -inc 1
 pkill -RTMIN+1 i3blocks

else
 xbacklight -inc 10
 pkill -RTMIN+1 i3blocks
fi


This script checks if the brightness value is at its lowest and if it is, increases the brightness by a value of 1. Otherwise, it increases the brightness by a value of 10.


To decrease screen brightness:


#!/bin/bash
#Created by Brian Winkler
#This script is free to use and modify as your own
#Check out my blog at https://nuxview.blogspot.com/

STATUS="$(xbacklight -get)"
CHECK="${STATUS}"

if [[ $CHECK == 100.000000 ]]

then
 xbacklight -dec 9
 pkill -RTMIN+1 i3blocks

else
 xbacklight -dec 10
 pkill -RTMIN+1 i3blocks
fi

This script checks if the brightness is all the way up and if it is, decreases it by a value of 9. Otherwise, it decreases the brightness by a value of 10.


For both of these scripts, pkill -RTMIN+1 i3blocks makes it so I can set my interval to once in the brightness display command in i3blocks.conf and then whenever I change the brightness, it automatically reloads the brightness display.


So now my i3blocks brightness block is using only multiples of ten and allows for me to turn my brightness off and when I turn it on, it first sets the brightness to the lowest possible value.

I then made these scripts executable using chmod +x and copied them to /usr/local/bin/ and named them brightinc and brightdec respectively.


My new ~/.config/i3/config looks like this:


#Brightness controls
bindsym XF86MonBrightnessUp exec brightinc
bindsym XF86MonBrightnessDown exec brightdec


These scripts as also available on my i3blocks github.


If you have any questions or comments, please feel free to contact me or to comment here. I would love to hear from you!










No comments:

Post a Comment