My mouse has a fancy wheel. Can I use it in X?

Yes. But you need to customize X client programs. See Colas Nahaboo's web page (http://www.inria.fr/koala/colas/mouse-wheel-scroll/) .

If you want to use the imwheel program, just follow these simple steps.

  1. Translate the Wheel Events

    The imwheel program works by translating mouse button 4 and mouse button 5 events into key events. Thus, you have to get the mouse driver to translate mouse wheel events to button 4 and 5 events. There are two ways of doing this, the first way is to have moused(8) do the translation. The second way is for the X server itself to do the event translation.

    1. Using moused(8) to Translate Wheel Events

      To have moused(8) perform the event translations, simply add -z 4 to the command line used to start moused(8). For example, if you normally start moused(8) via moused -p /dev/psm0 you would start it by entering moused -p /dev/psm0 -z 4 instead. If you start moused(8) automatically during bootup via /etc/rc.conf, you can simply add -z 4 to the moused_flags variable in /etc/rc.conf.

      You now need to tell X that you have a 5 button mouse. To do this, simply add the line Buttons 5 to the ``Pointer'' section of /etc/XF86Config. For example, you might have the following ``Pointer'' section in /etc/XF86Config.

      Example 11-1. ``Pointer'' Section for Wheeled Mouse in XFree86 3.3.x series XF86Config with moused Translation

          Section "Pointer"
             Protocol        "SysMouse"
             Device          "/dev/sysmouse"
             Buttons         5
          EndSection
      

      Example 11-2. ``InputDevice'' Section for Wheeled Mouse in XFree86 4.x series XF86Config with X Server Translation

          Section "InputDevice"
             Identifier      "Mouse1"
             Driver          "mouse"
             Option          "Protocol" "auto"
             Option          "Device" "/dev/sysmouse"
             Option          "Buttons" "5"
          EndSection
      

      Example 11-3. ``.emacs'' example for naive page scrolling with Wheeled Mouse

          ;; wheel mouse
          (global-set-key [mouse-4] 'scroll-down)
          (global-set-key [mouse-5] 'scroll-up)
      
    2. Using Your X Server to Translate the Wheel Events

      If you are not running moused(8), or if you do not want moused(8) to translate your wheel events, you can have the X server do the event translation instead. This requires a couple of modifications to your /etc/XF86Config file. First, you need to choose the proper protocol for your mouse. Most wheeled mice use the ``IntelliMouse'' protocol. However, XFree86 does support other protocols, such as ``MouseManPlusPS/2'' for the Logitech MouseMan+ mice. Once you have chosen the protocol you will use, you need to add a Protocol line to the ``Pointer'' section.

      Secondly, you need to tell the X server to remap wheel scroll events to mouse buttons 4 and 5. This is done with the ZAxisMapping option.

      For example, if you are not using moused(8), and you have an IntelliMouse attached to the PS/2 mouse port you would use the following in /etc/XF86Config.

      Example 11-4. ``Pointer'' Section for Wheeled Mouse in XF86Config with X Server Translation

          Section "Pointer"
             Protocol        "IntelliMouse"
             Device          "/dev/psm0"
             ZAxisMapping    4 5
          EndSection
      

      Example 11-5. ``InputDevice'' Section for Wheeled Mouse in XFree86 4.x series XF86Config with X Server Translation

          Section "InputDevice"
             Identifier      "Mouse1"
             Driver          "mouse"
             Option          "Protocol" "auto"
             Option          "Device" "/dev/psm0"
             Option          "ZAxisMapping" "4 5"
          EndSection
      

      Example 11-6. ``.emacs'' example for naive page scrolling with Wheeled Mouse

          ;; wheel mouse
          (global-set-key [mouse-4] 'scroll-down)
          (global-set-key [mouse-5] 'scroll-up)
      
  2. Install imwheel

    Next, install imwheel from the Ports collection. It can be found in the x11 category. This program will map the wheel events from your mouse into keyboard events. For example, it might send Page Up to a program when you scroll the wheel forwards. Imwheel uses a configuration file to map the wheel events to key presses so that it can send different keys to different applications. The default imwheel configuration file is installed in /usr/X11R6/etc/imwheelrc. You can copy it to ~/.imwheelrc and then edit it if you wish to customize imwheel's configuration. The format of the configuration file is documented in imwheel(1).

  3. Configure Emacs to Work with Imwheel (optional)

    If you use emacs or Xemacs, then you need to add a small section to your ~/.emacs file. For emacs, add the following:

    Example 11-7. Emacs Configuration for Imwheel

        ;;; For imwheel
        (setq imwheel-scroll-interval 3)
        (defun imwheel-scroll-down-some-lines ()
          (interactive)
          (scroll-down imwheel-scroll-interval))
        (defun imwheel-scroll-up-some-lines ()
          (interactive)
          (scroll-up imwheel-scroll-interval))
        (global-set-key [?\M-\C-\)] 'imwheel-scroll-up-some-lines)
        (global-set-key [?\M-\C-\(] 'imwheel-scroll-down-some-lines)
        ;;; end imwheel section
    

    For Xemacs, add the following to your ~/.emacs file instead:

    Example 11-8. Xemacs Configuration for Imwheel

        ;;; For imwheel
        (setq imwheel-scroll-interval 3)
        (defun imwheel-scroll-down-some-lines ()
          (interactive)
          (scroll-down imwheel-scroll-interval))
        (defun imwheel-scroll-up-some-lines ()
          (interactive)
          (scroll-up imwheel-scroll-interval))
        (define-key global-map [(control meta \))] 'imwheel-scroll-up-some-lines)
        (define-key global-map [(control meta \()] 'imwheel-scroll-down-some-lines)
        ;;; end imwheel section
    
  4. Run Imwheel

    You can just type imwheel in an xterm to start it up once it is installed. It will background itself and take effect immediately. If you want to always use imwheel, simply add it to your .xinitrc or .xsession file. You can safely ignore any warnings imwheel displays about PID files. Those warnings only apply to the Linux version of imwheel.



UNIXguide.net
Suggest a Site