Input

Differences between revisions 10 and 11
Revision 10 as of 2009-11-23 23:48:37
Size: 15875
Editor: p549F2849
Comment: Marked some links as "Probably out of date"
Revision 11 as of 2010-02-11 20:12:41
Size: 16987
Editor: pool-74-107-129-37
Comment:
Deletions are marked like this. Additions are marked like this.
Line 89: Line 89:
== Input Configuration with udev (Ubuntu 10.04) ==

Starting with Ubuntu 10.04, HAL has been removed and is no longer involved with device configuration. Where possible, configuration is done automatically in the kernel device driver. Manual configuration overrides can be done through udev rules, in /lib/udev/rules.d/. The syntax of these files is a bit unusual, but should be comprehensible for most developers; if in doubt, google 'udev rules'.

Input devices use the -evdev general purpose input driver by default (see 65-xorg-evdev.rules). AlpsPS/2 touchpads use -synaptics (see 66-xorg-synaptics.rules). Wacom devices use the new -wacom driver (see 69-xserver-xorg-input-wacom.rules). Keyboard configuration is achieved through console-setup (see 64-xorg-xkb.rules).

After installing new rules or modifying existing ones, you need to either reboot, or run this command:

{{{
udevadm trigger --action-add --subsystem-match=input
}}}

'''NOTE''': The above can trigger hangs in certain cases since it causes a lid device re-detection, which is a bit buggy.

Line 91: Line 106:
== Input Configuration with HAL ==

Beginning with Ubuntu 8.10, input device configuration is done through HAL rather than in your {{{xorg.conf}}}. The syntax for HAL {{{fdi}}} files is a bit different than {{{xorg.conf}}}, and editing XML is only marginally better than editing {{{xorg.conf}}}... but on the plus side configuration changes don't require an X restart - just replugging of the device.
== Input Configuration with HAL (Ubuntu 8.10 to 9.10) ==

In Ubuntu 8.10, 9.04, and 9.10, input device configuration is done through HAL rather than in your {{{xorg.conf}}}. The syntax for HAL {{{fdi}}} files is a bit different than {{{xorg.conf}}}, and editing XML is only marginally better than editing {{{xorg.conf}}}... but on the plus side configuration changes don't require an X restart - just replugging of the device.

Ubuntu 8.04 and later include a new version of Xorg which support input-hotplug. With this new functionality, it's likely that you won't need to do any configuration at all to make your devices work, assuming they're recognized and set up by the kernel. However, if you do need to do adjust things, read on.

Dynamic Input Configuration with xinput

The xinput command line tool can be used for some on-the-fly configuration adjustments. Ubuntu 8.04 users will first need to install xinput from universe.

To view a listing of the input devices X sees, run:

$ xinput list
...
"Configured Mouse"      id=2    [XExtensionPointer]
        Num_buttons is 9
        Num_axes is 2
        Mode is Relative
        Motion_buffer is 256
        Axis 0 :
                Min_value is -1
                Max_value is -1
                Resolution is 1
        Axis 1 :
                Min_value is -1
                Max_value is -1
                Resolution is 1
"Generic Keyboard"      id=3    [XExtensionKeyboard]
        Num_keys is 248
        Min_keycode is 8
        Max_keycode is 255

Individual devices can be queried for more details:

$ xinput query-state "Configured Mouse"
2 classes :
ButtonClass
        button[1]=up
        button[2]=up
        button[3]=up
        button[4]=up
        button[5]=up
        button[6]=up
        button[7]=up
        button[8]=up
        button[9]=up
ValuatorClass Mode=Relative Proximity=In
        valuator[0]=3182
        valuator[1]=969

If you have multiple mouse devices installed, you can switch which is considered the core pointer like this:

$ xinput set-pointer "Configured Mouse"

xinput can also be used to alter the button mappings on mice and adjust the acceleration and feedback settings.

In Ubuntu 8.10 and later, different input drivers may also expose arbitrary properties for applications to set. Synaptics touchpads are particularly configurable like this, but other devices have some more general properties.

$ xinput list-props "SynPS/2 Synaptics TouchPad"
Device 'SynPS/2 Synaptics TouchPad':
        Device Enabled:         1
        Synaptics Edges:                1632, 5312, 1575, 4281
        Synaptics Finger:               25, 30, 256
        Synaptics Tap Time:             180
        Synaptics Tap Move:             220
        Synaptics Tap Durations:                180, 180, 100
        Synaptics Tap FastTap:          0
[...]

$ xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Device Enabled" 8 0
$ xinput list-props "SynPS/2 Synaptics TouchPad"
Device 'SynPS/2 Synaptics TouchPad':
        Device Enabled:         0
        Synaptics Edges:                1632, 5312, 1575, 4281
        Synaptics Finger:               25, 30, 256
        Synaptics Tap Time:             180
        Synaptics Tap Move:             220
        Synaptics Tap Durations:                180, 180, 100
        Synaptics Tap FastTap:          0
[...]

Input Configuration with udev (Ubuntu 10.04)

Starting with Ubuntu 10.04, HAL has been removed and is no longer involved with device configuration. Where possible, configuration is done automatically in the kernel device driver. Manual configuration overrides can be done through udev rules, in /lib/udev/rules.d/. The syntax of these files is a bit unusual, but should be comprehensible for most developers; if in doubt, google 'udev rules'.

Input devices use the -evdev general purpose input driver by default (see 65-xorg-evdev.rules). AlpsPS/2 touchpads use -synaptics (see 66-xorg-synaptics.rules). Wacom devices use the new -wacom driver (see 69-xserver-xorg-input-wacom.rules). Keyboard configuration is achieved through console-setup (see 64-xorg-xkb.rules).

After installing new rules or modifying existing ones, you need to either reboot, or run this command:

udevadm trigger --action-add --subsystem-match=input

NOTE: The above can trigger hangs in certain cases since it causes a lid device re-detection, which is a bit buggy.

Input Configuration with HAL (Ubuntu 8.10 to 9.10)

In Ubuntu 8.10, 9.04, and 9.10, input device configuration is done through HAL rather than in your xorg.conf. The syntax for HAL fdi files is a bit different than xorg.conf, and editing XML is only marginally better than editing xorg.conf... but on the plus side configuration changes don't require an X restart - just replugging of the device.

Essentially, to configure a device, add a new fdi file for it to your /etc/hal/fdi/policy directory. You will then need to replug the device or log out and in again for the changes to take effect.

For example, use this sort of fdi file to set Synaptics touchpad options (see the synaptics manpage for possible options, or the Synaptics documentation for other methods):

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
 <device>
  <match key="input.x11_driver" string="synaptics">
   <merge key="input.x11_options.VertTwoFingerScroll" type="string">true</merge>
   <merge key="input.x11_options.HorizTwoFingerScroll" type="string">true</merge>
  </match>
 </device>
</deviceinfo>

The match elements are used to conditionally match on various attributes related to the device or system. In this case we apply these settings to any device using the synaptics (ie. touchpad) driver. The append elements are used to add parameters to various options. Options previously put in xorg.conf can be set using input.x11_options.<option-name> (string).

Here is an example fdi file for setting up keys on a Dell Precision M20:

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <match key="/org/freedesktop/Hal/devices/computer:system.hardware.product" prefix="Precision">
      <match key="/org/freedesktop/Hal/devices/computer:system.hardware.product" contains="M20">
        <append key="input.keymap.data" type="strlist">e005:brightnessdown</append> <!-- Fn+Down arrow Brightness Down -->
        <append key="input.keymap.data" type="strlist">e006:brightnessup</append> <!-- Fn+Up arrow Brightness Up -->
        <append key="input.keymap.data" type="strlist">e007:battery</append> <!-- Fn+F3 battery icon -->
        <append key="input.keymap.data" type="strlist">e008:wlan</append> <!-- Fn+F2 Turn On/Off Wireless -->
        <append key="input.keymap.data" type="strlist">e009:ejectclosecd</append> <!-- Fn+F10 Eject CD -->
        <append key="input.keymap.data" type="strlist">e00a:suspend</append> <!-- Fn+F1 hibernate -->
        <append key="input.keymap.data" type="strlist">e00b:displaytoggle</append> <!-- Fn+F8 CRT/LCD -->
        <append key="info.capabilities" type="strlist">input.keymap</append>
      </match>
    </match>
  </device>
</deviceinfo>

These match elements are used to match on the system's product name, to check that it starts with "Precision" and contains "M20". In this case, we're appending some [key]:[function] pairs to the input.keymap.data option.

As a contrived example, let's say you wanted to specify the dvorak-intl variant and configure the eurosign to the E key:

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <match key="info.capabilities" contains="input.keys">
      <merge key="input.xkb.variant" type="string">dvorak-intl</merge>
      <merge key="input.xkb.options" type="string">eurosign:e</merge>
    </match>
  </device>
</deviceinfo>

An example of configuring for the Logitech MX1000 USB mouse:

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
 <device>
  <match key="info.capabilities" contains="input.mouse">
   <merge key="input.x11_driver" type="string">mouse</merge>

    <!-- Logitech tweaks -->
    <match key="@input.originating_device:usb.vendor_id" int="0x46d">
     <match key="@input.originating_device:usb.product_id" int_outof="0xc50e;0xc518">
      <merge key="input.x11_options.RelHWHEELOptions" type="string">invert</merge>
     </match>
    </match>

   </match>
  </match>
 </device>
</deviceinfo>

The vendor_id and product_id values can be found via

$ cat /proc/bus/input/devices

Example: Disabling middle-mouse button paste on a scrollwheel mouse

Scrollwheel mice support a middle-button click event when pressing the scrollwheel. This is a great feature, but you may find it irritating. Fortunately it can be disabled.

First, you need to know the id of the mouse, like this:

$ xinput list | grep 'id='

"Virtual core pointer"  id=0    [XPointer]
"Virtual core keyboard" id=1    [XKeyboard]
"AT Translated Set 2 keyboard"  id=2    [XExtensionKeyboard]
"Macintosh mouse button emulation"      id=3    [XExtensionPointer]
"Logitech USB-PS/2 Optical Mouse"       id=4    [XExtensionPointer]

My mouse has the Logitech logo printed on it, so I gather I need the last entry.

I can view the current button mapping thusly:

$ xinput get-button-map "Logitech USB-PS/2 Optical Mouse"

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 10

Really, only the first three numbers have meaning for me. They represent the left, middle, and right mouse buttons.

Alternately, the id found by the above xinput list command can be used in this and other xinput commands to name the device instead of the full "Logitech..." string:

$ xinput get-button-map 4

I can turn the middle mouse button off by setting it to 0:

$ xinput set-button-map "Logitech USB-PS/2 Optical Mouse" 1 0 3

Or I can turn the middle-mouse button into a left-mouse button by setting it to 1:

$ xinput set-button-map "Logitech USB-PS/2 Optical Mouse" 1 1 3

To make this set on a per-user basis, I can plug that line into my ~/.xstartup or other init file. It can also be done via fdi files; we'll leave that as an exercise. Smile :-)

Example: Disabling L+R mouse button paste on a two-button mouse

The fdi file allows you to adjust the HAL layers auto-detection of hardware to make it work better, or work at all. So for instance, I am configuring my mouse. I will need to know what to use to match the input device and how it is identified by hal. Probing the HAL is very easy with

$ lshal | less

I can then search that output with /<search term> . In my case, I can able discover the following about my mouse device:

udi = '/org/freedesktop/Hal/devices/usb_device_2222_3061_noserial_if0_logicaldev_input'
  info.capabilities = {'input', 'input.mouse'} (string list)
  info.category = 'input'  (string)
  info.parent = '/org/freedesktop/Hal/devices/usb_device_2222_3061_noserial_if0'  (string)
  info.product = 'Evoluent Vertical Mouse 2'  (string)
  info.subsystem = 'input'  (string)
  info.udi = '/org/freedesktop/Hal/devices/usb_device_2222_3061_noserial_if0_logicaldev_input'  (string)
  input.device = '/dev/input/event1'  (string)
  input.originating_device = '/org/freedesktop/Hal/devices/usb_device_2222_3061_noserial_if0'  (string)
  input.product = 'Evoluent Vertical Mouse 2'  (string)
  input.x11_driver = 'evdev'  (string)
  linux.device_file = '/dev/input/event1'  (string)
  linux.hotplug_type = 2  (0x2)  (int)
  linux.subsystem = 'input'  (string)
  linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:0b.1/usb2/2-5/2-5.3/2-5.3:1.0/input/input1/event1'  (string)

I used to have this configured in my xorg.conf like this to disable pasting when clicking the left and right mouse buttons together (which simulates the middle-mouse button):

Section "InputDevice"
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

I will need to match the mouse device in the hal output and configure it to respond like it did in my xorg. I created the following fdi file to accomplish this.

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <match key="info.capabilities" contains="input.mouse">
        <merge key="input.x11_driver" type="string">mouse</merge>
        <merge key="input.x11_options.Emulate3Buttons" type="string">no</merge>
        <merge key="input.x11_options.ZAxisMapping" type="integer">4 5</merge>
    </match>
  </device>
</deviceinfo>

As you can see, the translation from xorg configuration to fdi is fairly trivial. I then repeated the same method for my keyboard configuration.

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <match key="info.capabilities" contains="input.keyboard">
      <merge key="input.x11_driver" type="string">kbd</merge>
    </match>
  </device>
</deviceinfo>

Thats it. Here are a few more links on general fdi configuration

Troubleshooting

Custom settings are restored to default when a device is hotplugged, so if you mess up mouse button behavior just unplug it and plug it back in. No need to reboot. Wink ;-)

If you run into a problem where your HAL hardware detection just doesn't work with GDM(once the login screen comes up) you're not alone. It looks like there is an issue with the gdm start priorities. Since a patch is not released yet, you can read about it here, the best solution is to alter the boot priorities of gdm during start up so it always starts after hal. You do that by running the following:

$ sudo update-rc.d -f gdm remove #get rid of the old boot symlinks
$ sudo update-rc.d gdm defaults 25 #add the new ones with a higher priority

That's all there is to it. Hopefully that fixed the issue for you. If not, try converting your old xorg.conf input sections to fdi files using the techniques described above.

Contributed Documentation

The following documentation was provided by various people in the past. Generally, much of it was written for pre-InputHotplug X, so may or may not still work in Intrepid.

Keyboard Config

Mouse Config

Tablet Config

Touchpad Config

Game Controller Config

X/Config/Input (last edited 2012-12-21 12:38:00 by 027edfa5)