Mouse button mapping in Xorg.conf

I purchased a Logitech G400 mouse to temporarily replace my Logitech MX Anywhere mouse, which I forgot at home. I wanted to use the top button for pasting instead of the scroll wheel button, which I feel is too hard to press.

This command solves the problem, by swapping the functions of button 2 (the scrollwheel button) and 10 (the top button):

$ xmodmap -e "pointer = 1 10 3 4 5 6 7 8 9 2"

The trick is that I want it done automatically when I use the G400.

My Debian Wheezy installation didn’t have a xorg.conf file, but there is nowadays an option to put specific conf snippets in /etc/X11/xorg.conf.d/*.conf:

$ mkdir /etc/X11/xorg.conf.d
$ vi /etc/X11/xorg.conf.d/LogitechG400.conf

There are a few directives in the InputClass section that can match device attributes. I used MatchProduct and MatchIsPointer (to be safe). You can just as well use MatchUSBID, I guess. These are the contents of my /etc/X11/xorg.conf-d/LogitechG400.conf file:

Section "InputClass"
Identifier "evdev mouse"
MatchProduct "Logitech Gaming Mouse G400"
MatchIsPointer "true"
Option "ButtonMapping" "1 10 3 4 5 6 7 8 9 2"
EndSection

The ButtonMapping option swaps the function of button 2 (the scrollwheel button) and 10 (the top button).

Now I can paste using the top button with the G400 mouse.