Disabling Emulate3Buttons on Ubuntu

2009/02/21

Categories: GeekStuff

Okay, this might be just a bit specialized, but it took me long enough to figure out.

Basic problem: X needs 3-button mice. It really does. Many machines don’t have them. So, X has a useful feature; you can set it so that simultaneous (or nearly) left+right clicks produce a “middle” click.

In recent Ubuntu, this sometimes gets enabled because the system isn’t quite sure that ALL of your “mice” have this feature – say, if it perceives a KVM switch as two mice, or if you have a built-in mouse and another mouse, or something.

The problem is that you can’t just override this in xorg.conf anymore. You need to use xinput. xinput’s powerful, clever, flexible… and totally over the heads of a lot of users. Here’s a script to run from .xinitrc or the equivalent which disables Emulate3Buttons on any input devices which have it. (It’s now called “Middle Button Emulation”, mind.)

#!/bin/sh
xinput list | sed -ne 's/^[^ ][^V].*id=\([0-9]*\).*/\1/p' | while read id
do
        case `xinput list-props $id` in
        *"Middle Button Emulation"*)
                xinput set-int-prop $id "Middle Button Emulation" 8 0
                ;;
        esac
done

How this works: We first obtain a list of ID numbers, disregarding those where the second character on the line was V, because xinput list-props doesn’t work on the "Virtual[...] lines for the generic keyboard and mouse. For each such device, we check to see whether it has the feature; if so, we disable it. (The number 8 indicates that we’re setting an 8-bit value; it doesn’t really matter. The disabled state is 0.)

The elaborate dance is done because I have no obvious guarantee that the id of a given mouse device might not change from one server restart to another under some future circumstances.

Comments [archived]


From: Claudio
Date: 2009-05-06 20:48:32 -0500

You help me a lot!!! :D

TNX!!!!


From: dave
Date: 2009-11-03 13:09:37 -0600

Thank you for this! It is much appreciated!


From: sempronius
Date: 2010-03-18 16:38:32 -0500

Doesn’t work here.

xinput list-props 2 tells me:

X Error of failed request: BadRequest (invalid request code or no such operation)

Major opcode of failed request: 151 (XInputExtension) Minor opcode of failed request: 36 () Serial number of failed request: 15 Current serial number in output stream: 15

Those device ids don’t work, but the name doesn’t either.


From: Dylan
Date: 2010-05-11 18:25:01 -0500

Only thing that works


From: Roygaard
Date: 2010-06-20 08:11:34 -0500

THX!!!!

It’s a great solution for some old-style-Q3A/OSP-sessions when I need some rocket-jumps to escape… ;)

Great work!

CU