2014-04-28

Small victories: Configuring the Touchpad Key on an Asus Eee PC 1005HAB

Once upon a time, the realm of Microsoft decreed that Windows XP should be consigned to the dustbins of history. And so it was that my in-laws bequeathed to me an Asus Eee PC 1005HAB. This is the tale of a small victory in rehabilitating this netbook.

I had great success installing Arch Linux and getting a basic LXDE setup in place. However, there was a major irritation: the Synaptics touchpad. I'm an old-school touch typist with large hands and I found myself constantly fighting with the cursor as it leapt around every time I accidentally bumped the touchpad. I installed the acpi-eeepc-generic package from the AUR, but found that many of the settings simply weren't working. It also seemed to me that some of the scripts were overkill, requiring root privileges when they weren't strictly necessary.

Using xev, I made a list of keycodes for all the Fn key combinations. I then began adding keybindings to ~/.config/openbox/lxde-rc.xml. All of them worked EXCEPT the Touchpad Key (and the equivalent Fn F3 combination).

Here's the xev output for the Touchpad Key/Fn F3 keys:
KeyPress event, serial 45, synthetic NO, window 0x2400001,
    root 0x7e, subw 0x0, time 26427246, (106,43), root:(108,437),
    state 0x0, keycode 191 (keysym 0x1008ff81, XF86Tools), same_screen YES,
    XKeysymToKeycode returns keycode: 179
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

Small victory #1: I realized that I needed to bind to 191 (the original keycode) not XF86Tools.

While I was now able to invoke /etc/acpi/eeepc/acpi-eeepc-generic-toggle-touchpad.sh from the keys, it was slow and required invoking gksudo.

Small victory #2: I discovered that synclient did not require root privileges. I could have the functionality--as long as I didn't care about the aesthetics of turning the LED on and off.

Small victory #3: I realized I could write a small script to toggle the LED which could then safely be invoked via sudo without a password.

So here are the pieces of my solution:

TouchpadKeyLED.sh
#!/bin/bash

# TouchpadKeyLED.sh - Control the state of the Touchpad key LED

# NOTE: This command requires ROOT privileges, however, it is relatively
#   safe because we are only setting a single value in the /sys filesystem

LED_KEY=/sys/devices/platform/eeepc/leds/eeepc\:\:touchpad/brightness

case $1 in
    on | 0 )    STATE=0                     ;;
    off | 1 )   STATE=1                     ;;
    * )         STATE=$((1-$(<$LED_KEY)))   ;;
esac

echo $STATE >$LED_KEY


I'm pretty pleased with the flexibility here. We can pass as an argument either the actual values stored in "brightness" or simply "on" and "off". For any other argument, we toggle the current value by subtracting it from 1.

TouchpadToggle.sh
#!/bin/bash

# TouchpadToggle.sh

# 140428-BaP: Simplified version of acpi-eeepc-generic-toggle-touchpad.sh
#   that doesn't require sudo password prompting
# Based on https://wiki.archlinux.org/index.php/Touchpad_Synaptics

# TouchpadOff values: 0=on, 1=off, 2=only tapping/scrolling are off

# Allow explicit setting of all 3 states, as well as toggling between 0 & 1
#   (By counting "=.*0", we'll return 1 if it's on, otherwise 0)
case $1 in
    on | 0 )    TOGGLE=0    ;;
    off | 1 )   TOGGLE=1    ;;
    2 )         TOGGLE=2    ;;
    * )         TOGGLE=$(synclient -l | grep -c 'TouchpadOff.*=.*0')    ;;
esac

# Because I will almost always have the touchpad off, I want to light the LED
#   whenever the touchpad is active. (The acpi-eeepc-generic-toggle-touchpad.sh
#   script turned the LED on when the touchpad was off, which makes sense for
#   power savings when the touchpad is normally on...)
case $TOGGLE in
    0 ) STATE=0 ;;
    1 ) STATE=1 ;;
    2 ) STATE=0 ;;
esac

synclient TouchpadOff=$TOGGLE
sudo /usr/local/bin/TouchpadKeyLED.sh $STATE


Although I won't use it often, I'm pleased that my solution allows for setting all 3 possible values for "TouchpadOff". The original code only toggled between 0 and 1.

Of course, a more robust solution might cycle through 0, 1, and 2--but I think it's sufficient that I can set 2 if desired.

The next step was to add the following to my /etc/sudoers:

# 140428: Allow anyone to toggle the Touchpad key LED without a password
ALL ALL=(ALL) NOPASSWD: /usr/local/bin/TouchpadKeyLED.sh


For completeness, here's the keybinding from ~/.config/openbox/lxde-rc.xml
    <!-- LH Silver Key & Fn F3 -->
    <keybind key="0xBF">
      <action name="Execute">
        <command>/usr/local/bin/TouchpadToggle.sh</command>
      </action>
    </keybind>


The final piece of my solution was to ensure the touchpad is turned off by default for me:

~/.config/autostart/TouchpadDisable.desktop
[Desktop Entry]
Type=Application
Name=Touchpad Disable
Comment=Disables the Synaptics Touchpad
Exec=/usr/local/bin/TouchpadToggle.sh off
StartupNotify=false
Terminal=false
Hidden=false


Final small victory: I log in, the touchpad is disabled, the keybindings work, and the LED lights.

For now, I plan to keep the acpi-eepc-generic package installed. I want to make sure I've taken a look at all the scripts to see if there are better ways to enable all the functions of this netbook.

One final note: I did a quick proofread--I think I managed to undo any code mangling that occurred while pasting into this blog entry. Use at your own risk.

No comments:

Post a Comment