Showing posts with label laptop. Show all posts
Showing posts with label laptop. Show all posts

Saturday, December 3, 2011

Reduce Linux laptop's backlight on boot up

I like Linux. Especially for being able to create graceful workarounds for the things we get accustomed in a real life.

Being a Linux-powered laptop owner I have always been annoyed by sharp backlight change when Linux boots up. I do not like when a backlight is set to the maximum one and there are no ways to affect these settings on. So I did a very funny trick.

System's backlight (aka "display's brightness") in Linux could be changed through the special /sys/class/backlight/acpi_video0/brightness file. When an integer is written Linux immediately changes laptop's backlight level. E.g. the following command:
# echo 10 > /sys/class/backlight/acpi_video0/brightness

will set display's brightness to 10 points.

The first steps of Linux boot up are made with initramfs scripts which are executed one by one. When system-required-specific modules are loaded laptop's backlight level dramatically raises up. So we can think about this point in time as a moment when the user is able to tell Linux not to do so; or at least set it explicitly to a preferred value. That moment in time in the terms of initrams-tools could be called "premount".
#!/bin/sh

### file: /etc/initramfs-tools/scripts/local-premount/backlight_level
### this file must have an executable bit.
###
### Author: Andrew Sichevoi
### Please feel free to send your bug reports to http://blog.thekondor.net

PREREQ=""
prereqs()
{
  echo "${PREREQ}"
}

case "${1}" in
  prereqs)
           exit 0;
           ;;
esac

. /scripts/functions

DEFAULT_BACKLIGHT_LEVEL=10
BACKLIGHT_LEVEL=
for arg in $(cat /proc/cmdline); do
  case ${arg} in
    backlight_level=*)
                       BACKLIGHT_LEVEL=${arg#backlight_level=}
                       ;;
  esac
done

if [ -z ${BACKLIGHT_LEVEL} ]; then
   log_warning_msg "Using default backlight level: '${DEFAULT_BACKLIGHT_LEVEL}'"
   BACKLIGHT_LEVEL=${DEFAULT_BACKLIGHT_LEVEL}
fi

echo ${BACKLIGHT_LEVEL} > /sys/class/backlight/acpi_video0/brightness

So here we go:
  1. Add the below-mentioned backlight_level script to /etc/initramfs-tools/scripts/local-premount directory, make it executable;
  2. Update initramfs using update-initramfs command (Linux distribution specific; at least that works for Debian and Ubuntu) to include the script to the initrd image;
  3. Set passing backlight_level=X (where X is a preferred backlight level) boot option in your's grub.cfg.
and reboot to see the changes in action.

The script just looks up backlight_level kernel boot option and writes (if any, or default one otherwise) this value to the brightness file for immediate laptop's brightness update.

Simple? I think yes. Does it work? Definitely. Perfect? Not at all: I believe that system's boot's up settings should not differ from main DE's ones: they should be configured through the single entry point not several ones. Anyway this scripts makes feel us that we able to control Linux as well as we have a new task to think about :). So stay tuned!

Thursday, June 23, 2011

actkbd package for Debian/Ubuntu

Recently I became an owner of Thinkpad X120E laptop produced by Lenovo. The computer was supplied with no pre-installed OS so I deployed (unexpected decision, huh!) Debian GNU/Linux there. This time I decided not to use desktop "ready-to-use-out-of-the-box" environments like Gnome or KDE and give a try to build a DE I want from bricks.

The one of the tasks I have faced with is how to make ThinkPad X120E hotkeys work in Debian GNU/Linux in a uniform way - to have a single keybindings entry point; which should work in VT w/o X.org also. Some of the keys (like VolUp, VolDown, Suspend etc) can be successfully handled through acpid daemon but the rest ones (say enable/disable microphone or switch touchpad/trackpoint) can be with xbindkeys (or similar) application only.

After a short research I found an amazing application called actkbd -- a keyboard shortcut X.org independent daemon. Thanks for being dependent on evdev Linux interface actkbd allows to handle ACPI events as well. But unfortunately there have been no ready-to-use Debian (Ubuntu) package available on the Internet (*).

(*) Of course I could install it using "configure && make && make install" way but I did not want to transform my Debian GNU/Linux installation to Slackware or kind of :).

Hence I made actkbd Debian/Ubuntu package by myself. So you can download here already built actkbd package for Debian Wheezy/i386 or build it by yourself (using dpkg-buildpackage). I am not so experienced in applications debianizing but seems it works well. Please feel free to use it or even to push to Debian/Ubuntu repositories.
Sources of debian/* files are to be shared soon through my git repository.

Thursday, May 6, 2010

My new laptop: Lenovo Thinkpad

Today I bought my first Thinkpad -- Thinkpad T410. I know that since 'Thinkpad' trademark was bought out from IBM by Lenovo many people believe that they lost their legendary advantages. I think so also. A bit :). Anyway I still like them and their spirit.

Buying Thinkpads in Russia has its own unique peculiarities.
First one: you have to do your best to find a laptop w/ tech specs you like/need. You are able to find only 3-5 models of each series. But sometimes these models may not satisfy you and you have to choose from what they offer not from you like.
Second: there is no shipping directly from Lenovo using post/DHL. I believe that Russian post service is the worst in the World. And Lenovo (AFAIK) doesn't ship to Russia; USA/Europe only.
Third and not the coolest one: you should play kinda 'roulette' game; if you buy your laptop at an Internet shop and have not unboxed it on receiving, it's hard to return it back or to have a replace. If I didn't check today Thinkpad's keyboard I would get the problem called 'flex keyboard' (check out YouTube for it to get the idea of what it is).

Here is some positive. The one of shop assistants asked me what I'm gonna to install on my new laptop. When I told him that my choice is Linux, he became more energetic and the rest of the time of shopping we periodically were discussing Linux and Open Source. He was a newbie (2 years experience of playing around with Linux) but he is already fan of Open Solaris -- believes that it is a future of OS`s, fan of upcoming `btrfs' file system and XFCE as DE :). Believe me -- it is a rarity (at least it was before) for Russian shop assistants :).