ASUS M6N Notebook

Foreword

From the times when I started my adventure in the world of Linux I remember that getting full support for the features offered by mobile computers was rather difficult to achieve. Today those kind of problems are over. We have direct support for both suspend and hibernate functions a long side with vendor specific ACPI drivers available in Kernel. Most of modern binary distributions work on mobile devices without any problems giving users ability to fully control advanced ACPI functions. There are also available specific distributions for mobile computers like Ubuntu Netbook Edition or created by Intel and Nokia MeeGo platform. Today Linux sets new trends in mobile computers market.

I have a quite old Asus M6N notebook which I'm using mostly for browsing Internet, connecting to remote servers and running presentations. I use my notebook only If I'm away from my main computer. It's not a speed daemon especially for todays standards but for those kind of tasks my notebook is perfect and I don't need a better one. I could use any Linux distribution and they would work well but fortunately I'm Gentoo Linux user and thanks to this I'm able to make my notebook work perfect. Here you can find my configuration for mobile computer, including kernel, advanced ACPI, multimedia keys and KDE desktop environment configurations that let me use my notebook the way I want to. Some of the provided here information are specific for both my distribution and my notebook but some of them should be applicable not only for any distribution but with small changes also for any notebook. I hope you will find some of provided here information useful. I will start with kernel configuration.

TuxOnIce Kernel Configuration

Default Linux kernel for my distribution has the same support for suspend and hibernation that most of Linux distribution has. It's working well but it can be done better. This better way is kernel patchset called TuxOnIce. It gives the user additional features like ability to cancel hibernation or image restoration by pressing escape, nice user interface, fast multithreaded compression support and many others. To use TuxOnIce you have to patch your distribution kernel, but in Gentoo we already have a kernel with TuxOnIce patchset available in portage tree. So for Gentoo Linux all you have to do is to run this command in terminal:

USE="symlink" emerge -av sys-kernel/tuxonice-source

To use nice TuxOnIce GUI interface I additionally installed tuxonice-userui package by running following command in terminal:

USE="fbsplash" emerge -av sys-apps/tuxonice-userui

To configure my new kernel I had to enter kernel catalog and start menuconfig by running following commands in terminal:

cd /usr/src/linux
make menuconfig

Next I had to mark all kernel options needed to run TuxOnIce suspend and hibernate functions. Below you will find list of those options.

Linux Kernel Configuration: Enable TuxOnIce features
Power management and  ACPI options  --->
  [*] Suspend to RAM and standby
  [*] Hibernation (aka 'suspend to disk')
  (/dev/sda8) Default resume partition
  <*>   Enhanced Hibernation (TuxOnIce)  --->
          *** Image Storage (you need at least one allocator)
    < >   File Allocator
    <*>   Swap Allocator
          *** General Options
    <*>   Compression support
    <*>   Userspace User Interface support
    (/sbin/tuxoniceui_fbspalsh) Default userui program location
    [ ]   Allow Keep Image Mode
    [*]   Replace swsusp by default
    [ ]   Wait for initrd/ramfs to run, by default
    (25)  Default waiting time for emergency boot messages
    (2000) Default extra pages allowance
    [*]   Checksum pageset2

-*- Cryptographic API  --->
  <*>   LZO compression algorithm

As you can see I'm using both suspend to Ram and hibernate functions. Very important thing is to provide correct swap partition location, my swap is located on /dev/sda8. In TuxOnIce configuration I'm not using file allocator, I will use swap hibernation only. I'm also providing a fbsplash user interface location to have graphical information during suspend and resume operation. This will require additional configuration of my graphical boot up splash, more information you will find below. Last important thing is compression which will lower suspend image capacity. It's highly important to build LZO compression algorithm directly into kernel not as a module.

After marking all necessary kernel modules I'm ready to recompile, install and use new kernel. I usually do it by running this commands in terminal:

cd /usr/src/linux
make && make modules_install install

Now I can take care of my system splash image to make it compatible with TuxOnIce suspend GUI. Normally I would create graphical bootup splash using natural_gentoo theme by running following commands in terminal:

emerge -av splashutils splash-themes-gentoo
splash_geninitramfs --verbose --res 1024x768 --generate /boot/fbsplash-natural_gentoo-1024x768 natural_gentoo

To make my splash use installed earlier TuxOnIce GUI I have to decompressed it and copy tuxoneice_fbsplash into it. To do it I need to run following commands in terminal:

mkdir ~/initrd.d
cp /boot/fbsplash-natural_gentoo-1024x768 ~/initrd.d/
cd ~/initrd.d
gunzip -c fbsplash-natural_gentoo-1024x768 | cpio -idm --quiet -H newc
rm fbsplash-natural_gentoo-1024x768
cp /sbin/tuxoniceui_fbsplash sbin/
find . | cpio --quiet --dereference -o -H newc | gzip -9 > /boot/fbsplash-natural_gentoo-1024x768

Now I have TuxOnIce graphical notification during both hibernation and system resume.

The suspend to Ram and hibernation should work without any problem with this configuration in graphical desktop environment. I'm using KDE 4.x and KDE is using pm-utils and hal to suspend and hibernate system. This was working for me but I thought I could make it work better. To do it I use hibernate-script which has some advantages over core pm-utils implementation. Some of them are: easy to use complex plug-in based configuration with ability to suspend virtual machines before core system suspend, ability to change grub splash for suspended system, ability to unmount network file system before suspend, ability to restart chosen system services after resume and ability to change instant messengers status on suspend. To use hibernate script I have to install it. In Gentoo Linux we would do it like this:

