--get your your Linux knowledge
> Linux Reviews > Howtos > XFree configuration >

Mouse setup - Wheel and USB

XFree related mouse tips

  1. How to configure mice with a mousewheel and/or many buttons
  2. Hints on using USB mice

1. How to configure mice with a mousewheel and/or many buttons

The mouse is configured in the file /etc/X11/XF86Config-4 (On Gentoo /etc/X11/XF86Config). Use your favourite editor or your distributions X-configuration frontend.

You need to add or change a "InputDevice" section for your mouse.

The "InputDevice" section for XFree86 may look like this:

  Section "InputDevice"
  	Identifier  "Mouse0"
  	Driver      "mouse"
  		Option "Protocol"    "MouseManPlusPS/2"
  		Option  "Device"                "/dev/mouse"
  		Option  "Emulate3Buttons"       "no"
  		Option  "ZAxisMapping"          "4 5"
  		Option  "Buttons"               "5"

(This example configuration is for a 3 (5) button Logitech Cordless Mouse)

Mousewheels actually communicate with the computer as if it was two buttons, meaning that if your mouse has three buttons, it really has five. Four button mice has six, and so on.

This means the correct value for Buttons is two higher than what you have. The ZAxisMapping defines which of these buttons will be used for the mousewheel. Normally this is the last two. The first value means up, the second down: swap the values if the mousewheel scrolls the wrong way.

If you do not know what Protocol to use, try running xf86config . It's first question is regarding the mouse type. Just enter bogus values throughout the rest of the configuration, save the config to a alternative filename, and look at what values where given for your mouse.

Remapping the "buttons".

Strangely, XFree86 requires the mousewheel buttons to be the last who on the mouse. Some mice, like the 4 button Logitech Cordless Desktop Pro mouse, uses buttons 4 and 5 for the mousewheel. This means that if you use "ZAxisMapping" "4 5", what is the correct setup, the last button will be unusable. Instead, use a normal configuration. An example:

  Section "InputDevice"
          Identifier      "Mouse0"
          Driver          "mouse"
          Option          "Device"                "/dev/mouse"
          Option          "Protocol"              "MouseManPlusPS/2"
          Option          "Emulate3Buttons"       "no"
          Option          "ZAxisMapping"          "5 6"
          Option          "Buttons"               "6"

(This example configuration is for a 4 (6) button Logitech Cordless Desktop Pro Mouse)

This makes all the buttons usable, but the mousewheel is mapped all wrong. Scrolling down gives up, and the last (side) button functions as the down part of the mousewheel.

To solve this, use xmodmap -e "pointer = values" to remap the buttons in of your desktop init scripts (usually placed in /etc/X11/xdm/Xsession. You can also use /opt/kde/startkde or /usr/bin/startkde if you are using KDE, /usr/bin/gnome-session if you use Gnome. To find out where your startkde, Xsession or whatever is, type 'locate startkde'. locate is a very good tool to locate files). A valid xmodmap command:

  xmodmap -e "pointer = 1 6 3 2 4 5"

This remaps the mousewheel correct, and also remaps button three to button six. If this does not work with your mouse, then read the xmodmap manual page and experiment. You might even find the right values by reading your mouses manual, if it came with such a thing.

1.1. Wireless Intellimouse Explorer 2.0

This mouse has a total of 9 (7 + mousewheel) buttons. This configuration works:


  Section "InputDevice"
      Identifier  "Intellimouse"
      Driver      "mouse"
      Option        "Protocol" "ExplorerPS/2"
  # Change the device to point to the correct location!
  # I use the USB connection
      Option        "Device" "/dev/input/mice"
  # My Wireless Intellimouse Explorer 2.0
  # has 9 buttons counting the left/right tilt of the wheel
  # although I haven't succeeded in using the left/right 
  # tilt for anything yet.
      Option        "Buttons" "9"
  # The wheel needs to be the "last" two buttons (bug?)
      Option        "ZAxisMapping" "8 9"
  # Executable script /etc/X11/xinit/xinitrc.d/xmousebuttons contains:
  # /usr/X11R6/bin/xmodmap -e "pointer = 1 2 3 6 7 8 9 4 5"
  # Result is the scroll wheel and back/forward thumb buttons work.

Add /usr/X11R6/bin/xmodmap -e "pointer = 1 2 3 6 7 8 9 4 5" to your init script in order to remap the buttons correctly.

Big thanks to Jim Budler for sharing his configuration

2. Hints on using USB mice

Make sure you have the hotplug package running. There are hotplug packages available for most distributions, and many distributions has hotplugging set up by default.

Gentoo: emerge hotplug, make sure it is autoloaded with 'rc-update add hotplug default'. Start hotplugging with '/etc/init.d/hotplug start'.

With hotplugging, the modules for mice, joysticks, cameras and other usb devices are plug-and-play, as long as you compiled all the USB drivers as modules.

**Make sure USB support is compiled as a module or in the kernel (m or y). In general, it's a good idea to compile all USB modules (m).**

If you don't like hotplugging, you can add the modules to /etc/modules.conf (Gentoo: /etc/module.autoload), or manually load them via insmod.

Use /dev/usbmouse or /dev/input/mice with USB mice (IMPS/2).

To check if Linux knows about your usb mouse:

  ls /dev/input

Try cat /dev/input/something and move your mouse (garbage will appear if it's the right one). Press ctrl-c to cancel cat.

In /etc/X11/XF86Config</b>, use

  	Identifier  "USB Mice"
  	Driver      "mouse"
  	Option      "Protocol"   "IMPS/2"
  	Option      "Device"     "/dev/input/mice"
  	Option      "ZAxisMapping"   "4 5"
  	Option      "Buttons"        "5"

You may also need to add "SendCoreEvents" to the InputDevice line.

  InputDevice "USB Mice" "SendCoreEvents"

Meet new people