How many of you have a monitor next to a window in which the sun shines in the morning, afternoon or evening? Even if the rays of the Sun do not dazzle and do not create glare on the screen surface, it will still create a little discomfort during sunset, at least for me.
How?
Everything is very simple. Towards evening, the sun is setting to a sunset and the light enters the room very brightly, sanctifying the space around my workplace is brighter than ever. But the closer the sun comes to the horizon, the duller its rays become and it is necessary to turn on artificial lighting. And at this very time, the difference in the illumination of the room is formed and against the background of the subdued illumination the 22-inch monitor begins to “cut” the eyes.
Decision
Although there are already ready-made programs, for example
f.lux or
Redshift , in which a gradual change in color temperature is realized, I nevertheless decided to give my attention to brightness. And since I am the proud owner of an HD3870 video card with the proprietary fglrx driver installed, I wrote three small shell scripts to automatically gradually change the screen brightness.
')
How?
Again, everything is very simple!
- Every day during sunset, gradually and evenly, for an hour, imperceptibly visible to the eye, we reduce the screen brightness to a level that is pleasing to my eyes.
- During each dawn, the second script is launched, which, on the contrary, restores the screen brightness to a convenient day job at the computer.
- And the third script is executed every time you start the computer and immediately restores the brightness to the standard mark.
"Evening" algorithm
- Determine the initial brightness.
- Determine the duration of the transition and divide the time by Δ brightness.
- Dim the screen gradually.
now=$((now-1))
aticonfig --set-dispattrib=tmds1,brightness:$now
- We are waiting for n / m seconds, where "n" is the dimming time, and "m" is Δ brightness.
- Repeat the 3rd and 4th paragraph until $ now becomes equal to the required blackout.
“Morning” algorithm
- Determine the initial brightness.
aticonfig --query-dispattrib=tmds1,brightness
- Determine the duration of the transition, find Δ brightness.
- We continue if Δ brightness 0, otherwise the required mark has already been reached.
- Add brightness.
now=$((now+1))
aticonfig --set-dispattrib=tmds1,brightness:$now
- We are waiting for n / m seconds, where "n" is the dimming time, and "m" is Δ brightness.
- Repeat the 4th and 5th paragraph until $ now becomes equal to the initial level of brightness.
"Boot" algorithm
- Immediately restore to the default level.
aticonfig --set-dispattrib=tmds1,brightness:0
“
Evening ”, “
Morning ” and “
Boot ” script, works without root rights.
Carefully read the comments at the very top, as you may have to guess with a different type of display!
Tricky question"
How to make it all work? Again, everything is elementary.
- We change the scheduler task list in the terminal.
~$ crontab -e
- We insert only two lines 1 . The first one is to run every day, for example, at 05:00 restore the brightness, and the second is to dim at 20:00 every day. Do not forget to change the path to the script!
0 5 * * * export DISPLAY=:0 && "/ /brightness_morning.sh"
0 20 * * * export DISPLAY=:0 && "/ /brightness_evening.sh"
- Restart cron.
~$ sudo /etc/init.d/cron restart
- Open the list of programs that run when Ubuntu starts
System → Preferences → Startup Applications
or in the terminal.
~$ gnome-session-properties
- Add a line to run 2 .
"/ /brightness_reboot.sh"
Voila! Everything is ready for long night coding. It remains to make coffee and snacks, for programming new bugs appear on an empty stomach.
It was and became
It only remains for me to write an algorithm for calculating the beginning and end of daylight depending on the date and location, but this is a completely different story. I hope someone else, besides me, will need these scripts. Take care of your health, especially eyesight. Good luck!
1 Be sure to specify
export DISPLAY=:0
to run from under the “X”. Works great in Ubuntu 9.10 Karmic Koala.
2 I didn’t manage to reset the brightness to zero through cron, because first X and drivers should be launched, and only then the script itself, but if someone could manage to achieve the same result in the same way, please add your comments in the comments option.