emerge -av sys-power/hibernate-script

Main problem for me with using hibernate script is that there is no way (except changing the source code) to force KDE desktop environment to use hibernate-script instead of pm-utils and hal. But there is no need to change KDE behavior because you can force pm-utils to make a special hal script which will use hibernate-script. This solution is taken from Gentoo Linux Wiki pm-utils HowTo. Below you can find a full script which should be saved as /etc/pm/sleep.d/01HibernateScripts.

View the full /etc/pm/sleep.d/01HibernateScripts file
  1. #!/bin/bash
  2.  
  3. HAL_HIBERNATE="/usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux"
  4. HAL_SUSPEND="/usr/lib/hal/scripts/linux/hal-system-power-suspend-linux"
  5.  
  6. case $1 in
  7. hibernate)
  8. /bin/mv ${HAL_HIBERNATE} ${HAL_HIBERNATE}.original
  9. /bin/echo "#!/bin/bash" >> ${HAL_HIBERNATE}
  10. /bin/echo "/usr/sbin/hibernate" >> ${HAL_HIBERNATE}
  11. /bin/echo "exit \$?" >> ${HAL_HIBERNATE}
  12. /bin/chmod +x ${HAL_HIBERNATE}
  13. /usr/bin/killall pm-hibernate
  14. /usr/bin/chvt 7
  15. /usr/sbin/hibernate
  16. ;;
  17. suspend)
  18. /bin/mv ${HAL_SUSPEND} ${HAL_SUSPEND}.original
  19. /bin/echo "#!/bin/bash" >> ${HAL_SUSPEND}
  20. /bin/echo "/usr/sbin/hibernate-ram" >> ${HAL_SUSPEND}
  21. /bin/echo "exit \$?" >> ${HAL_SUSPEND}
  22. /bin/chmod +x ${HAL_SUSPEND}
  23. /usr/bin/killall pm-suspend
  24. /usr/bin/chvt 7
  25. /usr/sbin/hibernate-ram
  26. ;;
  27. esac

As you can see this file is creating special hal script which will use hibernate script commands whenever the hibernate and suspend actions are taken by user. The reason for such weird behavior is that during the system update the self created hal scripts can be overwritten. When you will create above script the hal scripts using hibernate-script will always be available in system. Now I can use hibernate script. To make full use of it I should make sure that a system service provided with the hibernate-script will be run on every computer boot. This service is called hibernate-cleanup. To make it run on every system boot I should run following command in terminal:

rc-update add hibernate-cleanup boot

The last thing to make my suspend and resume work as I would like it, is to configure hibernate-script itself. To do it I had to edit the /etc/hibernate/common.conf file. Below you can find my common.conf configuration file.

