Debouncing mice in Linux (esp. Ubuntu)

I’ve been using Ubuntu 14.04 as my main desktop for 3 months now, and i guess i’m 95% satisfied, 5% disgruntled. One of the things that caused me pain was how mice seem to auto-doubleclick sometimes. Of course, that’s the input switches that should be debounced in hardware, but obviously aren’t.

The problem started for me when i installed Ubuntu for the first time – my mouse, that had always worked well, had the problem with the new Ubuntu installation. Went out and bought a cheap 7,95 € one. It auto-doubleclicked from the first day on. Bought another, by Logitech, for 20 €. No problems yet. But …. on my other PC, my 60 € Razer mouse started double-clicking as well. So i started to investigate more.

Seems some guy named Matt Whitlock had the same problem a few years ago, and he developed a patch to the evdev code to add software debouncing. Unfortunately, the X maintainers refused to add it to the official sources, because of the cost of testing involved. This is even though many people seem to have this problem, and since all mice that had the problem in Ubuntu work well in Windows, i assume a) windows does its own software debouncing and b) hardware manufacturers don’t properly debounce their cheap mice because of a).

But the patch still works, and it can be added to your installation quite easily:

  • Get event-debounce-patch, either by copy/pasting from the original author post, or from my mirror.
  • Install the source code of evdev and the build environment, and compile it. Warning: the first apt-get will install the source to a subdirectory of your current directory, so cd to something suitable first.
apt-get source xserver-xorg-input-evdev-dev
 sudo apt-get build-dep xserver-xorg-input-evdev-dev
 cd xserver-xorg-input-evdev-2.8.2/
 patch -p 1 < ../evdev-debounce.patch
 dch -i
 debuild -us -uc -b
 cd ..
  • This will give you a file named xserver-xorg-input-evdev_2.8.2-1ubuntu2_amd64.deb in the directory you started from. Or, x86 instead if amd64 if you’re on a 32 bit system. In case you don’t want to compile yourself, you can download the file from my mirror. This is for Ubuntu 14.04, so depending on when you read this, my file will be outdated and you have to build it yourself.
  • Install this .deb file using
 sudo dpkg -i xserver-xorg-input-evdev_2.8.2-1ubuntu2_amd64.deb
  • Now, log out and re-login; this should start the X server and load the new package.
  • Next is to configure debouncing; unconfigured, the new software doesn’t change anything. Use xinput –list to find out the ID of your mouse device – in my case it’s the Razer mouse, ID=10:
$ xinput --list
 ⎡ Virtual core pointer id=2 [master pointer (3)]
 ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
 ⎜ ↳ Razer Razer Copperhead Laser Mouse id=10 [slave pointer (2)]
 ⎣ Virtual core keyboard id=3 [master keyboard (2)]
 ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
 ....
  • When you know your mouse device id, list the properties of that device. One of the properties – typically the last one – is the new debounce delay. You’ll need its id (286 in this case):
$ xinput --list-props 10
 .....
 Evdev Debounce Delay (286): 0
 .....
  • Last, change the property to the maximum value to debounce. If you set this too high, a fast real double-click might be “debounced” as well – a value of 20 works well for me, if your mouse switches are worn out badly, you might want to use 50:
$ xinput --set-prop --type=int --format=32 10 286 20
  • Once you find a value you like, you can put the above command into your $HOME/.xprofile. Or, to install a system-wide configuration file, put the following into /usr/share/X11/xorg.conf.d/12-evdev-debounce.conf – this file is new, and you need to be root to write it:
Section "InputClass"
 Identifier "evdev pointer debounce"
 MatchIsPointer "on"
 MatchDriver "evdev"
 Option "DebounceDelay" "20"
 EndSection

Problem solved!

