Skip to content

Instantly share code, notes, and snippets.

@dukechem
Created March 14, 2021 15:14
Show Gist options
  • Save dukechem/600965ea649b0c85fac922fcc7d9d989 to your computer and use it in GitHub Desktop.
Save dukechem/600965ea649b0c85fac922fcc7d9d989 to your computer and use it in GitHub Desktop.
Inadvertent middle-button on touchpad closes browser tabs, pastes in terminal. Add lines below to .bashrc to Disable mouse middle button emulation by touchpad
# Disable mouse middle button emulation by touchpad
# Add these lines to your .bashrc on linux. Tested with debian
# You may need to change $5 to $6 as explained here:
# Ref: https://forums.linuxmint.com/viewtopic.php?t=284009
# xinput --set-prop (your id number) (your libinput Middle Emulation Enabled number) 1
# That is, setting "Emulation Enabled" to "1" actually disables emulation (confusingly).
# If `xinput not found` then `sudo apt install xinput` or alternatively
# `brew install xinput`
# XINP="/home/linuxbrew/.linuxbrew/bin/xinput"
XINP=$(which xinput)
TOUCHPAD_ID=$($XINP | grep -i Touchpad | awk '{print $6}' | sed 's/id=//g')
MIDDLE_BUTTON_ID=$( $XINP --list-props $TOUCHPAD_ID | grep -i Middle | grep -vi Default | sed 's/[(|):]//g' | awk '{print $5}')
$XINP --set-prop $TOUCHPAD_ID $MIDDLE_BUTTON_ID 1
@dukechem
Copy link
Author

To see how or if it works...

Try it manually

 $ which xinput
/usr/bin/xinput
$ xinput | grep -i touchpad
⎜   ↳ SynPS/2 Synaptics TouchPad              	id=13	[slave  pointer  (2)]
$ xinput --list-props 12 | grep -i middle
$ xinput --list-props 13 | grep -i middle
	libinput Middle Emulation Enabled (333):	0
	libinput Middle Emulation Enabled Default (334):	0

before and after

$ xinput --list-props 13 | grep -i middle
	libinput Middle Emulation Enabled (333):	0
	libinput Middle Emulation Enabled Default (334):	0
$ source ~/.bashrc  # above is before ever running script and below is after running script.
$ xinput --list-props 13 | grep -i middle
	libinput Middle Emulation Enabled (333):	1
	libinput Middle Emulation Enabled Default (334):	0
$ # first prop is now 1 (insteadof 0) and 1 is what we want to actually disable middle-button emulation. Go figure. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment