Thinkpad laptops (and laptops in general) have special actions mapped to certain keys, which can be accessed with "Fn" key. For example, "Fn+F4" will suspend the laptop to RAM. Of course that happens only in the pre-installed Windows 7. If you install linux you usually have to configure those keys to do the actions they're supposed to yourself. There are some keys that work out of the box, for example the "Fn+PgUp" will toggle the Thinklight, and also the screen brightness can be adjusted using the predefined keys ("Fn+Home" and "Fn+End"). In my old Thinkpad T60, the volume buttons were also working (probably hardwired), but in T410s this is not so.
Fortunately Awesome (also Openbox, and probably other WM-s and DE-s) will allow you to define global keys. In rc.lua (usually placed in ~/.config/awesome) you can define your own key codes and map some action to them. Here's an example:
awful.key({}, "XF86AudioPrev",function () awful.util.spawn("mocp -r") end)
What this does is it maps the key "XF86AudioPrev" to do the action "mocp -r". In Thinkpads "XF86AudioPrev" is mapped to "Fn+Arrow left". This is supposed to select previous song from some audioplayer. What it does in my system is it will select previous song in MOC.
To assign the actions to the keys you need to know the key names and of course some program to do the task (preferably something similar to the task that was configured under Windows). For the key names I used a program called xev that prints out different data it receives by events (key presses etc.) generated by X.
Here is a list of various configured keys in my system:
globalkeys = awful.util.table.join(
...
awful.key({}, "XF86AudioPrev",function () awful.util.spawn("mocp -r") end),
awful.key({"Control"}, "XF86AudioPrev",function () awful.util.spawn("mocp -k -10") end),
awful.key({}, "XF86AudioNext",function () awful.util.spawn("mocp -f") end),
awful.key({"Control"}, "XF86AudioNext",function () awful.util.spawn("mocp -k 10") end),
awful.key({}, "XF86AudioPlay",function () awful.util.spawn("mocp -G") end),
awful.key({"Control"}, "XF86AudioPlay" ,function () awful.util.spawn("mocp -p") end),
awful.key({"Control", "Mod1"}, "XF86AudioPlay",function () awful.util.spawn("mocp -S") end),
awful.key({}, "XF86AudioStop",function () awful.util.spawn("mocp -s") end),
awful.key({"Control"}, "XF86AudioStop",function () awful.util.spawn("mocp -x") end),
awful.key({}, "XF86AudioRaiseVolume",function () awful.util.spawn("amixer set Master unmute 2%+ > /dev/null") end),
awful.key({}, "XF86AudioLowerVolume",function () awful.util.spawn("amixer set Master unmute 2%- > /dev/null") end),
awful.key({}, "XF86ScreenSaver",function () awful.util.spawn("slock") end),
awful.key({}, "XF86AudioMute",function () awful.util.spawn("amixer set Master toggle > /dev/null") end),
...
)
So, for locking the screen I use slock, suspend works via pm-utils. Music is served through MOC server and since the audio functionality is provided by ALSA, all the volume actions are done through amixer. One thing to note with the volume buttons is that when the volume is muted, pressing the volume up or down button will unmute it and then increase or lower the volume. So for every time the volume raise or volume lower button is pressed you have to explicitly unmute the mixer for the keys to work as expected (of course you could make a script that checks if the volume is muted and only then unmute it).
Going to go ahead and add hibernation functionality now, see how it goes (on T60 it stopped working correctly after some use so I had to disable it).
Computers are so much fun!
ReplyDelete