View the full /etc/hibernate/common.conf file
  1. # Configuration options common for suspending to disk or RAM.
  2. # Options are not case sensitive.
  3. #
  4. # See hibernate.conf(5) for help on the configuration items.
  5.  
  6. ##############################################################################
  7. ### Some global settings
  8. ##############################################################################
  9.  
  10. Verbosity 1
  11. LogFile /var/log/hibernate.log
  12. LogVerbosity 4
  13. LogTimestamp yes
  14. # AlwaysForce yes
  15. AlwaysKill yes
  16. # HibernateVT 15
  17. Distribution gentoo
  18. # XDisplay :0
  19.  
  20. ##############################################################################
  21. ### Scriptlets
  22. ### Scriptlets provide support for doing all sorts of things before and after
  23. ### suspending. The defaults settings here should work for most people, but
  24. ### you may wish to edit these to taste. Consult "hibernate -h" for help on
  25. ### the configuration settings.
  26. ##############################################################################
  27.  
  28. ### bootsplash
  29. ## If you use bootsplash, also enabling SwitchToTextMode is recommended if
  30. ## you use X, otherwise you may end up with a garbled X display.
  31. #Bootsplash on
  32. #BootsplashConfig /etc/splash/tuxonice/1024x768.cfg
  33.  
  34. ### clock
  35. SaveClock restore-only
  36. #DirectIsa
  37.  
  38. ### devices
  39. # IncompatibleDevices /dev/dsp /dev/video*
  40.  
  41. IncompatibleDevices /dev/video*
  42.  
  43. ### diskcache
  44. DisableWriteCacheOn /dev/sda
  45.  
  46. ### fbsplash (enable SwitchToTextMode if you use this)
  47. FBSplash on
  48. FBSplashTheme natural_gentoo
  49.  
  50. ### filesystems
  51. # Unmount /nfsshare /windows /mnt/sambaserver
  52. UnmountFSTypes smbfs nfs vfs
  53. # UnmountGraceTime 1
  54. # Mount /windows
  55.  
  56. ### grub
  57. ChangeGrubMenu yes
  58. GrubMenuFile /boot/grub/grub.conf
  59. AlternateGrubMenuFile /boot/grub/menu-suspended.lst
  60. BackupGrubMenuFile /boot/grub/grub.conf.bak
  61.  
  62. # see http://bugs.debian.org/317479
  63. # RemountXFSBoot yes
  64.  
  65. ### hardware_tweaks
  66. # IbmAcpi yes
  67. RadeonTool yes
  68. # Runi915resolution yes
  69. FullSpeedCPU yes
  70.  
  71. ### lilo
  72. # EnsureLILOResumes yes
  73.  
  74. ### lock (generally you only want one of the following options)
  75. ## For console you need vlock available.
  76. ## For x you need xscreensaver-command-command available.
  77. ## For gnome you need gnome-screensaver-command available.
  78. ## For kde you need dcop, kscreensaver available.
  79. ## For XAuto you need xautolock available.
  80. ## For Xtr you need xtrlock available.
  81. ## For Freedesktop (for example KDE4) you need dbus-send available
  82. # LockConsoleAs root
  83. # LockXScreenSaver yes
  84. # LockGnomeScreenSaver yes
  85. # LockFreedesktop
  86. # LockKDE yes
  87. # LockXLock yes
  88. # LockXAutoLock yes
  89. # LockXtrLock yes
  90.  
  91. ### misclaunch
  92. OnSuspend 20 echo "Idę Spać Co się dziwisz czasami trzeba :D!"
  93. OnResume 20 echo "Gotów do roboty. No dalej co robimy!"
  94.  
  95. ### modules
  96. UnloadModules sd_ricoh
  97. # UnloadAllModules yes
  98. UnloadBlacklistedModules yes
  99. LoadModules auto
  100. # LoadModulesFromFile /etc/modules
  101.  
  102. ### modules-gentoo
  103. # GentooModulesAutoload yes
  104.  
  105. ### network
  106. DownInterfaces
  107. UpInterfaces auto
  108.  
  109. ### networkmanager
  110. EnableNMReconnect yes
  111.  
  112. ### pause_audio
  113. MuteAudio no
  114. PauseAudio yes
  115.  
  116. ### pcmcia
  117. EjectCards yes
  118.  
  119. ### programs
  120. #IncompatiblePrograms
  121.  
  122. ### services
  123. RestartServices hsf samba nfs nfsmount numlock lm_sensors sensord smartd hddtemp vixie-cron avahi-daemon irda ntpd distccd moblock sshd ulogd iptables laptop_mode acpi
  124. # StopServices alsasound
  125. # StartServices aumix
  126.  
  127. ### vbetool
  128. #EnableVbetool yes
  129. #RestoreVbeStateFrom /var/lib/vbetool/vbestate
  130. #VbetoolPost yes
  131. #RestoreVCSAData yes
  132.  
  133. ### xhacks
  134. SwitchToTextMode yes
  135. # UseDummyXServer yes
  136. # DummyXServerConfig xorg-dummy.conf
  137.  
  138. ### xstatus
  139. ## This can be set to gnome, kde or x:
  140. ## For gnome you need zenity available.
  141. ## For kde you need dcop, kstart, kdialog available.
  142. ## For x you need to have xosd OR xmessage available.
  143. # XStatus x
  144. # XmessageDisable yes
  145. # XSuspendText Preparing to suspend...
  146. # XResumeText Resuming from suspend...
  147. ## When using XStatus x, and you have xosd installed:
  148. # XosdSettings --font '-misc-fixed-medium-r-semicondensed--*-120-*-*-c-*-*-*' --colour=Green --shadow 1 --pos bottom --align center --offset 50
  149.  
  150. ### xbacklight
  151. # BackLight yes
  152.  
  153. ### gaim
  154. ## You need to have dbus, gaim_remote available.
  155. # LogoutGaim yes
  156. # GaimRestoreStatus yes
  157. # GaimLogoutMessage Hibernating
  158. # GaimLoginMessage Back from hibernation
  159.  
  160. ### pidgin
  161. LogoutPidgin yes
  162. PidginRestoreStatus yes
  163. PidginLogoutMessage Hibernating - bye!
  164. # PidginLoginMessage I'm back!
  165.  
  166. ### SSH and PGP keys
  167. # AgentsClearGPG yes
  168. # AgentsClearSSH yes
  169.  
  170. ### Virtualbox
  171. SuspendVirtualbox yes

These file is quite easy to read. On the top you will find logging configuration, lower you can see list of network file systems that need to be unmounted before suspend. Then you can see grub menu configuration, I wil provide grub menu information later. The important thing is also list of kernel modules that should be unloaded. I'm unloading module for my SD card reader. Litter lower you can see list of system services that should be restarted after system resume. As you can see I'm restarting mostly network services to make sure they will work all right. I'm also locking my X environment before suspend this way after resume I will be forced to provide password to get back to normal work. Another important thing is making use of utility named radeontool. This is special tool for power management of my graphics card. With proper graphics card configuration this tool should be installed as dependency to pm-utils. Of course you can always install this tool manually by running following command in terminal:

emerge -av app-laptop/radeontool

Last thing I need to do is to create grub configuration files. First file /boot/grub/grub.conf will be responsible for normal system start. Below you can see my grub.conf file.

View the full /boot/grub/grub.conf file
  1. default 0
  2. timeout 10
  3.  
  4. splashimage=(hd0,0)/boot/grub/gentoo.xpm.gz
  5.  
  6. title Gentoo Linux TuxOnIce 2.6.32-r9 (Main)
  7. root(hd0,0)
  8. kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 resume=swap:/dev/sda8 video=uvesafb:1024x768-24@60,mtrr:2,ywrap splash=kdgraphics,silent,fadein,theme:natural-gentoo quiet CONSOLE=/dev/tty1 fbcon=scrollback:256K acpi=on lapic=yes
  9. initrd (hd0,0)/boot/fbsplash-natural_gentoo-1024x768
  10.  
  11. title Gentoo Linux TuxOnIce 2.6.32-r9 (Rescue)
  12. kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 init=/bin/bb
  13.  
  14. title Memtest86Plus
  15. root(hd0,0)
  16. kernel --type=netbsd /boot/memtest86plus/memtest

