Saturday, November 15, 2008

My hate for tapping and an introduction to modifying drivers in Ubuntu

First, a little background. On most laptops you have a touchpad which you can use to move your mouse-pointer around. Then someone came up with the twisted idea that you could use the touchpad to click on stuff. I have always turned this off, both when sitting on Windows and Linux. But for some reason, the driver-makers seem to conspire against me. In windows, the setting won't get stored on my laptop, so after every reboot, it is turned on again. In linux, well, there are a few occasions when it just turns itself on again. Not to mention that if some tool decides to modify your xorg.conf, you probably will get it turned back on again.

Some time ago, I got really tired of this and decided to download the source for the linux-driver and remove the possibility to tap on the touchpad alltogether. :)

On ubuntu you just run:

$ apt-get source xserver-xorg-input-synaptics

To download the source.
When you have downloaded it, make a copy of it, in this post I will call them $ORIG and $COPY.

The reason for this is that in Ubuntu they package unmodified source for a particular release of the software and then they have a set of patches that they apply when they build the packages. So what we want to do is to create a patch that will apply cleanly just as if it had been a part of the Ubuntu release.

Some things about structure of the source package, if you go inside $COPY, you can see a debian catalog, this is where patches and configuration is stored, you can also see a src, for source. These are the two catalogs that we will be looking at.

Let's begin by finding what it is we want to change. You can turn off tapping by setting MaxTapTime to 0 in xorg.conf, so we begin by finding where this is read with:

$ grep MaxTapTime $COPY/src/*

So, it is in synaptics.c?
This line:
pars->tap_time = xf86SetIntOption(opts, "MaxTapTime", 180);
Let's do a google search on what xf86SetIntOption is supposed to return.
So, it returns the integer that is read from xorg.conf. This will be a quite easy patch then, since we always want this value to be 0.

So, let's set everything up and start working. Begin by applying all patches that are shipped.
While standing in $COPY, run:

$ for file in `ls debian/patches`; do patch -p1 < debian/patches/$file; done"

Now it is ready for our patch. Do a:

$ cp synaptics.c synaptics.c.orig

We need the original file so we can create a patch. Open the synaptics.c file in your favorite editor (emacs) go to the pars->tap_time line and change it to: pars->tap_time = 0;.

Now it's time to create the patch, quit the editor. Run:

$ diff -Naur synaptics.c.orig synaptics.c > $ORIG/debian/patches/107_no_more_tapping.patch

Add the new file to $ORIG/debian/patches/series

Now, modify the head of the patch to have the same style as the others. It should look something like this:

$ head -n5 107_no_more_tapping.patch

Index: xfree86-driver-synaptics-0.15.2/src/synaptics.c
===================================================================
--- xfree86-driver-synaptics-0.15.2.orig/src/synaptics.c 2008-11-15 13:35:36.000000000 +0100
+++ xfree86-driver-synaptics-0.15.2/src/synaptics.c 2008-11-15 13:36:07.000000000 +0100


After you have done this, it's time to build the new deb by running:

$ apt-get build-dep xserver-xorg-input-synaptics

This will install everything you need to have in order to compile the package.

Then go to $ORIG and run:

$ dpkg-buildpackage -rfakeroot

This will create the deb for you and put it in the directory above. To install your new tap-free driver, just run:

$ dpkg -i xserver-xorg-input-synaptics_0.15.2-0ubuntu7_amd64.deb

Be aware though that when a new version is released, it will by default overwrite your patched binary.. but just keep the patch and do the same procedure then.

And for a time, it was good.

Tapping was no more.

No comments: