How to Disable Middle Mouse Button in Ubuntu / Debian Linux
Like many things in Linux+GNU some users absolutely love the middle click - close-tab or paste feature of the mouse being set by default. Others absolutely hate it!
The problem in this case is: apparently there is no easy way to disable the mouse middle-click through any graphical settings tools of Ubuntu.
But as always, with Linux+GNU - there is a way. Here's a quick post about disabling the middle mouse button in Ubuntu or Debian Linux. This method would likely work with non Debian based distros as well, but I haven't tested it.
I've seen a few approaches to accomplish the disabling but the one I was able to get working is by using a custom xorg.conf file in Ubuntu 18.10.
The first thing one needs to figure out to disable the middle click is what button it's numbered as on in the 'xinput' command. Once we find that out, we set that number position to '0'.
You may need to install xinput with:
$ sudo apt install xinput
Try this command in the terminal (ctrl+alt+t) to see what your current pointer mapping is:
$ pointers=$(xinput --list --name-only|egrep -i 'touchpad|mouse'|sed 's/\ /_/g'); \ echo;echo "Button Maps:";for i in $(echo "$pointers");do echo "$i"|sed 's/_/\ /g'; \ xinput get-button-map "$(echo $i|sed 's/_/\ /g')";done;echo
example output:
What I figured out for my machine, in order to disable the middle-click, was that I needed to change my xinput mapping for the mouse to: '1 0 3 4 5 6 7'. The "0" in place of the "2" - disables the middle click for my USB mouse. This setting also worked for the Touchpad.
I can achieve this setting by simply running this command:
But, as I've seen asked so much out there - without any seemingly clear answer - is: How do I make this setting permanent so I don't have to run the xinput command every time I login?
$ xinput set-button-map 'PixArt Dell MS116 USB Optical Mouse' 1 0 3 4 5 6 7
But, as I've seen asked so much out there - without any seemingly clear answer - is: How do I make this setting permanent so I don't have to run the xinput command every time I login?
The answer is to create a custom xorg.conf file and place it in either /etc/X11/xorg.conf or /etc/X11/xorg.conf.d/somefilename.conf.
What I did was to simply create a file named (will have to use sudo to edit):
sudo vi /etc/X11/xorg.conf.d/disable-mouse-middle-click.conf
With contents:
Section "InputClass" Identifier "USB Pointer" MatchIsPointer "true" Option "ButtonMapping" "1 0 3 4 5 6 7" EndSection Section "InputClass" Identifier "TouchPad Pointer" MatchIsTouchpad "true" Option "ButtonMapping" "1 0 3 4 5 6 7" EndSection
Then top it off with "Ctrl-Alt-Backspace" to restart my session. Checkout this link to enable it if it's not already.
Here's the text for a script to help you set it up:
#Finally Disable middle click with a custom xorg.conf #By Shannon VanWagner #3/21/2019 #humans-enabled.com if [ $# -eq 0 ]; then echo echo "$(basename $0): Disable pointer-middle-click w/cust. xorg.conf" echo echo "To install the fix run:" echo "$0 -i" echo echo "To remove the fix run:" echo "$0 -r" echo fi xconfCustom='/etc/X11/xorg.conf.d/disable-mouse-middle-click.conf' xconfDir='/etc/X11/xorg.conf.d' if [ "$1" = "-i" ]; then while true; do if [ ! -d "$xconfDir" ]; then echo "Whoops! $xconfDir doesn't exist. Creating it with sudo..." sudo mkdir $xconfDir else echo "$xconfDir directory exists. This is good." break; fi done while true; do if [ ! -f "$xconfCustom" ]; then echo "Creating custom xconf file to disable middle click." echo "New file name: $xconfCustom" echo "Creating custom xconf file with the text below." echo "File name: $xconfCustom" echo echo '#Disable Middle Click - By vanwagner Section "InputClass" Identifier "USB Pointer" MatchIsPointer "true" Option "ButtonMapping" "1 0 3 4 5 6 7" EndSection Section "InputClass" Identifier "TouchPad Pointer" MatchIsTouchpad "true" Option "ButtonMapping" "1 0 3 4 5 6 7" EndSection' | sudo tee $xconfCustom echo else echo "Middle-click disabling xconf file is installed." echo "File name: $xconfCustom" echo "Enable changes w/ session restart (ctrl-alt-backspace if enabled)." break; fi done fi if [ "$1" = "-r" ]; then echo "Removing cust. xorg.conf file, sudo may be needed:" echo "File name: $xconfCustom" sudo rm -rf $xconfCustom if [ ! -f "$xconfCustom" ]; then echo "Custom xconf has been removed or doesn't exist." echo "Enable changes w/ session restart (ctrl-alt-backspace if enabled)." fi fi
Cheers!
Shannon VanWagner
3/22/2019
The "virtual middle click" on my touchpad has really been bothering me so this was really helpful, thanks!
ReplyDeleteMy system doesn't have a xorg.conf.d directory so I added `xinput set-button-map...` as a startup command and it seems to work as expected