As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label touchpad. Show all posts

Having little fun with touchpad:

https://i.ytimg.com/vi/HrSgK9pe0Ko/sddefault.jpg

A/V out of sync, sorry about that!

Its a Bash script, you will need to enable SHMConfig for monitoring touchpad activity. I divided my touchpad into 3x2 cells, each with one audio file from /usr/share/sounds. The sound files may not be available on your system, just edit the script for audio files you have.

Synaptics actually provides three programs, called Just for Fun. They are Windows-only, which is not much of a surprise. I dont know how exactly these programs are, how much fun they could be. But I decided to create a simple one of my own.

After I have a working code, I realized there is a thing called keyboard and it would work even better than touchpad. Just I made this, well, because I can.

I was thinking to allow multiple tapping, but thats not very possible. Even though there is information about how many fingers on touchpad, but you dont have the position of each finger, only the first ones.

Back in December, 2008, I posted Proper way to turn on SHMConfig in X Server 1.5 with input hotplugging, that was when HAL had not been deprecated. I checked my un-merging log, HAL was removed from my system in December, 2010, two years later of the post.

According to man synaptics, since X server 1.6, you don't need SHMConfig for changing settings on the fly via synclient. However, the -m touchpad activity monitoring option still requires SHMConfig, or you will get the same old error message:
Can't access shared memory area. SHMConfig disabled?
I have a plan for monitoring activity of touchpad, so I tried to turn it on again and the proper way is to edit /usr/share/X11/xorg.conf.d/50-synaptics.conf:
Section "InputClass"
        Identifier "touchpad catchall"
        Driver "synaptics"
        MatchDevicePath "/dev/input/event*"
        MatchIsTouchpad "on"
        Option "SHMConfig" "on"
EndSection
The lines in bold text were what I added to it, the rest were the original content. I found out /dev/input/event* is crucial to get SHMConfig turned on. Without it, I still got the same error message saying SHMConfig disabled. I don't know if it also affects other options, but you don't actually need to put touchpad options here, you can change in your ~/.xinitrc or write a startup script.

If you don't have the file, then just create one in the same directory or one listed in man xorg.conf, X server looks into many different directories for configuration files.

I recently found out you can use xinput to enable or disable an input device. I used to use synclient to disable my touchpad, or using this tricky way to disable my laptop keyboard.

The first step to get device name or id of the device:

% xinput list
 Virtual core pointer                          id=2    [master pointer  (3)]
    Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
    USB Optical Mouse                         id=8    [slave  pointer  (2)]
    SynPS/2 Synaptics TouchPad                id=7    [slave  pointer  (2)]
 Virtual core keyboard                         id=3    [master keyboard (2)]
     Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
     Sleep Button                              id=9    [slave  keyboard (3)]
     Power Button                              id=10   [slave  keyboard (3)]
     Video Bus                                 id=11   [slave  keyboard (3)]
     AT Translated Set 2 keyboard              id=6    [slave  keyboard (3)]

For touchpad, the device name is 'SynPS/2 Synaptics TouchPad' and id is 7; for keyboard, they are 'AT Translated Set 2 keyboard' and 6. Next step is to know the properties of a device:

% xinput list-props 'AT Translated Set 2 keyboard'
Device 'AT Translated Set 2 keyboard':
        Device Enabled (127):   1

This keyboard only has a property 'Device Enabled' whose value is 1, that means this keyboard is enabled. To test disabling:

sleep 0.1 ; xinput set-prop 'AT Translated Set 2 keyboard' 'Device Enabled' 0 ; sleep 5 ; xinput set-prop 'AT Translated Set 2 keyboard' 'Device Enabled' 1

The first sleep 0.1 is to prevent enter keypress being repeatedly sent somehow when you directly disable the keyboard, I am guessing when you hit the enter and the command is executed, meaning the keyboard is disabled, but the keyup event is not yet sent, so X still thinks the enter key is pressed down.

Another simple way is to use id, so you dont need long device name:

sleep 0.1 ; xinput set-prop 8 127 0 ; sleep 5 ; xinput set-prop 8 127 1

8 is id of this keyboard and 127 is the property id of 'Device Enabled'. When you list properties of device using list-props, the numbers after property names are the property ids. It seems that 'Device Enabled' always has id 127, but device id is not always the same. It depends on device attached time, who shows up first who gets next available id.

One more thing to note: I dont need root privilege to set property value.

Your X probably doesn't have xorg.conf but automatically detect devices. Since Fedora 9, there is no xorg.conf after installing.

I just want to turn on the SHMConfig in order to change some settings of Synaptics touchpad. I then found out I need to create a configuration file, but the fact is not necessary. I only need to add a setting to /usr/share/hal/fdi/policy/20thirdparty/10-synaptics.fdi:
<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <match key="info.capabilities" contains="input.touchpad">
      <match key="info.product" contains="Synaptics TouchPad">
    <merge key="input.x11_driver" type="string">synaptics</merge>
    <merge key="input.x11_options.SHMConfig" type="string">on</merge>
      </match>
      <match key="info.product" contains="AlpsPS/2 ALPS">
    <merge key="input.x11_driver" type="string">synaptics</merge>
      </match>
      <match key="info.product" contains="appletouch">
          <merge key="input.x11_driver" type="string">synaptics</merge>
      </match>
      <match key="info.product" contains="bcm5974">
          <merge key="input.x11_driver" type="string">synaptics</merge>
      </match>
    </match>
  </device>
</deviceinfo>
This file ships with Fedora 10 with an added line:
<merge key="input.x11_options.SHMConfig" type="string">on</merge>
That will enable SHMConfig after your restart X.

By the way, if you want to auto-disable the touchpad while external mouse attached, add a /etc/udev/rules.d/50-synaptics.rules with content as follows:
ACTION=="add", SUBSYSTEM=="input", ID_CLASS="mouse", RUN+="/usr/bin/synclient -s TouchpadOff=1"
ACTION=="remove", SUBSYSTEM=="input", ID_CLASS="mouse", RUN+="/usr/bin/synclient -s TouchpadOff=0"
You should see the touchpad being disabled/enabled if you plug/unplug a mouse without restart X.

You can read more about touchpad and input hotplugging on ArchWiki.

Updated on 2009-10-26: Added -s to synclient command, newer version requires specifying the use of SHM. Without that argument, the root account (or whom run the synclient) couldn't be able to set the touchpad's parameters.