udev: Disabling touch pad when there’s an external mouse

Thursday, September 6th 2007

My hands are big and unwieldy. My touch pad is hyper sensitive. Together they make a mess of everything I do: the pointer jumps back and forth on the screen like some horny bonobo, and it makes my blood boil.

Easy solution

Turning the touch pad off is easy: synclient TouchPadOff=1.

But having to issue that command all the time is not very elegant, and I’d like the computer to do it by itself. I’m already using an external mouse most of the time, so this is just the matter of turning off the touch pad whenever the mouse is connected. For this we need

  1. to enable synclient,
  2. a short udev script to catch plugging and unplugging and
  3. a short shell script to run synclient

Enabling synclient

synclient is an interface to the Synaptics TouchPad driver. It won’t work until you’ve enabled SHMConfig "on" in the XOrg configuration (usually /etc/X11/xorg.conf). But this is not multi-user safe (from the synclient man page):

WARNING: This is not secure if you are in an untrusted multiuser environment. All local users can change the parameters at any time.

Catch the plug events

On contemporary lunix systems, udev monitors hardware connects and disconnects. This small snippet will run our shell script whenever an external mouse is plugged or unplugged:

KERNEL=="mouse[0-9]*", SUBSYSTEM=="input", RUN="/usr/local/bin/plug_external_mice $devpath"

Add this to your local file /etc/udev/rules.d/10-local.rules (create it if it doesn’t exist).

Manipulate the touch pad

Put this into /usr/local/bin/plug_external_mice and make it executable ( chmod +x /usr/local/bin/plug_external_mice ):

#!/bin/bash
# read http://reactivated.net/writing_udev_rules.html
## uncomment this for debugging:
#echo $ACTION-ing $@ >> /tmp/usb-mice-plug.log
case "$ACTION" in
  remove) /usr/bin/synclient TouchpadOff=0 ;;
  add) /usr/bin/synclient TouchpadOff=1 ;;
esac

This will turn the touch pad off when you connect the external mouse, and back on when you remove it.

Taking it further

Ideally, there shouldn’t be any need for an external bash script. But, for some reason, these rules won’t work:

SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION="add", RUN="/usr/bin/synclient TouchpadOff=1"
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION="remove", RUN="/usr/bin/synclient TouchpadOff=0"

I have no ideas why. If you do, please let me know!

Kubuntu Breezy and the hungry gam_server

Thursday, February 23rd 2006

I started noticing some days ago that some applications seemed to slow the system down significantly. More specifically, every time I ran digikam, it felt like running through maple syrup.

A quick look at top revealed that a process called gam_serverwas merrily eating up 10%-20% of cpu capacity. Of course, I killed it straight away. But alas! Like a bird phoenix, it was up in no time, doing central processing like nothing happened.

So I turned to the internet. I read about [gamin], and I read about a possible solution to my woes. 10 minutes later, *gam_server is not giving me such a hard time* anymore. Here's what I did.

  1. Installed gamin from dapper, as per spilog's suggestions
  2. Installed a new ~/.gaminrc configuration file, from the gamin pages
  3. killall gam_server

What does my gaminrc look like?

# configuration for gamin
# http://www.gnome.org/~veillard/gamin/config.html
#
# Can be used to override the default behaviour.
# notify filepath(s) : indicate to use kernel notification
# poll filepath(s)   : indicate to use polling instead
# fsset fsname method poll_limit : indicate what method of notification for the filesystem
#                                  kernel - use the kernel for notification
#                                  poll - use polling for notification
#                                  none - don't use any notification
#
#                                  the poll_limit is the number of seconds
#                                  that must pass before a resource is polled again.
#                                  It is optional, and if it is not present the previous
#                                  value will be used or the default.

# this is where I keep my pictures and my music, use kernel notification on these paths:
notify /mnt/felles/bilder* /mnt/felles/musikk*

More reading

picking on dnotify

Ubuntu on a usb disk and Debian in a chroot

Sunday, October 23rd 2005

Now, I have long been interested in Ubuntu (who hasn't), and it is exciting to follow the revitalisation of Debian in the wake of Ubuntu.

I am a diehard Debian fan, and have previously only tried the Ubuntu Live disk. But yesterday this changed. I write this from a Ubuntu install on an external usb harddrive. My Debian installation is still thriving on the internal harddrive, in fact I use a lot of programs and documents from it.

Let me show you.

Installing Ubuntu: The Struggle

Using my Ubuntu 5.04 Hoary disc, I had no problems installing on the external harddrive (a 300GB Maxtor OneTouch II). But it did not boot. All I got was the error message:

USB Mass Storage support registered
pivot_root: No such file or directory
/sbin/init: 428: cannot open dev/console: no such file
Kernel Panic - not syncing: Attempted to kill init!

Clearly not good. And the pivot_root: No such file or directory message strongly suggested the cause: the ubuntu root partition was not found.

The solution

Luckily, this is swiftly remedied:

  • re-boot from the Ubuntu install disc, this time supplying the parameter rescue

  • when asked, mount the correct root file system (the one on the external drive)

  • type mount -t proc proc /proc

  • mount your boot partition if you have one

  • Add "ehci_hcd", "ohci_hcd", "ide_disk" and "usb_storage" to "/etc/mkinitrd/modules":

    echo -e "ehci_hcd\nohci_hcd\nide_disk\nusb_storage\n" >> /etc/mkinitrd/modules
    
  • Open /etc/mkinitrd/mkinitrd.conf and increase the variable DELAY from 0 to 10

  • Create the new initrd:

    mkinitrd -o /boot/initrd.img-[kernel version]-usb [kernel version]
    

Now, you can try out the new initrd from grub, and if it works you can edit /boot/grub/menu.lst to make it permanent.

Running Debian within Ubuntu

Setting up what is called a chroot, I am able to run all the programs from the Debian installation even though I've booted Ubuntu. And it's not just Debian: The same technique would've let me run any other Linux or BSD.

Here's how:

  • mount the debian partition: sudo mount /dev/hda6 /mnt/debian

  • mount proc: sudo mount -t proc proc /mnt/debian/proc

  • mount tmp: sudo mount --bind /tmp /mnt/debian/tmp. Why do we mount tmp? Because we need it to run X clients, graphic progams, from within the chroot.

  • Fix networking:

    sudo mv /mnt/debian/etc/resolv.conf /mnt/debian/etc/resolv.conf.old; 
    sudo cp /etc/resolv.conf /mnt/debian/etc
    
  • Now you can enter the chroot:

    sudo chroot /mnt/debian /bin/bash
    

Voila! You're "running Debian"! There's one thing left before you can start your graphic programs: since the graphic server is started by Ubuntu and not Debian, you need to import the so-called Magic Cookie. I'm sure there are other ways to do this, but here's a simple one:

In a Ubuntu shell, type: xauth list. This will list the "Cookies". Add these by typing in a Debian shell:

xauth add [paste line from Ubuntu shell here]

I recommend cutting-and-pasting the cookies, so typing errors don't bite you.

Now, try to run a graphic program, like xclock or qtorrent. Does it work?