You can see one important information for suspend and resume, a kernel parameter resume pointing to my swap partition location. This parameter is required only if I would not provide proper swap partition information during my kernel configuration. Second grub configuration file is /boot/grub/menu-suspended.lst. This file will be responsible for system start after hibernation. The hibernate script will take care of replacing the grub files during hibernation process. Below you can see my menu-suspended.lst file.

View the full /boot/grub/menu-suspended.lst
  1. default 0
  2. timeout 10
  3.  
  4. splashimage=(hd0,0)/boot/grub/gentoo.xpm.gz
  5.  
  6. title Gentoo Linux TuxOnIce 2.6.32-r9 (RESUME SUSPENDED SYSTEM)
  7. root(hd0,0)
  8. kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 resume=swap:/dev/sda8 video=uvesafb:1024x768-24@60,mtrr:2,ywrap splash=kdgraphics,silent,fadein,theme:natural-gentoo quiet CONSOLE=/dev/tty1 fbcon=scrollback:256K acpi=on lapic=yes
  9. initrd (hd0,0)/boot/fbsplash-natural_gentoo-1024x768
  10.  
  11. title Gentoo Linux TuxOnIce 2.6.32-r9 (START UNSUSPENDED SYSTEM)
  12. root(hd0,0)
  13. kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 resume=swap:/dev/sda8 noresume video=uvesafb:1024x768-24@60,mtrr:2,ywrap splash=kdgraphics,silent,fadein,theme:natural-gentoo quiet CONSOLE=/dev/tty1 fbcon=scrollback:256K acpi=on lapic=yes
  14. initrd (hd0,0)/boot/fbsplash-natural_gentoo-1024x768
  15.  
  16. title Gentoo Linux TuxOnIce 2.6.32-r9 (Rescue)
  17. kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 init=/bin/bb
  18.  
  19. title Memtest86Plus
  20. root(hd0,0)
  21. kernel --type=netbsd /boot/memtest86plus/memtest

As you can see there are two kernel configurations on this file. First one which should boot up and load suspended system from a swap partition and second one which has special kernel parameter noresume which will start up system in a normal way. The third grub configuration file /boot/grub/grub.conf.bak is just a copy of the first file. This is all I did to make my suspend and hibernate work as I want to. Next thing is ACPI configuration for my notebook.

ACPI configuration

ACPI configuration is two-stage process. First stage is kernel configuration, second one is installation and configuration of tools which will make use of features available in kernel. Below you will find ACPI kernel configuration for my notebook.

Linux Kernel Configuration: Enable ACPI features
Power management and  ACPI options  --->
  [*] Power Management support 
  [*] Run-time PM core functionality 
  [*] ACPI (Advanced Configuration and Power Interface) Support  --->
    [*]   Deprecated /proc/acpi files
    [*]   Deprecated power /proc/acpi directories
    < >   ACPI 4.0 power meter
    [*]   Future power /sys interface
    [*]   Deprecated /proc/acpi/event support
    <M>   AC Adapter
    <M>   Battery
    <M>   Button
    <M>   Fan
    -*-   Dock
    <*>   Processor
    < >    Processor Aggregator
    (0)   Disable ACPI for systems before Jan 1st this year 
    <M>   Smart Battery System
      CPU Frequency scaling  --->
    [*] CPU Frequency scaling
    [*]   Enable CPUfreq debugging
    <M>   CPU frequency translation statistics
    [*]     CPU frequency translation statistics details
           Default CPUFreq governor (userspace)  --->
    <*>   'performance' governor
    <*>   'powersave' governor
    <*>   'userspace' governor for userspace frequency scaling
    <*>   'ondemand' cpufreq policy governor
    <*>   'conservative' cpufreq governor
    <M>   ACPI Processor P-States driver
 -*- CPU idle PM support
Device Drivers  --->
 [*] X86 Platform Specific Device Drivers  --->
    <M>   Asus Laptop Extras
    < >   ASUS/Medion Laptop Extras (DEPRECATED)

As you can see I marked most of available in kernel ACPI features including all possible CPU frequency scaling governors. Very important thing is marking direct support for ACPI features typical for a notebook vendor. For Asus notebooks it's highly important not to use old deprecated kernel module even if you have as old notebook as mine. The new support will work just fine. Now we can install some programs to use advanced capabilities of mobile computer.

If you already installed system with graphical desktop environment, you most likely has all needed software. For Gentoo Linux system is important to add two USE flags that affect advanced power management to /etc/make.conf file. Those flags are: acpi and laptop. After this you should make sure all packages using those tools will be rebuild. To do it in Gentoo Linux system we need to run following command in terminal:

emerge --deep --newuse --update world

This should end up in installing most important package for power management functions, which is pm-utils. This package should be installed as dependency to hal hardware abstraction layer package or as dependency to desktop environment power management utility. This packages can be also installed manually by running following commands in terminal:

emerge -av sys-power/pm-utils

There are also another power management tools you may want to have in your system. First one is acpid daemon for advanced power management, second is laptop-mode-tools third is cpufrequtils. You can install all those tools by running following command in terminal:

emerge -av sys-power/acpid app-laptop/laptop-mode-tools sys-power/cpufrequtils

After installing all those tools you also need to add its system services to default run level. To do it in Gentoo Linux you can run following commands in terminal:

rc-update add acpid default
rc-update add laptop-mode-tools default
rc-update add cpufrequtils default

Today most of the power management tasks are executed by graphical desktop environment power management utility. KDE the desktop environment I use have really good tool called PowerDevil. I added all those services to default run level because I prefer to have power management support even if I'm not logged to the graphical environment. One of those tools require additional configuration. For cpufrequtils you need to provide a CPU governor that should be setup on start and stop of the system service. This configuration should go to /etc/conf.d/cpufrequtils. Below you can find my /etc/conf.d/cpufrequtils file.

View the full /etc/conf.d/cpufrequtils file
  1. # /etc/conf.d/cpufrequtils: config file for /etc/init.d/cpufrequtils
  2.  
  3. # Options when starting cpufreq (given to the `cpufreq-set` program)
  4. START_OPTS="--governor ondemand"
  5.  
  6. # Options when stopping cpufreq (given to the `cpufreq-set` program)
  7. STOP_OPTS="--governor performance"

This way I have dynamic CPU frequency scaling before logging into graphical desktop environment. Now I have all tools I need the last thing to do is to setup my multimedia keys.

Multimedia Keys Configuration

Setting up multimedia keys in Linux is much easier today that it was before. Thanks to support build directly into the hal, multimedia keys for most of the notebooks are recognized as normal keys and they can be configured by any key setup utility. Earlier the setup wasn't so hard but it required a little more work to create special acpi events scripts which were performing defined actions when keys were pressed. Unfortunately not all of my notebook keys could be configured the new way. Sadly one of them wasn't recognized and another one was acting not the way I would like it. Thats why my configuration is using both approaches the new one for those buttons that were corectly recognized and old one for 2 buttons that wasn't recognized. Below you will find list of my multimedia keys and the actions I would like them to perform.

List of my keys:
  • Sleep button - Suspend system to ram - this button was working in KDE without the need of additional configuration.
  • Wireless button (2 buttons) - Switch off and on wireless network interface.
  • Brightness Up - This button has hardware support. Brightness up function is working even without operating system loaded.
  • Brightness Down - This button has hardware support. Brightness down function is working even without operating system loaded.
  • LCD button - This button has hardware support toggle between LCD on and off function is working even without operating system loaded.
  • LCD - CRT button - Toggle between dual screen setups.
  • Mute Sound button - Mute sound mixer - this button was working in KDE without the need of additional configuration.
  • Volume Up button - Volume up - this button was working in KDE without the need of additional configuration.
  • Volume Down button - Volume down - this button was working in KDE without the need of additional configuration.
  • Mail button - lunch Kmail mail client.
  • WWW button - lunch Chromium web browser.
  • Touchpad button - Switch on and off the touchpad - this button wasn't recognized as normal key.
  • Performance button - Toggle between available performance profiles - this button was recognized as screen saver button.
  • Play | Pause button - Toggle between play and pause in Amarok player.
  • Next track button - Next track in Amarok player.
  • Previous track button - Previous track in Amarok player.
  • Stop button - Stop playback in Amarok player.
  • Lunch media button - Start Amarok media player.

As you can see some of my notebook buttons were working without the need of additional configuration. Default configuration of KDE desktop environment assumes that those buttons will be available in system. For other correctly recognized buttons I used buttons settings utility provided by KDE. For multimedia buttons: Play | Pause, Next track, Previous Track and Stop buttons I used Global keyboard Shortcuts settings for Amarok player. All I need to do was to choose Amarok action matching my key and press my multimedia key to bound it to this function. 30 seconds of work. For Mail, WWW and Media Start buttons I used Keyboard Actions settings utility. I created three new Global Shortcuts for Command/URL actions first one command /usr/bin/chromium bound to WWW button, second /usr/bin/kmail bound to Email key and last one /usr/bin/amarok bound to Media Start button. This way I'm able to lunch my Internet browser, mail client and favorite multimedia player using my notebook buttons. This was the easy part. I must admit I had more problems with setting up wireless and performance buttons. The main problem was that I couldn't find simple system or dbus commands which could help simply achieve task I would like to bound to those buttons. But where is a will there is a way. For wireless button I found a great script created by Poul Sladen for Ubuntu acpi-support package. I used his functions for checking wireless device state and toggling wireless devices on and off. I used this functions a little different that original acpi-support package was making use of it. I created 3 scripts. First one I called wireless-toggle.sh. Below you can see this script.

