428
|
1 ;;; mwheel.el --- Mouse support for MS intelli-mouse type mice
|
|
2
|
|
3 ;; Copyright (C) 1998, Free Software Foundation, Inc.
|
|
4 ;; Maintainer: William M. Perry <wmperry@cs.indiana.edu>
|
|
5 ;; Keywords: mouse
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
458
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the
|
428
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Synched up with: Not synched.
|
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; This code will enable the use of the infamous 'wheel' on the new
|
|
29 ;; crop of mice. Under XFree86 and the XSuSE X Servers, the wheel
|
|
30 ;; events are sent as button4/button5 events.
|
|
31
|
|
32 ;; I for one would prefer some way of converting the button4/button5
|
|
33 ;; events into different event types, like 'mwheel-up' or
|
|
34 ;; 'mwheel-down', but I cannot find a way to do this very easily (or
|
|
35 ;; portably), so for now I just live with it.
|
|
36
|
|
37 ;; To enable this code, simply put this at the top of your .emacs
|
|
38 ;; file:
|
|
39 ;;
|
|
40 ;; (autoload 'mwheel-install "mwheel" "Enable mouse wheel support.")
|
|
41 ;; (mwheel-install)
|
|
42
|
|
43 ;;; Code:
|
|
44
|
|
45 (require 'custom)
|
|
46 (require 'cl)
|
|
47
|
502
|
48 (globally-declare-fboundp
|
|
49 '(event-basic-type
|
|
50 posn-window event-start mwheel-event-window mwheel-event-button))
|
|
51
|
1621
|
52 (defcustom mwheel-scroll-amount '(5 1 nil)
|
428
|
53 "Amount to scroll windows by when spinning the mouse wheel.
|
1621
|
54 A list with 3 elements specifying the amount to scroll on: a normal wheel
|
|
55 event, a wheel event with the shift key pressed, and a wheel event with the
|
|
56 control key pressed, in that order.
|
428
|
57
|
|
58 Each item should be the number of lines to scroll, or `nil' for near
|
|
59 full screen.
|
|
60 A near full screen is `next-screen-context-lines' less than a full screen."
|
|
61 :group 'mouse
|
1621
|
62 :type '(list
|
428
|
63 (choice :tag "Normal"
|
|
64 (const :tag "Full screen" :value nil)
|
|
65 (integer :tag "Specific # of lines"))
|
|
66 (choice :tag "Shifted"
|
|
67 (const :tag "Full screen" :value nil)
|
1621
|
68 (integer :tag "Specific # of lines"))
|
|
69 (choice :tag "Controlled"
|
|
70 (const :tag "Full screen" :value nil)
|
428
|
71 (integer :tag "Specific # of lines"))))
|
|
72
|
|
73 (defcustom mwheel-follow-mouse nil
|
|
74 "Whether the mouse wheel should scroll the window that the mouse is over.
|
|
75 This can be slightly disconcerting, but some people may prefer it."
|
|
76 :group 'mouse
|
|
77 :type 'boolean)
|
|
78
|
|
79 (if (not (fboundp 'event-button))
|
|
80 (defun mwheel-event-button (event)
|
|
81 (let ((x (symbol-name (event-basic-type event))))
|
|
82 (if (not (string-match "^mouse-\\([0-9]+\\)" x))
|
|
83 (error "Not a button event: %S" event))
|
|
84 (string-to-int (substring x (match-beginning 1) (match-end 1)))))
|
|
85 (fset 'mwheel-event-button 'event-button))
|
|
86
|
|
87 (if (not (fboundp 'event-window))
|
|
88 (defun mwheel-event-window (event)
|
|
89 (posn-window (event-start event)))
|
|
90 (fset 'mwheel-event-window 'event-window))
|
|
91
|
|
92 (defun mwheel-scroll (event)
|
|
93 (interactive "e")
|
|
94 (let ((curwin (if mwheel-follow-mouse
|
|
95 (prog1
|
|
96 (selected-window)
|
|
97 (select-window (mwheel-event-window event)))))
|
|
98 (amt (if (memq 'shift (event-modifiers event))
|
1621
|
99 (cadr mwheel-scroll-amount)
|
|
100 (if (memq 'control (event-modifiers event))
|
|
101 (caddr mwheel-scroll-amount)
|
|
102 (car mwheel-scroll-amount)))))
|
458
|
103 (unwind-protect
|
|
104 (case (mwheel-event-button event)
|
|
105 (4 (scroll-down amt))
|
|
106 (5 (scroll-up amt))
|
|
107 (otherwise (error "Bad binding in mwheel-scroll")))
|
|
108 (if curwin (select-window curwin)))
|
|
109 ))
|
428
|
110
|
|
111 ;;;###autoload
|
|
112 (defun mwheel-install ()
|
|
113 "Enable mouse wheel support."
|
444
|
114 (interactive)
|
1621
|
115 (let ((keys '([(mouse-4)] [(shift mouse-4)] [(control mouse-4)]
|
|
116 [(mouse-5)] [(shift mouse-5)] [(control mouse-5)])))
|
|
117
|
428
|
118 ;; This condition-case is here because Emacs 19 will throw an error
|
|
119 ;; if you try to define a key that it does not know about. I for one
|
|
120 ;; prefer to just unconditionally do a mwheel-install in my .emacs, so
|
|
121 ;; that if the wheeled-mouse is there, it just works, and this way it
|
|
122 ;; doesn't yell at me if I'm on my laptop or another machine, etc.
|
|
123 (condition-case ()
|
|
124 (while keys
|
|
125 (define-key global-map (car keys) 'mwheel-scroll)
|
|
126 (setq keys (cdr keys)))
|
|
127 (error nil))))
|
458
|
128
|
2546
|
129 ;;;###autoload
|
|
130 (define-behavior 'mwheel
|
|
131 "This code enables the use of the infamous 'wheel' on the new
|
|
132 crop of mice. Under XFree86 and the XSuSE X Servers, the wheel
|
|
133 events are sent as button4/button5 events, which are automatically
|
|
134 set up to do scrolling in the expected way. The actual way that the
|
|
135 scrolling works can be controlled by `mwheel-scroll-amount' and
|
|
136 `mwheel-follow-mouse'."
|
|
137 :group 'mouse
|
|
138 :short-doc "Mouse wheel support for X Windows"
|
|
139 :enable 'mwheel-install)
|
|
140
|
428
|
141 (provide 'mwheel)
|
|
142
|
|
143 ;;; mwheel.el ends here
|