Thursday, February 26, 2015

xcalib: Say No to Eye Strain - Exclusively for You on Linux!

Eyes getting tired after staring at the computer screen for a couple of hours? Don't take it lightly; eye strain, if neglected, can eventually lead to catastrophic conditions like glucoma and even total blindness. And it's quite common around members of the IT sector, who have no other option than staring at their computer screens for long periods each day.

Eye strain often traces back to computer screens that are too bright (although lack of brightness can also cause problems at times). If you are a frequent computer user, you would have noticed that reading text on white or other light-coloured backgrounds over prolonged times can lead to eye strain quite quickly.

As a result, many applications now provide themes and configurations to ensure minimum eye strain. Ubuntu Linux, for example, offers a (PDF) Document Viewer featuring an 'Inverted Colors' option, while IDEs like NetBeans and IntelliJ IDEA have specialized 'dark themes' that provide similar colour configurations. Even the default text editor, gedit, can be configured to display light-coloured text on a black background.

However, if you are frequently switching between the 'light' and 'dark' modes, you will soon realize how painful it is to configure each application individually during the transition process. Besides, there's no guarantee that every arbitrary application would support colour inversion, so you may very well end up in situations where you are stuck with black text on white on one application and the eye-friendly inverse on all the others.

On Ubuntu Linux, as with anything else, there's a workaround: xcalib.

Installation takes the usual, friendly path: sudo apt-get install xcalib

This utility can be used to completely invert screen colours with a single command, so you never have to mess with individual configurations again:

xcalib -i -a

Repeating the same command will bring the screen back to normal.

The catch, however, is that it will also swap the other screen colours (red becomes cyan, blue becomes yellow, and so on). It takes some time for the brain to get used to this strangeness, but after that it just becomes normal.

xcalib only seems to trigger the colour swap on the display; if you take a screenshot with xcalib executed, you will notice that it would still be a 'natural colour' screenshot.

Still, it may be required to configure some colour schemes, such as that on the terminal, so that whether you are in the inverted mode or not, you would be seeing a 'natural' (light text on dark background) terminal.

Here are two shell scripts, zkreen and swap, that I use for inverting my screen and the terminal colours together so that I always see a green-text-on-black terminal but everything else gets swapped (please note that you need gconftool-2 installed, for the swap operation to work).


xcalib -i -a


xcalib -i -a
fore=`gconftool-2 --get "/apps/gnome-terminal/profiles/Profile0/foreground_color"`;
if [ $fore = "#0000FFFF0000" ]; then
	gconftool-2 --set "/apps/gnome-terminal/profiles/Profile0/background_color" --type string "#FFFFFFFFFFFF";
	gconftool-2 --set "/apps/gnome-terminal/profiles/Profile0/foreground_color" --type string "#FFFF0000FFFF";
	gconftool-2 --set "/apps/gnome-terminal/profiles/Profile0/background_color" --type string "#000000000000";
	gconftool-2 --set "/apps/gnome-terminal/profiles/Profile0/foreground_color" --type string "#0000FFFF0000";

(Make sure that you set executable permissions on both scripts, using chmod +x.)

I leave other configurations untouched so that I can switch back to the dark-on-light scheme easily when I get bored with light-on-dark, or have some special requirement such as viewing a colour image.

On both Ubuntu systems that I am using, the effect of xcalib seems to wear off suddenly during certain operations (such as pressing Ctrl+C or Ctrl+V, on the terminal or in other applications). The issue is intermittent and I believe it is a bug (not a serious one, though). The second script (swap) is for such situations, whose job is to solely swap terminal colours when such a thing happens (otherwise the terminal will retain a funny-looking pink-text-on-pink scheme, which we had actually set during the xcalib swap so as to get a natural-looking terminal under colour inversion).

Using dconf and other related utility commands, you will be able to customize the script to trigger colour changes on other selected applications such as gedit, and maybe even get rid of xcalib and rely solely on application configurations for colour inversions.

No comments:

Post a Comment