Disabling Emulate3Buttons on Ubuntu

2009-02-21 14:35

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.

Peter Seebach

---

Comment

  1. You help me a lot!!! :D
    TNX!!!!

    — Claudio · 2009-05-06 19:48 · #

  2. Thank you for this! It is much appreciated!

    — dave · 2009-11-03 13:09 · #

  3. 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.

    — sempronius · 2010-03-18 15:38 · #

  4. Only thing that works

    — Dylan · 2010-05-11 17:25 · #

  5. THX!!!!

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

    Great work!

    CU

    — Roygaard · 2010-06-20 07:11 · #

 
---