For Ubuntu 18.04 and later (which have middle mouse button emulation enabled by default):
Create a script called disable-middle-button-emulation
with following contents:
#!/bin/bash
to through all input devices
xinput list --id-only | while read id
do
# if this device supports middle button emulation, disable it (both evdev and libinput variants)
xinput --list-props "$id" | grep -qF "Evdev Middle Button Emulation" && xinput set-prop "$id" "Evdev Middle Button Emulation" 0
xinput --list-props "$id" | grep -qF "libinput Middle Button Emulation" && xinput set-prop "$id" "libinput Middle Button Emulation" 0
xinput --list-props "$id" | grep -qF "libinput Middle Emulation" && xinput set-prop "$id" "libinput Middle Emulation" 0
done
Then run chmod a+x disable-middle-button-emulation
to set execute enabled bit and then you can run it with ./disable-middle-button-emulation
. If you put the file in your home directory under subdirectory bin
, you don't need to prefix the command. As an alternative, you can put all of the above in file ~/.xsessionrc
which gets automatically executed whenever you start a new X session.
To verify the system behavior (before or after the above change), run xev
, move mouse pointer over the xev
window and press both left and right buttons simultaneously. If you get "button 2" (middle mouse button) in the terminal output, emulation is still active. You should get separate events for "button 1" (left mouse button) and "button 3" (right mouse button). Note that if the simulation is active, the event from pressing mouse button 1 or 3 down will be delayed 50 ms which causes extra lag for everything in the system. If you truly want to use emulation but reduce lag, you can modify the above script to look for Button Emulation Timeout
and adjust it to your liking. The default value is 50
which means 50 ms.