Thursday, March 26, 2009

Goodbye VCP/VCK?


:: whot@dingo:~/xorg/app/xinput/src> ./xinput --list --short
Default device id=2 [master device]
↳ Power Button (FF) id=3 [slave device (2)]
↳ Video Bus id=4 [slave device (2)]
↳ Sleep Button (CM) id=5 [slave device (2)]
↳ Video Bus id=6 [slave device (2)]
↳ Microsoft Microsoft? Digital Media Keyboard id=7 [slave device (2)]
↳ Microsoft Microsoft? Digital Media Keyboard id=8 [slave device (2)]
↳ ThinkPad Extra Buttons id=9 [slave device (2)]
↳ Macintosh mouse button emulation id=11 [slave device (2)]
↳ Microsoft Microsoft 5-Button Mouse with IntelliEye(TM) id=13 [slave device (2)]
↳ SynPS/2 Synaptics TouchPad id=14 [slave device (2)]
foobar id=15 [master device]
↳ AT Translated Set 2 keyboard id=10 [slave device (15)]
↳ TPPS/2 IBM TrackPoint id=12 [slave device (15)]


So what does this mean?

xinput --list simply lists all the devices connected to the server. In current servers, these were the "Virtual Core Pointer", the "Virtual Core Keyboard" and a bunch of physical devices.

I simply got rid of the distinction between pointers and keyboards, because too many devices are both anyway. The distinction doesn't really make sense. Even worse, with MPX's event routing through the respective master devices it became a bit of a nightmare to do key events correctly. I'll spare you the details.

So anyway. The idea is to merge master pointers and master keyboards into a single master device. This device is both, thus all events from any attached slave device goes through this single master. Nice and clean, and once we need more capabilities (*cough*multitouch*cough*) we can easily tack it onto the MD.

Now, we do have the notion of pointer and keyboards in the core protocol and to break the core protocol requires a presidential pardon that I have yet to obtain. One of the tougher things here are core grabs. With a single master device, all we need to support is an async pointer grab that is overridden by a passive sync keyboard grab (affecting the same device, but other events) that may or may not get modified by an active pointer grab. So while freezing the device for keyboard events you may need to replay pointer events on the device that is frozen, if this device isn't still frozen for pointer events by some other grab. Surprisingly, there's nothing in the Genevan Convetion about this.

Anyhow. AFAICT, this works now, with core grabs passing the X Test Suite and I'm happily running my standard Fedora desktop without noticing anything different.

Some of the remaining issues:
- god, this code is ugly.
- lazy transfer of classes to the MD.
- handling of the focus if the MD loses the key class.
- there is not enough beer in the fridge.
- testing this through the XI2 API to make sure it isn't completely insane.
- spec out XI2 grabs.
- misc. details that will make me regret this attempt.

Oh, as a side-effect this also enables merged modifiers, i.e. pressing shift on one keyboard types capitals on another one (if both are attached to the same master).

[edit: this whole experiment is not upstream, not even on my people.freedesktop until I cleaned it up]

Monday, March 23, 2009

XI2 implementation, take 1

This weekend, I announced the first implementation of XI2 on the xorg-devel list.

You can get the repositories from

git://people.freedesktop.org/~whot/xserver.git
git://people.freedesktop.org/~whot/inputproto.git
git://people.freedesktop.org/~whot/libXi.git
git://people.freedesktop.org/~whot/xinput.git

Check out the xi2 branch on all four repositories.

XI2 is important for two reasons. One, it's the client-side API that enables applications to make use of MPX. For obvious reasons, I have some interest in getting this done.
The other part of XI2 (and why it is called XI2) is that it's a new version of the X Input Extension. One of the goals here is a cleaned up API that is less painful to use than the first, current, version.

Aside from some API cleanup, the new additions are subpixel precision in events, the ability to support devices that change capabilities at runtime and relative device events. And of course all the stuff required to access MPX' functionality.

