Update to the Touchpad Script

Some time ago I posted a script that turned the touchpad on and off as needed. This script disabled the touchpad when I using a mouse. After using it for sometime I found that occasionally the device numbers changed after a reboot. So I modified the script to use the device name in place of the ID.

The original post, now updated, is here.

Disabling Touchpad when using a Mouse

After using this script for a while I found a problem when occasionally after a reboot the device numbers had changed. So I have changed the script to use the device name in place of the ID. This has solved the problem. I’ve also added icons to the notification output.

There is a common feature on current Linux desktop that allows the touchpad to be disabled while typing. This is a useful feature but it has its limitations. The delay before the touchpad starts working can be set to a long time to reduce accidental movement but then the delay becomes irritating. I find I still occasionally brush the touchpad and cause an issue with what I am typing particularly when I pause to review what I have written.

As I normally use a bluetooth mouse I would prefer that the touchpad is completely disabled or preferably disabled when the mouse is in use. There are several scripts around which do this using synclient. I have found a few of these and tested them and none worked for me. I could see that the setting was changed but the touchpad was still active.

After a fair bit of research I found mention of using xinput and the commands needed to use xinput to disable the touchpad. Xinput has an advantage over synclient in that it completely disables the touchpad, buttons and all whereas synclient just stops any cursor movement.

I have tested this on my Thinkpad running Korora 23 Xfce but it should work on any recent version of most distros and with most desktop environments. It isn’t needed in KDE which includes this as an option in the touchpad settings. The script should also work with a USB mouse, in fact any sort of mouse, as well as the Bluetooth mouse it was tested with. The script uses xinput to check if a mouse is present. If your mouse is listed there and the name includes the word “mouse” it will work. Type “xinput –list” (without the quotes of course) with your mouse attached and check it is there.

There are a couple of steps needed to get xinput to work. The first is to identify the id of the touchpad. To do this run the command “xinput –list”. It will show a list of all the devices xinput controls. One of these is clearly marked as the touchpad. Looking along that line there is an ‘id=’ field. Make a note of this number, mine is 11 but yours may well be different. Looking along that line also make a note of the exact title of the touchpad, mine was “SynPS/2 Synaptics TouchPad” which seems to be common.

Next you need the id of the touchpad off setting for that device. Run “xinput –list-props 11” substituting the device number you found earlier for 11. This gives a long list of properties for that device. Look for “Device Enabled”, for me this was first on the list and so I had to scroll up to see it. That line will have a number in brackets, the property id, mine is 139 but again yours will probably be different.

With both those numbers recorded we are ready to test the xinput command. There is no point making a script if the command doesn’t work. Test with the command “xinput set-int-prop 11 139 8 0” (replacing my 11 with the device number you found and the 139 with the property number you found). If the command works your touchpad will be disabled. Run the command “xinput set-int-prop 11 139 8 1” (yes replace my numbers with yours again) to enable it again.

Once that is working we can create a script. My script is copied from several I found that used synclient but with the appropriate command replaced. Don’t forget to put the correct numbers in your script. We will also use the exact name of the touchpad in place of the number.

First as root or using sudo open /usr/local/bin/touchpad in your favourite text editor. It should be a new file. Copy and paste the script below and then edit the lines with the xinput command.