View the full wireless-toggle.sh file
  1. #Function to toggle wireless interfaces originaly created by Paul Sladen for Ubuntu acpi-support package
  2. for DEVICE in /sys/class/net/* ; do
  3. if [ -d $DEVICE/wireless ] ; then
  4. # $DEVICE is a wireless device.
  5.  
  6. FOUND=
  7. # Yes, that's right... the new interface reverses the truth values.
  8. ON=1
  9. OFF=0
  10. for CONTROL in $DEVICE/device/rfkill/rfkill*/state; do
  11. if [ -w "$CONTROL" ]; then
  12. FOUND=1
  13.  
  14. if [ "$(cat "$CONTROL")" = "$ON" ] ; then
  15. # It's powered on. Switch it off.
  16. echo -n "$OFF" > "$CONTROL"
  17. else
  18. # It's powered off. Switch it on.
  19. echo -n "$ON" > "$CONTROL"
  20. fi
  21. fi
  22. done
  23. # it might be safe to assume that a device only supports one
  24. # interface at a time; but just in case, we short-circuit
  25. # here to avoid toggling the power twice
  26. if [ -n "$FOUND" ]; then
  27. continue
  28. fi
  29.  
  30. ON=0
  31. OFF=1 # 1 for rf_kill, 2 for power/state
  32. for CONTROL in $DEVICE/device/rf_kill $DEVICE/device/power/state ; do
  33. if [ -w $CONTROL ] ; then
  34. # We have a way of controlling the device, lets try
  35. if [ "`cat $CONTROL`" = 0 ] ; then
  36. # It's powered on. Switch it off.
  37. if echo -n $OFF > $CONTROL ; then
  38. break
  39. else
  40. OFF=2 # for power/state, second time around
  41. fi
  42. else
  43. # It's powered off. Switch it on.
  44. if echo -n $ON > $CONTROL ; then
  45. break
  46. fi
  47. fi
  48. fi
  49. done
  50. fi
  51. done

This script is using Poul Sladen function for toggling on and off all wireless devices in the system. Important thing is to remember that this script need to be run with higher system privileges. Normal user want be able to use it. A long side with toggling on and off wireless devices the user should be also informed about the current state of wireless devices by system led placed on the front side of the notebook. To do it I created the second script called wireless-led.sh. Below you can see this script.

View the full wireless-led.sh file
  1. #/bin/sh
  2.  
  3. echo $1 > /sys/devices/platform/asus_laptop/wlan

As you can see this script is very basic it just passes the first script parameter to system wireless led device. To light on the led I need to run this script like this: ./wireless-led.sh 1. To light off the led I need to run this script like this: ./wireless-led.sh 0. This script also needs a higher system privileges. I saved both scripts in /usr/local/bin catalog. To make both mentioned above scripts available to normal user I used sudo utility. In Gentoo Linux you can install sudo by running following command in terminal.

emerge  -av app-admin/sudo

With sudo installed in system all I needed to do is run visudo utility and create belows configuration to let anyone logged on my notebook use wireless scripts with higher privileges without the need of providing password.

ALL notebook = NOPASSWD: /usr/local/bin/wireless-led.sh
ALL notebook = NOPASSWD: /usr/local/bin/wireless-toggle.sh

Last thing I did to make my wireless devices manageable by notebook buttons is providing the script which will use mentioned above scripts to toggle wireless state and notebook led. I called this script wireless.sh and saved it in /usr/local/bin catalog. Below you can see wireless.sh script.

View the full wireless.sh file
  1. #!/bin/sh
  2. #Function to check status originaly created by Paul Sladen for Ubuntu acpi-support package
  3. isAnyWirelessPoweredOn()
  4. {
  5. for DEVICE in /sys/class/net/* ; do
  6. if [ -d $DEVICE/wireless ]; then
  7. # Hurray for stable interfaces... now the rfkill is scarcely
  8. # associated with the network device at all (!)
  9. for RFKILL in $DEVICE/device/rfkill/rfkill*/state; do
  10. if [ -r "$RFKILL" ] && [ "$(cat "$RFKILL")" -eq 1 ]
  11. then
  12. return 0
  13. fi
  14. done
  15. # if any of the wireless devices are turned on then return success
  16. if [ -r $DEVICE/device/power/state ] && [ "`cat $DEVICE/device/power/state`" -eq 0 ]
  17. then
  18. return 0
  19. fi
  20. if [ -r $DEVICE/device/rf_kill ] && [ "`cat $DEVICE/device/rf_kill`" -eq 0 ]
  21. then
  22. return 0
  23. fi
  24. fi
  25. done
  26.  
  27. # otherwise return failure
  28. return 1
  29. }
  30.  
  31. if (isAnyWirelessPoweredOn); then
  32. kdialog --passivepopup "Wyłączam Interfejsy bezprzewodowe" --title "Wciśnięty przycisk Wifi"
  33. else
  34. kdialog --passivepopup "Włączam Interfejsy bezprzewodowe" --title "Wciśnięty przycisk Wifi"
  35. fi
  36.  
  37. sudo /usr/local/bin/wireless-toggle.sh
  38.  
  39. if (isAnyWirelessPoweredOn); then
  40. sudo /usr/local/bin/wireless-led.sh 1
  41. else
  42. sudo /usr/local/bin/wireless-led.sh 0
  43. fi

This script is using Poul Sladen function to check wireless device state, then is informing user by KDE popup passive dialog about action that will be taken, then is using sudo to perform wireless device and notebook led toggle. This script is the script I bound with my notebook wireless button by creating new Global Shortcut for Command/URL in Keyboard Actions utility. This way I can switch on and off my wireless devices using one of two available wireless buttons on my notebook.

Fortunately performance button required only one script. As I wrote above I would like this button to toggle between defined in system power profiles. KDE desktop environment has great PowerDevil utility to configure and manage power profiles. I created a script which is using Dbus command provided by PowerDevil to switch profile. Below you can see my performance.sh script.