So, if you're adventurous*, grab the repositories, compile them up and test them. You can write little test apps to play around with the new stuff, and if you find any problems or inconsistencies, please report them back. I'm trying really hard to get this right.
Note that because this is the first version, API changes are to be expected and there will be the odd bug in there.

* One of the main goals of MPX (and XI2) is that it must be invisible until used. So you can grab the repositories and run your everyday desktop off it and there should be no difference.

Thursday, February 26, 2009

Tip of the day - wheel emulation

[update 30 May 2012: add xorg.conf.d snippet] First, run xinput --list --short to identify your mouse device. Let's assume that your mouse is called "USB Mouse".
Then, run the following command:

xinput --set-int-prop "USB Mouse" "Evdev Wheel Emulation" 8 1
xinput --set-int-prop "USB Mouse" "Evdev Wheel Emulation Button" 8 3

Now, holding the right mouse button and moving up and down will scroll. Very useful for reading long articles.

Requirements: evdev 2.1, X server 1.6 and xinput 1.4. Don't forget to check the evdev man page, there's a few extra tweaks related to wheel emulation. xinput is not persistent, but the above can be achieved with the following xorg.conf.d snippet:
Section "InputClass"
   Identifier     "Wheel Emulation"
   MatchIsPointer "on"
   MatchProduct   "USB Mouse"
   Option         "EmulateWheelButton" "3"
   Option         "EmulateWheel" "on"
EndSection
Save this as /etc/X11/xorg.conf.d/99-wheel-emulation.conf and you're good to go. Requires X Server 1.8 or later, for older servers you can do the same by merging the keys input.x11_options.EmulateWheel and input.x11_options.EmulateWheelButton your HAL fdi file.

Tuesday, February 17, 2009

Generic axis support in evdev

After the groundwork by Matt Helsley we now have generic axis support in evdev. So evdev finally sets the device up according to what the kernel reports rather than limiting itself to x/y and potentially pressure.

A truly generic driver. Rejoice.

And because we can, it does axis labeling too (if you have xserver git master, that is).
No more guessing what axis 7 actually is.

The obligatory "screenshot":


whot@roo:~> xinput --list-props "PIXART USB OPTICAL MOUSE" | grep "Axis Labels"
Axis Labels (242): "Rel X", "Rel Y", "Rel Vert Wheel"
whot@roo:~> xinput --list-props "Wacom Intuos3 4x6" | grep "Axis Labels"
Axis Labels (242): "Abs X", "Abs Y", "Abs Z", "Abs Rotary X", "Abs Rotary Z", "Abs
Throttle", "Abs Wheel", "Abs Pressure", "Abs Distance", "Abs Tilt X", "Abs Tilt Y", "Abs Misc"


Expect this to be in evdev 2.2, once it has matured and potential glitches are ironed out.

Thursday, January 8, 2009

4 useful things - try this at home.

tig: a curses interface for git. It gives you a mutt-like interface of the git repository and provides you with the ability to define custom key commands, etc. Really good for reviewing patches or lists of patches before pushing them, and even better for branch work. Example: git checkout mybranch; tig master. Hitting C now will cherry-pick the currently selected patch onto the current branch. I have to admit, that only since I started using tig I got a reasonably good handle on my branches. Thanks to Kristian Høgsberg for showing me tig.



cscope_maps: a cscope pluging for vim. It provides a significant advantage over the ctags support as it doesn't require the use of :cnext anymore. Instead, it lists all tags in a list and you can jump straight to them. It also gives you the "who's using this symbol" cscope search on "Ctrl+Space, s".




taglist: another plugin for vim. After hitting :Tlist, it lists the symbols defined in the current file (and also from previous buffers, though I find this sometimes annoying). Great for getting an overview on a new code base, or searching for symbols. The use of Tlist goes down the more familiar I become with a file, but it's still invaluable after a few years of looking at the same few files.