#!/bin/bash
sleep 1
list=`xinput --list | grep -i 'mouse'`
if [ ${#list} -eq 0 ]; then
xinput set-int-prop 'SynPS/2 Synaptics TouchPad' 139 8 1
notify-send -i touchpad-indicator "No Mouse found" "Your touchpad is set to ON"
else
xinput set-int-prop 'SynPS/2 Synaptics TouchPad' 139 8 0
notify-send -i preferences-desktop-peripherals "Mouse connected" "Your touchpad is now turned OFF"
fi

Save the file. Make it executable, “chmod +x /usr/local/bin/touchpad”. Note the sleep on the first line isn’t strictly needed but occasionally the script fails to run without it.

Now it should work. Test by running the script as a user. If your mouse is connected you should see a notification and the touchpad should be disabled. Next disconnect the mouse and check the touchpad again. I use a bluetooth mouse and it takes some time for the system to recognise that the mouse is off. I’m guessing it thinks there is a temporary break in communication. But with a usb mouse it should react much faster. I normally don’t need to run the script again.

However the exception is after a reboot or very occasionally upon returning from a suspend I find I need to run it. I use a dropdown terminal so it isn’t a problem to open it and run the script. However you may prefer to create a keyboard shortcut so that you can run the script quickly and easily as needed. In Xfce go to settings – Keyboard – Application Shortcuts and put the full path to the command as the application, press the key(s) and it is set. Test it.

One interesting result of this script is I can still move the cursor on my Thinkpad using the Trackpoint but none of the buttons work. I could disable the Trackpoint too but it isn’t easy to accidentally bump the Trackpoint, at least I’ve never done it so I don’t think it is necessary.

New Life for Old Laptop

I’m writing this on my Thinkpad T20. Nothing unusual in that you may say and you would be right, sort of. This old machine hasn’t seen much use recently as it was showing its age. It has a P3 700 and used to run W98SE on 128meg Ram, all on a 12gig hard drive. It seemed its days of usefulness were over.

I had been considering replacing it but it doesn’t get a lot of use, mainly as a terminal for Internet use and occasional use in meetings etc. and it is in good condition. I couldn’t really justify the cost of a new machine. There is not much available under $800 to $1000 here in Australia. So what other choices did I have?

I found a dealer selling used ram, important as the new Ram was very expensive if you could find it. I had been quoted $220 from an interstate supplier. For $50 I had an extra 256m installed and tested.

The hard drive was the next to go. I was going to get 80 gig but on a dollar per gig basis 160 was much cheaper so I splashed out. My old machine now had almost as good specs as a machine selling for $1200 or more. All for an investment of under $200. All it needed was a modern OS.

I have been using Linux for a number of years on my desktop but the hassles of getting WiFi working on the laptop meant I hadn’t used it here. I have read reports of much better support now so decided it was time to give it another go.

I had a few different distros on disks laying around so I tried some. The older ones still had wireless problems and some of the newer ones had other hardware issues, the video card is a problem. The DVD drive is a bit fussy too, some disks that work fine on my desktop wouldn’t load on the laptop.

After a couple of experiments I installed Ubuntu 7.04 Feisty Fawn. WiFi worked with WPA (when I found the correct password) on my Netgear WPN511 card out of the box. But no sound and video was a problem.

With the Savage driver X refused to load. I set it to vesa and it worked but wouldn’t allow resolutions greater than 800×600 and 1024×768 is the native resolution of this screen. The screen looks terrible at the smaller resolution too, but that is probably the driver. I spent some time on Thinkwiki (a recommended site for Thinkpad users) and the Ubuntu forums trying many suggestions without success. A live CD is handy here, it allows editing of messed up files, I found it the easiest way of restoring the last working setup. Finally on the forums I found a way of editing xorg.conf that worked. Now I have 1024×768 on a good clear screen.

I wasn’t too worried about the sound as I often work with it turned off so as not to disturb others but a chance find on the forums mentioned a similar problem solved by pressing the volume keys next to the Thinkpad key. So simple I hadn’t tried it. I’m embarrassed to say it worked.

There have been other issues too. I spent some time trying work out why ACPI won’t load. Every time I rebooted I got a message that I needed to force it to load, which I had done. Then I realised it was loading. I still get the message but it seems to work. The battery life is not as good as it was previously but that will take some fine tuning. The battery icon works well as does the wireless one.

With memory of 384 meg, which is less than the recommended but more than the minimum for Feisty, I find some programs slow to load but work well once loaded. I wouldn’t try using too many programs at a time but I have had no problem so far.

This is the first time I have used Gnome. All my Linux experience has been with KDE. So far so good. Of course I could install KDE and thereby make my system Kubuntu if I want but at the moment it is fine.

The result is a usable laptop for a minimum of expense, around $A200 and an investment of several hours of my time. Would I recommend it to others? Not unless they are willing to invest the time to make it work but I am pleased with the outcome.

UPDATE. One small problem has come to light since I wrote this. As this is an old computer the bios doesn’t know about big drives. It doesn’t handle anything over 33 gig. However Linux overcomes this problem except in one area. Linux can’t do anything until it is running. Consequently the boot partition must be on the first 33 gigs. I tried adding another copy of Linux as a dual boot but as the new partition was added on the end it wouldn’t boot. Not a big problem but worth noting.