26 thoughts on “Debouncing mice in Linux (esp. Ubuntu)

  1. Martin L

    I looked up the problem the past few days and hoped it would be already patched in ubuntu … well … worked as described, of course some packages where missing on my fresh installation, but was easy to figure out. Thanks, helped me a lot!

    Reply
  2. Michel V

    Thx man, this really helped me out.
    Funny thing though I did not had this problem in 12.04 with my logitecht md-570 (wireless trackball , very nice for a htpc on while sitting on a couch) upgraded (clean install) to 14.04 recently and right form that start i had this problem, which almost annoyed as much as windows normally does, almost.

    anyway thx again

    Reply
  3. Pingback: Ubuntu:mouse sometimes doubleclicks when i click once – Ubuntu Linux Questions

  4. Quentin

    Thanks, it worked!
    I have Linux Mint 17.2 and two very old, but very good Logitech mouses. They both work nicely under Windows, and fail with random double clicks on Linux.
    While I was not able to compile the solution from source (error: Unable to find a source package for xserver-xorg-input-evdev), the provided compiled file worked great! I set the debounce to 40ms and my mouses are perfect once again!

    Awesome <3

    Reply
  5. Jim

    Great! I’ve had this problem with several mice and have always hated throwing them out. I’m posting encouragement in the hope that the Xorg developers will see the value in this patch. Its my experience that long running projects like Xorg tend to hate the idea of any change. Even changing version numbers!

    Reply
  6. Dave

    I just got a new mouse (Gear Head) and it was double clicking like no tomorrow. I am using Linux Mint 15. I went to mouse preferences and changed the double click parameter to be longer. Problem solved. No code download required, no other changes required.

    Reply
  7. Yuyu Yacubu

    Thanks so much for the woderful instructions, for years I have fought with this and now, perfect!
    I had two issues however. First, in my distro (Funtoo) we are currently on xf86-input-evdev-2.92. The patch wouldn’t work, apparently the updated source has changed. So I manually created an updated patch that works for the newer input-evdev, it can be found here: https://github.com/yuyuyak/input-evdev-debounce.patch. I’ll also inform Matt Whitlock if possible.
    The second issue is regarding the setting command for .xprofile (I actually use .xinitrc). My mouse id and even the debounce variable number would be different at different startups. I’ve now found that logging out and logging back in with my display manager (slim) would cause this, but I’m not so sure that evdev can be trusted to always assign the same id. In any case, the following line will always pick the right incantation:
    xinput –set-prop –type=int –format=32 $(xinput –list|grep “USB Receiver”|cut -d “=” -f2|cut -f1) $(xinput –list-props 6|grep Debounce | cut -d “(” -f2|cut -d “)” -f1) 20
    Note that other users must change “USB Receiver” to uniquely match their mouse and change the 20 at the end if they wish for a different delay. Like you Guntram, 20 works fantastic for me!

    Reply
  8. Ezh

    Working with gentoo too. Thank you

    ebuild /usr/portage/x11-drivers/xf86-input-evdev/xf86-input-evdev-2.9.2.ebuild digest
    ebuild /usr/portage/x11-drivers/xf86-input-evdev/xf86-input-evdev-2.9.2.ebuild fetch
    ebuild /usr/portage/x11-drivers/xf86-input-evdev/xf86-input-evdev-2.9.2.ebuild unpack
    patch -p1 < evdev-debounce.patch
    ebuild /usr/portage/x11-drivers/xf86-input-evdev/xf86-input-evdev-2.9.2.ebuild compile
    ebuild /usr/portage/x11-drivers/xf86-input-evdev/xf86-input-evdev-2.9.2.ebuild install
    ebuild /usr/portage/x11-drivers/xf86-input-evdev/xf86-input-evdev-2.9.2.ebuild qmerge

    Reply
  9. Yuyu Yacubu

    Whoops! That fail-safe command in last post should be:
    xinput –set-prop –type=int –format=32 $(xinput –list|grep “USB Receiver”|cut -d “=” -f2|cut -f1) $(xinput –list-props $(xinput –list|grep “USB Receiver”|cut -d “=” -f2|cut -f1)|grep Debounce | cut -d “(” -f2|cut -d “)” -f1) 20
    Sorry for the confusion.

    Reply
  10. Alan

    Newer versions of debian (and probably ubuntu) default to using libinput for mouse drivers (google libinput vs evdev)

    To enable this patch to work, you have to remove the xserver-xorg-input-libinput package (and restart X etc..)

    Reply
  11. Pingback: Doppelklick anstatt einfachem Mausklick: Das Linux-Debouncing-Problem lösen › Linux und Ich

  12. Maurice

    Worked great on Mint 17. Built from source successfully.

    Note to the above comment about “error: Unable to find a source package for xserver-xorg-input-evdev”
    You need to configure source packages.

    Menu > Admin > Software Sources > enable source code repositories

    Reply
    1. Zeb

      Merci Maurice !!

      I had this problem (as well as the mouse problem).

      It’s pretty painfull that nothing is made straightforward in distroagainst the boucing fx…
      I’m trying to convince as many people as possible to switch to linux but that kind of problem is exactly what stop them … make it user friendly or cry.

      Reply
  13. reagan

    I’ve just been trying this fix out on Linux Mint 18.1, but after issuing the patch -p 1 < ../evdev-debounce.patch command, I get the following error, which I'm assuming is the reason the deb file is not produced where the article says it should be. Any help would be much appreciated. The double-clicking of the mouse is driving me nuts!

    patching file include/evdev-properties.h
    Hunk #1 succeeded at 91 with fuzz 2 (offset 4 lines).
    patching file src/Makefile.am
    patching file src/debounce.c
    patching file src/evdev.c
    Hunk #1 succeeded at 587 (offset -80 lines).
    Hunk #2 succeeded at 1937 (offset 127 lines).
    Hunk #3 succeeded at 1995 (offset 127 lines).
    Hunk #4 succeeded at 2645 (offset 110 lines).
    patching file src/evdev.h
    Hunk #1 FAILED at 222.
    Hunk #2 succeeded at 284 (offset -14 lines).
    1 out of 2 hunks FAILED — saving rejects to file src/evdev.h.rej

    Reply
    1. tonton9

      The src/evdev.h.rej you mentioned contains

      — src/evdev.h
      +++ src/evdev.h
      @@ -222,6 +222,17 @@ typedef struct {
      Time expires; /* time of expiry */
      Time timeout;
      } emulateWheel;
      + /* Button debouncing */
      + struct debounce {
      + Time delay;
      + OsTimerPtr timer;
      + BOOL bouncing;
      + struct {
      + BOOL pressed;
      + BOOL bouncing;
      + Time expiry;
      + } state[EVDEV_MAXBUTTONS];
      + } debounce;
      /* run-time calibration */
      struct {
      int min_x;

      Can the author or anyone provide a fix?

      Reply
  14. Jeffrey Taffuri

    I am a Mint 18.3 XFCE user who needs to apply this patch. I can follow the Terminal work but I don’t have a clue as to how to update the patch. I know I am probably asking much from the community but if there is a kind sole who could please provide the updated .deb file I would make a donation in your name to your preferred charity.

    Reply
  15. Sören Bindinger

    I found a -possibly- easier approach, by chance – but I’m not at all certain: will it work anywhere else?
    I’m now on MX Linux 17.1, XFCE4 desktop.
    Mainly with the RightMouseButton, I had that problem on Mint & Xubuntu before.
    These are the steps I took:

    sudo apt install xinput xbindkeys xautomation xev

    identify the button’s numbers:

    xev | grep ‘button’

    then, copied these 2 lines to ~/.xbindkeysrc (create the file, if not present):

    “/usr/bin/xte ” &”
    b:3 + Release

    for button 3 (RMB here, like probably in most cases)

    Pressing the RMB now pre-selects NO CONTEXT MENU ITEM AT ALL. That pre-selection made the following “Release” trigger the action from that item. The drawback is: you DO have to select the menu item manually …

    Reply
  16. Sören Bindinger

    NOTE: concerning my previous comment:

    the quotes between “xte” and ” &””:

    those are TWO SINGLE QUOTES

    Reply

Leave a Reply to tonton9 Cancel reply

Your email address will not be published. Required fields are marked *