View the full performance.sh file
  1. #!/bin/sh
  2.  
  3. PROFILES="/usr/local/bin/profiles"
  4.  
  5. test -f ${PROFILES} || exit 0
  6.  
  7. TEMPFILE=/tmp/${USER}-profile.tmp
  8.  
  9. if (test -f ${TEMPFILE}) then
  10. read line < ${TEMPFILE}
  11. PROFILE=${line}
  12. else
  13. PROFILE=Dynamic
  14. fi
  15.  
  16. i=0
  17. flaga=0
  18.  
  19. while read line
  20. do
  21. i=`expr $i + 1`
  22. if (test "${line}" = "${PROFILE}") then
  23. flaga=$i
  24. fi
  25. done < ${PROFILES}
  26.  
  27. if (test $flaga -eq $i) then
  28. flaga=1
  29. else
  30. flaga=`expr $flaga + 1`
  31. fi
  32.  
  33. j=0
  34.  
  35. while read line
  36. do
  37. j=`expr $j + 1`
  38. if (test $flaga -eq $j) then
  39. PROFILE=${line}
  40. fi
  41. done < ${PROFILES}
  42.  
  43. CMD="dbus-send --print-reply --session --dest=org.kde.powerdevil /modules/powerdevil org.kde.PowerDevil.setProfile string:"
  44.  
  45. ${CMD}"${PROFILE}"
  46.  
  47. echo ${PROFILE} > ${TEMPFILE}

This script loops thought profile list defined in additional file, marking currently chosen profile and switching to the next one on the list using PowerDevil Dbus setProfile command. To make use of this script I need to define additional file containing all defined in my system power profiles. Below you can see my profiles list file.

View the profiles file
  1. Performance
  2. Performance No3D
  3. Dynamic
  4. Presentation
  5. Powersave
  6. Aggressive Powersave
  7. Xtreme Powersave

I bound performance.sh script with performance button the same way I did this for wireless button by creating new Global Shortcut for Command/URL in Keyboard Actions utility.

There are only two buttons left. But those buttons I configured using older approach. Unfortunately my TouchPad button wasn't recognized the same way the others buttons were. Probably configuration of my quite old notebook isn't fully supported by new hal mappings. That's why I need additional tool created especially for Asus notebooks. This tool is called acpi4asus. To install this tool in Gentoo Linux system I had to run following commands in terminal:

echo "app-laptop/acpi4asus ~x86" > /etc/portage/package.keywords
emerge -av app-laptop/acpi4asus

This tool provides small program which helps recognized pressed button as acpi events. Thanks to this I can configure my last two buttons. First I need to make sure that this little program will be started when ever I logged into my KDE desktop environment. To do it I created a small script which will lunch this program and I save this script inside my home in ~/.kde4/Autostart catalog. You can see my asusacpid.sh file below.

  1. #!/bin/sh
  2.  
  3. /usr/bin/asus_acpid

This way every time I will log to my KDE graphical desktop environment this small application will be lunched and ready to support my configuration. The configuration of this tool should go to hidden catalog inside my home called .asus_acpi. The configuration is fairly simple first thing we need to do is to provide a file which will map keycode acpi event with the script performing desired by user action. Below you can see my mapping file for TouchPad button.

View the ~/.asus_acpi/events/asus-touchpad file
  1. # /etc/acpi/events/asus-touchpad
  2. # This is called when the user presses the touchpad button and calls
  3. # /etc/acpi/asus-touchpad.sh for further processing.
  4.  
  5. event=hotkey (ATKD|HOTK) 0000006a
  6. action=~/.asus_acpi/actions/asus-touchpad.sh &

As you can see my key is mapped to acpid event code 0000006a. When ever I press this button asus_acpid helper program should lunch ~/.asus_acpi/actions/asus-touchpad.sh script. The script of course should be responsible for toggling on and off my touchpad. Below you can see my ~/.asus_acpi/actions/asus-touchpad.sh.

View the ~/.asus_acpi/events/asus-touchpad file
  1. #!/bin/bash
  2. state=$(synclient -l | grep TouchpadOff | awk -F"= " '{print $2}')
  3. if [ "$state" = "0" ]; then
  4. kdialog --passivepopup "Wyłączam TouchPad" --title "Wciśnięty przycisk TouchPad"
  5. synclient TouchpadOff=1
  6. else
  7. kdialog --passivepopup "Włączam TouchPad" --title "Wciśnięty przycisk TouchPad"
  8. synclient TouchpadOff=0
  9. fi

As you can see this script is fairly simple. It reads the state of the touchpad and depending on the current state it informs the user using KDE passive popup dialog of action that will be performed and performing switching on and off the touchpad using synclient command. This script should work. However I found out that my synaptics touchpad driver need to be specially configured in Xorg.conf X server configuration file. Without this additional configuration the synclient command line tool wasn't able to access my touchpad. Below you can see part of my Xorg.conf file affecting synaptics driver configuration.

View the part of /etc/X11/Xorg.conf file
  1. Section "InputDevice"
  2. Identifier "Synaptics0"
  3. Driver "synaptics"
  4. Option "Protocol" "auto"
  5. Option "SendCoreEvents" "true"
  6. Option "Protocol" "auto"
  7. Option "SHMConfig" "on"
  8. EndSection

The most important part of this configuration is Option "SHMConfig" "on". This settings make touchpad accessible to synclient settings command. This is all that need to be done to make my touchpad button work.