Nostalgy: a Thunderbird plugin that provides keyboard shortcuts to move emails around. Hit S and type the mailbox, including autocompletion, etc. Sorry, no screenshots (I use TB for work email and I'm too lazy to blur out), but there's screenshots at the URL above anyway.

Aside from the usual stuff these four have become must-haves to me.

edit: fix cscope_maps link, thanks to jonathan.

Tuesday, December 2, 2008

evdev, xorg.conf, hal and other FUD

Sparked by this thread, here's a list of X input facts in random order.


  • The evdev driver is the preferred input driver. If you are not running Linux, then evdev is not available for you and you can keep using the mouse/kbd drivers.


  • If you are running Linux, you can keep using the mouse/kbd driver if you wish, but configuration adjustments need to be made. See below for details.


  • By default, the X server will expect a device list at runtime from HAL. You can turn this behaviour off by using Option "AutoAddDevices" "off" in the ServerLayout, or by disabling HAL at configure time. HAL is not required to use X.


  • If HAL is enabled, then the mouse/kbd drivers are disabled. Otherwise, you will get duplicate devices. If you want to use mouse/kbd, disable HAL.


  • Devices only get added if they have the input.x11_driver option set (check lshal). For mice and keyboards, evdev is the default, drivers such as linuxwacom or synaptics provide their own fdi.


  • Any other options need to be added with the key "input.x11_options.foobar" and must be of type string.


  • Devices specified in the xorg.conf will not be available after unplugging and replugging them, but will become available again after a VT switch or a resume.


  • XKB options are specified by HAL, not by the server.


  • The evdev driver will prevent you from adding the same event device twice. The synaptics driver does too. Evdev will not prevent you from adding /dev/input/mice and /dev/input/event1 at the same time.


  • HAL will prevent you from adding the same UDI.


  • AutoAddDevices specifies whether to add devices through HAL (default on).

  • AutoEnableDevices specifies whether to enable such devices immediately (default on).

  • AllowEmptyInput specifies if a mouse/kbd section if none is present is required (if AEI is on -> no mouse/kbd required, disables mouse/kbd if present in the xorg.conf). AllowEmptyInput defaults to (AutoAddDevices && AutoEnableDevices)


  • Synaptics SHM or other options can be enabled in the FDI file with the key "input.x11_options.SHMConfig" (or likewise). Options have to be type string.


  • Synaptics has improved a lot in regards to autoconfiguration and you probably won't need half of your options anymore.


  • For every default setting that annoys you there's at least one person that loves it. For every default setting that you find appropriate, there's at least one person hating it. Become an active contributor, then you get to decide on what the defaults are.


  • Storing configuration in HAL's fdi file is not the best solution but the best we have right now.


  • The old system worked, because you only ever had one mouse and one keyboard in X. Now you can have multiple of each, independently configured. This is why we switched to HAL for hotplugging and autoconfiguring.


  • Ranting and/or commenting on some blog won't get your issues fixed. Filing a bug may.

Wednesday, November 19, 2008

evdev 2.1 is out

After a (too) long wait, evdev 2.1 is finally out. This release should bring evdev up to speed and provide those features that the mouse driver had, but were previously missing from evdev. Get it while it's fresh.

One of the important things here (especially if you're a distributor): evdev 2.1 does not call EVIOCGRAB on the device anymore. Either patch it in again, or update your server to one that doesn't require it (1.5.3 will do).

Here's a short list of new features that have been added since 2.0:
- axis inversion
- touchscreen support (those that don't report BTN_LEFT)
- run-time calibration for absolute devices
- axis swapping
- mouse wheel emulation
- drag lock

Also included is property support for run-time configuration. We don't have a released server that provides this option yet, but it'll be good for a test-bed until 1.6 comes out.
The properties also caused the long wait for the release, I wanted to wait until the server API had settled down. The next release will be sooner. The proposed release date for X server 1.6 is
Jan 5 2009. Evdev 2.2 will be released by Jan 5 2009 as well.

A great thanks to Adam Jackson, Ander Conselvan de Oliveira, Chris Salch, Dan Nicholson, Daniel Stone, Fernando Carrijo, Julien Cristau, Keith Packard, Michel Dänzer, Simon Munton, and Søren Hauberg for their patches.