The last button to configure is LCD - CRT button. I want to use this button to toggle between dual screen configurations. I found out that pressing this button generate 3 different acpi event codes. First time I pressed the button it generates the code 00000061, second time it generates the code 00000062 and the third time i press it it generates the code 00000063. Thanks to this behavior I can easily assign 3 different actions and toggle between them using one key. First thing I need to do is to provide event mappings. First one I called asus-screen1. Below you can see this file.

View the ~/.asus_acpi/events/asus-screen1 file
  1. # ~/.asus_acpi/events/asus-screen1
  2. # This is called when the user is presing screen lcd/crt button,
  3.  
  4. event=hotkey (ATKD|HOTK) 00000061
  5. action=~/.asus_acpi/actions/screen1.sh &

Second one I called asus-screen2. Below you can see this file.

View the ~/.asus_acpi/events/asus-screen2 file
  1. # ~/.asus_acpi/events/asus-screen2
  2. # This is called when the user is presing screen lcd/crt button,
  3.  
  4. event=hotkey (ATKD|HOTK) 00000062
  5. action=~/.asus_acpi/actions/screen2.sh &

Third one I called asus-screen3. Below you can see this file.

View the ~/.asus_acpi/events/asus-screen3 file
  1. # ~/.asus_acpi/events/screen3
  2. # This is called when the user is presing screen lcd/crt button,
  3.  
  4. event=hotkey (ATKD|HOTK) 00000063
  5. action=~/.asus_acpi/actions/screen3.sh &

Every action mapping file is pointing to script created in actions catalog. First one of this scripts is called screen1.sh. Below you can see this file.

View the ~/.asus_acpi/actions/screen1.sh file
  1. #!/bin/sh
  2.  
  3. kdialog --passivepopup "Wyłączam drugi ekran" --title "Wciśnięty przycisk Screen"
  4.  
  5. xrandr --output LVDS --auto --output VGA-0 --off

This script is disabling possibly attached to my notebook second screen and setting the main screen into default resolution using command line xrandr tool. Second one of this scripts is called screen2.sh. Below you can see this file.

View the ~/.asus_acpi/actions/screen2.sh file
  1. #!/bin/sh
  2.  
  3. kdialog --passivepopup "Ustawiam oba ekrany w tryb klonowania" --title "Wciśnięty przycisk Screen"
  4.  
  5. xrandr --output LVDS --mode 1024x768 --output VGA-0 --mode 1024x768 --same-as LVDS

This script is setting both screen resolution to 1024x768 and setting positioning one over another enabling cloning mode. Third one of this scripts is called screen3.sh. Below you can see this file.

View the ~/.asus_acpi/actions/screen3.sh file
  1. #!/bin/sh
  2.  
  3. kdialog --passivepopup "Uaktywniam oba ekrany w trybie domyślnej rozdzielczości " --title "Wciśnięty przycisk Screen"
  4.  
  5. xrandr --output LVDS --auto --output VGA-0 --auto --right-of LVDS

This script is setting both screens into it's default resolutions and placing 2nd screen on the right of the 1st screen. Now I can toggle between screen configurations using only one button. This is highly important for me as I'm very often using my computer to show something to larger audience.

This is it I have all my multimedia keys configured exactly the way I wanted. Thats why I love Gentoo Linux. If I want to achieve something I can do it I'm not bound to any default configuration. At the end I add one more quite obvious thing. All mentioned above scrips has to be made executable before you can use them. To do it you can run following command in terminal:

chmod +x /path-to-script/script-name.sh

Additional Information

To make my configuration complete I must point that I did one more thing. My notebook has a mail notification led. I would like this led to light up when my default mail client downloads new mail from one of my mailboxes. To achieve this goal I created a mailledon.sh script. Below you can see this file.

View the mailledon.sh file
  1. #!/bin/sh
  2.  
  3. echo 1 > /sys/class/leds/asus\:\:mail/brightness

This script is passing 1 value to mail led device, which should turn on the led. Unfortunately this script has to be lunched using higher system privileges. I additionally had to run visudo utility and add belows line to sudo configuration.

ALL notebook = NOPASSWD: /usr/local/bin/mailledon.sh

This will let any user logged to my notebook use this script without the need of providing the password. I attached this script in Kmail mail client configuration in Detailed mail notification section this way:

sudo /usr/local/bin/mailledon.sh

When I'm receiving new mail the notification led is lighting now.

I copied all my configuration to /etc/skel catalog. To by more specific I copied whole ~/.asus_acpi catalog content a long side with ~/.kde4/Autostart/asusacpid.sh, ~/.kde4/share/config/khotkeysrc, ~/.kde4/share/config/kglobalshortcutsrc, ~/.kde4/share/config/powerdevilprofilesrc and ~/.kde4/share/config/powerdevilprofilesrc. This way when I was creating new user account for my girlfriend she already had all needed multimedia keys configuration in her profile. No need of painful additional configuration for her.

Most of mentioned above scripts are avaiable on my svn server. Below you can find direct links to them.

Prove that it's working

Sources


Comments

If you have found something wrong with the information provided above or maybe you just want to speak your mind about it, feel free to leave a comment.
All comments will show up on page after being approved. Sorry for such policy but I want to make sure that my site will be free of abusive or vulgar content. I don't mind being criticized just do it using right words.

Leave a comment