Mercurial > hg > xemacs-beta
comparison lisp/packages/avoid.el @ 2:ac2d302a0011 r19-15b2
Import from CVS: tag r19-15b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:35 +0200 |
parents | 376386a54a3c |
children | 9ee227acff29 |
comparison
equal
deleted
inserted
replaced
1:c0c6a60d29db | 2:ac2d302a0011 |
---|---|
1 ;;; avoid.el --- make mouse pointer stay out of the way of editing. | 1 ;;; avoid.el --- make mouse pointer stay out of the way of editing |
2 | 2 |
3 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. | 3 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Boris Goldowsky <boris@cs.rochester.edu> | 5 ;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu> |
6 ;; Keywords: mouse | 6 ;; Keywords: mouse |
7 ;; Version: 1.10 | 7 ;; Version: 1.10 |
8 | 8 |
9 ;; This file is part of XEmacs. | 9 ;; This file is part of XEmacs. |
10 | 10 |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 ;; General Public License for more details. | 19 ;; General Public License for more details. |
20 | 20 |
21 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 22 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
24 | 24 ;; 02111-1307, USA. |
25 ;;; Synched up with: FSF 19.28. | 25 |
26 ;;; Synched up with: FSF 19.34. | |
26 | 27 |
27 ;;; Commentary: | 28 ;;; Commentary: |
28 ;;; | 29 |
29 ;;; For those who are annoyed by the mouse pointer obscuring text, | 30 ;; For those who are annoyed by the mouse pointer obscuring text, |
30 ;;; this mode moves the mouse pointer - either just a little out of | 31 ;; this mode moves the mouse pointer - either just a little out of |
31 ;;; the way, or all the way to the corner of the frame. | 32 ;; the way, or all the way to the corner of the frame. |
32 ;;; To use, load or evaluate this file and type M-x mouse-avoidance-mode . | 33 ;; To use, load or evaluate this file and type M-x mouse-avoidance-mode . |
33 ;;; To set up permanently, put this file on your load-path and put the | 34 ;; To set up permanently, put this file on your .emacs: |
34 ;;; following in your .emacs: | 35 ;; |
35 ;;; | 36 ;; (if window-system (mouse-avoidance-mode 'animate)) |
36 ;;; (cond (window-system | 37 ;; |
37 ;;; (require 'avoid) | 38 ;; The 'animate can be 'jump or 'banish or 'exile or 'protean if you prefer. |
38 ;;; (mouse-avoidance-mode 'animate))) | 39 ;; See the documentation for function `mouse-avoidance-mode' for |
39 ;;; | 40 ;; details of the different modes. |
40 ;;; The 'animate can be 'jump or 'banish or 'exile or 'protean if you prefer. | 41 ;; |
41 ;;; See the documentation for function `mouse-avoidance-mode' for | 42 ;; For added silliness, make the animatee animate... |
42 ;;; details of the different modes. | 43 ;; put something similar to the following into your .emacs: |
43 ;;; | 44 ;; |
44 ;;; For added silliness, make the animatee animate... | 45 ;; (if window-system |
45 ;;; put something similar to the following into your .emacs: | 46 ;; (mouse-avoidance-set-pointer-shape |
46 ;;; | 47 ;; (eval (nth (random 4) |
47 ;;; (cond (window-system | 48 ;; '(x-pointer-man x-pointer-spider |
48 ;;; (setq x-pointer-shape | 49 ;; x-pointer-gobbler x-pointer-gumby))))) |
49 ;;; (eval (nth (random 4) | 50 ;; |
50 ;;; '(x-pointer-man x-pointer-spider | 51 ;; For completely random pointer shape, replace the setq above with: |
51 ;;; x-pointer-gobbler x-pointer-gumby)))) | 52 ;; (setq x-pointer-shape (mouse-avoidance-random-shape)) |
52 ;;; (set-mouse-color (cdr (assoc 'mouse-color (frame-parameters)))))) | 53 ;; |
53 ;;; | 54 ;; Bugs / Warnings / To-Do: |
54 ;;; For completely random pointer shape, replace the setq above with: | 55 ;; |
55 ;;; (setq x-pointer-shape (mouse-avoidance-random-shape)) | 56 ;; - Using this code does slow emacs down. "banish" mode shouldn't |
56 ;;; | 57 ;; be too bad, and on my workstation even "animate" is reasonable. |
57 ;;; Bugs / Warnings / To-Do: | 58 ;; |
58 ;;; | 59 ;; - It ought find out where any overlapping frames are and avoid them, |
59 ;;; - Using this code does slow emacs down. "banish" mode shouldn't | 60 ;; rather than always raising the frame. |
60 ;;; ever be too bad though, and on my workstation even "animate" doesn't | 61 |
61 ;;; seem to have a noticable effect during editing. | 62 ;; Credits: |
62 ;;; | 63 ;; This code was helped by all those who contributed suggestions, |
63 ;;; - It should find out where any overlapping frames are and avoid them, | 64 ;; fixes, and additions |
64 ;;; rather than always raising the frame. | 65 ;; Joe Harrington (and his advisor), for the original inspiration. |
65 | 66 ;; Ken Manheimer, for dreaming up the Protean mode. |
66 ;;; Credits: | 67 ;; Richard Stallman, for the awful cat-and-mouse pun, among other things. |
67 ;;; This code was helped by all those who contributed suggestions, | 68 ;; Mike Williams, Denis Howe, Bill Benedetto, Chris Moore, Don Morris, |
68 ;;; fixes, and additions | 69 ;; Simon Marshall, and M.S. Ashton, for their feedback. |
69 ;;; Joe Harrington (and his advisor), for the original inspiration. | 70 |
70 ;;; Ken Manheimer, for dreaming up the Protean mode. | |
71 ;;; Richard Stallman, for the awful cat-and-mouse pun, among other things. | |
72 ;;; Mike Williams, Denis Howe, Bill Benedetto, Chris Moore, Don Morris, | |
73 ;;; Simon Marshall, and M.S. Ashton, for their feedback. | |
74 ;;; | |
75 ;;; Code: | 71 ;;; Code: |
76 | 72 |
77 (provide 'avoid) | 73 (provide 'avoid) |
78 | 74 |
79 (defvar mouse-avoidance-mode nil | 75 (defvar mouse-avoidance-mode nil |
100 | 96 |
101 ;; Internal variables | 97 ;; Internal variables |
102 (defvar mouse-avoidance-state nil) | 98 (defvar mouse-avoidance-state nil) |
103 (defvar mouse-avoidance-pointer-shapes nil) | 99 (defvar mouse-avoidance-pointer-shapes nil) |
104 (defvar mouse-avoidance-n-pointer-shapes 0) | 100 (defvar mouse-avoidance-n-pointer-shapes 0) |
101 (defvar mouse-avoidance-old-pointer-shape nil) | |
105 | 102 |
106 ;;; Functions: | 103 ;;; Functions: |
107 | 104 |
108 ;; XEmacs change -- this is so ugly. | 105 (defsubst mouse-avoidance-set-pointer-shape (shape) |
106 "Set the shape of the mouse pointer to SHAPE." | |
107 (setq x-pointer-shape shape) | |
108 (set-mouse-color nil)) | |
109 | |
110 ;; XEmacs change -- this is so ugly. [FSF version is totally different -sb] | |
109 (defun mouse-avoidance-point-position () | 111 (defun mouse-avoidance-point-position () |
110 "Returns (WINDOW X . Y) of current point - analogous to mouse-position" | 112 "Returns (WINDOW X . Y) of current point - analogous to mouse-position" |
111 (let* ((beg (window-start)) | 113 (let* ((beg (window-start)) |
112 (pos (point)) | 114 (pos (point)) |
113 (col (current-column)) | 115 (col (current-column)) |
127 ;; leave the mouse where it was. However, this is currently | 129 ;; leave the mouse where it was. However, this is currently |
128 ;; difficult to do, so we just raise the frame to avoid frame switches. | 130 ;; difficult to do, so we just raise the frame to avoid frame switches. |
129 ;; Returns t if it moved the mouse. | 131 ;; Returns t if it moved the mouse. |
130 (let ((f (selected-frame))) | 132 (let ((f (selected-frame))) |
131 (raise-frame f) | 133 (raise-frame f) |
134 ;; XEmacs: FSF version of set-mouse-position requires FRAME parameter | |
132 (set-mouse-position (frame-selected-window f) (car pos) (cdr pos)) | 135 (set-mouse-position (frame-selected-window f) (car pos) (cdr pos)) |
133 t)) | 136 t)) |
134 | 137 |
135 (defun mouse-avoidance-too-close-p (mouse) | 138 (defun mouse-avoidance-too-close-p (mouse) |
136 ;; Return t if mouse pointer and point cursor are too close. | 139 ;; Return t if mouse pointer and point cursor are too close. |
156 (defsubst mouse-avoidance-delta (cur delta dist var min max) | 159 (defsubst mouse-avoidance-delta (cur delta dist var min max) |
157 ;; Decide how far to move in either dimension. | 160 ;; Decide how far to move in either dimension. |
158 ;; Args are the CURRENT location, the desired DELTA for | 161 ;; Args are the CURRENT location, the desired DELTA for |
159 ;; warp-conservation, the DISTANCE we like to move, the VARIABILITY | 162 ;; warp-conservation, the DISTANCE we like to move, the VARIABILITY |
160 ;; in distance allowed, and the MIN and MAX possible window positions. | 163 ;; in distance allowed, and the MIN and MAX possible window positions. |
161 ;; Returns something as close to DELTA as possible withing the constraints. | 164 ;; Returns something as close to DELTA as possible within the constraints. |
162 (let ((L1 (max (- min cur) (+ (- dist) (- var)))) | 165 (let ((L1 (max (- min cur) (+ (- dist) (- var)))) |
163 (R1 (+ (- dist) var )) | 166 (R1 (+ (- dist) var )) |
164 (L2 (+ dist (- var))) | 167 (L2 (+ dist (- var))) |
165 (R2 (min (- max cur) (+ dist var)))) | 168 (R2 (min (- max cur) (+ dist var)))) |
166 (if (< R1 (- min cur)) (setq L1 nil R1 nil)) | 169 (if (< R1 (- min cur)) (setq L1 nil R1 nil)) |
177 (defun mouse-avoidance-nudge-mouse () | 180 (defun mouse-avoidance-nudge-mouse () |
178 ;; Push the mouse a little way away, possibly animating the move | 181 ;; Push the mouse a little way away, possibly animating the move |
179 ;; For these modes, state keeps track of the total offset that we've | 182 ;; For these modes, state keeps track of the total offset that we've |
180 ;; accumulated, and tries to keep it close to zero. | 183 ;; accumulated, and tries to keep it close to zero. |
181 (let* ((cur (mouse-position)) | 184 (let* ((cur (mouse-position)) |
185 (cur-frame (car cur)) | |
182 (cur-pos (cdr cur)) | 186 (cur-pos (cdr cur)) |
183 (deltax (mouse-avoidance-delta | 187 (deltax (mouse-avoidance-delta |
184 (car cur-pos) (- (random mouse-avoidance-nudge-var) | 188 (car cur-pos) (- (random mouse-avoidance-nudge-var) |
185 (car mouse-avoidance-state)) | 189 (car mouse-avoidance-state)) |
186 mouse-avoidance-nudge-dist mouse-avoidance-nudge-var | 190 mouse-avoidance-nudge-dist mouse-avoidance-nudge-var |
187 0 (frame-width))) | 191 0 (frame-width))) |
188 (deltay (mouse-avoidance-delta | 192 (deltay (mouse-avoidance-delta |
189 (cdr cur-pos) (- (random mouse-avoidance-nudge-var) | 193 (cdr cur-pos) (- (random mouse-avoidance-nudge-var) |
190 (cdr mouse-avoidance-state)) | 194 (cdr mouse-avoidance-state)) |
191 mouse-avoidance-nudge-dist mouse-avoidance-nudge-var | 195 mouse-avoidance-nudge-dist mouse-avoidance-nudge-var |
192 0 (window-height)))) | 196 0 (frame-height)))) |
193 (setq mouse-avoidance-state | 197 (setq mouse-avoidance-state |
194 (cons (+ (car mouse-avoidance-state) deltax) | 198 (cons (+ (car mouse-avoidance-state) deltax) |
195 (+ (cdr mouse-avoidance-state) deltay))) | 199 (+ (cdr mouse-avoidance-state) deltay))) |
196 (if (or (eq mouse-avoidance-mode 'animate) | 200 (if (or (eq mouse-avoidance-mode 'animate) |
197 (eq mouse-avoidance-mode 'proteus)) | 201 (eq mouse-avoidance-mode 'proteus)) |
198 (let ((i 0.0) | 202 (let ((i 0.0) |
203 ;; XEmacs change | |
199 (color (cdr (assoc 'mouse-color (frame-parameters))))) | 204 (color (cdr (assoc 'mouse-color (frame-parameters))))) |
200 (while (<= i 1) | 205 (while (<= i 1) |
201 (mouse-avoidance-set-mouse-position | 206 (mouse-avoidance-set-mouse-position |
202 (cons (+ (car cur-pos) (round (* i deltax))) | 207 (cons (+ (car cur-pos) (round (* i deltax))) |
203 (+ (cdr cur-pos) (round (* i deltay))))) | 208 (+ (cdr cur-pos) (round (* i deltay))))) |
204 (setq i (+ i (max .1 (/ 1.0 mouse-avoidance-nudge-dist)))) | 209 (setq i (+ i (max .1 (/ 1.0 mouse-avoidance-nudge-dist)))) |
205 (if (eq mouse-avoidance-mode 'proteus) | 210 (if (eq mouse-avoidance-mode 'proteus) |
211 ;; XEmacs change | |
206 (progn | 212 (progn |
207 (setq x-pointer-shape (mouse-avoidance-random-shape)) | 213 (setq x-pointer-shape (mouse-avoidance-random-shape)) |
208 (set-mouse-color color))) | 214 (set-mouse-color color))) |
209 (sit-for mouse-avoidance-animation-delay))) | 215 (sit-for mouse-avoidance-animation-delay))) |
210 (mouse-avoidance-set-mouse-position (cons (+ (car (cdr cur)) deltax) | 216 (mouse-avoidance-set-mouse-position (cons (+ (car (cdr cur)) deltax) |
243 (mouse-avoidance-too-close-p mp)) | 249 (mouse-avoidance-too-close-p mp)) |
244 (setq mouse-avoidance-state mp) | 250 (setq mouse-avoidance-state mp) |
245 (mouse-avoidance-banish-mouse)) | 251 (mouse-avoidance-banish-mouse)) |
246 ((and mouse-avoidance-state | 252 ((and mouse-avoidance-state |
247 (not (mouse-avoidance-too-close-p mouse-avoidance-state))) | 253 (not (mouse-avoidance-too-close-p mouse-avoidance-state))) |
254 ;; XEmacs change | |
248 (if (and (eq (car mp) (if (< emacs-minor-version 12) | 255 (if (and (eq (car mp) (if (< emacs-minor-version 12) |
249 (selected-frame) | 256 (selected-frame) |
250 (selected-window))) | 257 (selected-window))) |
251 (equal (cdr mp) (mouse-avoidance-banish-destination))) | 258 (equal (cdr mp) (mouse-avoidance-banish-destination))) |
252 (mouse-avoidance-set-mouse-position | 259 (mouse-avoidance-set-mouse-position |
260 (if (and (not executing-kbd-macro) ; don't check inside macro | 267 (if (and (not executing-kbd-macro) ; don't check inside macro |
261 (mouse-avoidance-kbd-command (this-command-keys)) | 268 (mouse-avoidance-kbd-command (this-command-keys)) |
262 (mouse-avoidance-too-close-p (mouse-position))) | 269 (mouse-avoidance-too-close-p (mouse-position))) |
263 (let ((old-pos (mouse-position))) | 270 (let ((old-pos (mouse-position))) |
264 (mouse-avoidance-nudge-mouse) | 271 (mouse-avoidance-nudge-mouse) |
272 ;; XEmacs change | |
265 (if (not (eq (if (< emacs-minor-version 12) | 273 (if (not (eq (if (< emacs-minor-version 12) |
266 (selected-frame) | 274 (selected-frame) |
267 (selected-window)) (car old-pos))) ; move went awry | 275 (selected-window)) (car old-pos))) ; move went awry |
268 (set-mouse-position (car old-pos) ; sigh.. | 276 (set-mouse-position (car old-pos) ; sigh.. |
269 (car (cdr old-pos)) | 277 (car (cdr old-pos)) |
282 (if (listp (aref key i)) | 290 (if (listp (aref key i)) |
283 (throw 'done nil)) | 291 (throw 'done nil)) |
284 (setq i (1+ i)))) | 292 (setq i (1+ i)))) |
285 t)))) | 293 t)))) |
286 | 294 |
295 ;;;###autoload | |
287 (defun mouse-avoidance-mode (&optional mode) | 296 (defun mouse-avoidance-mode (&optional mode) |
288 "Set cursor avoidance mode to MODE. | 297 "Set cursor avoidance mode to MODE. |
289 MODE should be one of the symbols `banish', `exile', `jump', `animate', | 298 MODE should be one of the symbols `banish', `exile', `jump', `animate', |
290 `cat-and-mouse', `proteus', or `none'. | 299 `cat-and-mouse', `proteus', or `none'. |
291 | 300 |
314 '(("banish") ("exile") ("jump") ("animate") | 323 '(("banish") ("exile") ("jump") ("animate") |
315 ("cat-and-mouse") ("proteus") ("none")) | 324 ("cat-and-mouse") ("proteus") ("none")) |
316 nil t)))) | 325 nil t)))) |
317 (if (eq mode 'cat-and-mouse) | 326 (if (eq mode 'cat-and-mouse) |
318 (setq mode 'animate)) | 327 (setq mode 'animate)) |
319 (setq post-command-hook | 328 ;; XEmacs change - We don't have post-command-idle-hook |
320 (delete 'mouse-avoidance-banish-hook (append post-command-hook nil))) | 329 (remove-hook 'post-command-hook 'mouse-avoidance-banish-hook) |
321 (setq post-command-hook | 330 (remove-hook 'post-command-hook 'mouse-avoidance-exile-hook) |
322 (delete 'mouse-avoidance-exile-hook (append post-command-hook nil))) | 331 (remove-hook 'post-command-hook 'mouse-avoidance-fancy-hook) |
323 (setq post-command-hook | 332 ;; Restore pointer shape if necessary |
324 (delete 'mouse-avoidance-fancy-hook (append post-command-hook nil))) | 333 (if (eq mouse-avoidance-mode 'proteus) |
334 (mouse-avoidance-set-pointer-shape mouse-avoidance-old-pointer-shape)) | |
335 | |
336 ;; Do additional setup depending on version of mode requested | |
325 (cond ((eq mode 'none) | 337 (cond ((eq mode 'none) |
326 (setq mouse-avoidance-mode nil)) | 338 (setq mouse-avoidance-mode nil)) |
327 ((or (eq mode 'jump) | 339 ((or (eq mode 'jump) |
328 (eq mode 'animate) | 340 (eq mode 'animate) |
329 (eq mode 'proteus)) | 341 (eq mode 'proteus)) |
342 ;; XEmacs: we don't have post-command-idle-hook | |
330 (add-hook 'post-command-hook 'mouse-avoidance-fancy-hook) | 343 (add-hook 'post-command-hook 'mouse-avoidance-fancy-hook) |
331 (setq mouse-avoidance-mode mode | 344 (setq mouse-avoidance-mode mode |
332 mouse-avoidance-state (cons 0 0))) | 345 mouse-avoidance-state (cons 0 0) |
346 mouse-avoidance-old-pointer-shape x-pointer-shape)) | |
333 ((eq mode 'exile) | 347 ((eq mode 'exile) |
348 ;; XEmacs: FSF uses post-command-idle-hook | |
334 (add-hook 'post-command-hook 'mouse-avoidance-exile-hook) | 349 (add-hook 'post-command-hook 'mouse-avoidance-exile-hook) |
335 (setq mouse-avoidance-mode mode | 350 (setq mouse-avoidance-mode mode |
336 mouse-avoidance-state nil)) | 351 mouse-avoidance-state nil)) |
337 ((or (eq mode 'banish) | 352 ((or (eq mode 'banish) |
338 (eq mode t) | 353 (eq mode t) |
339 (and (null mode) (null mouse-avoidance-mode)) | 354 (and (null mode) (null mouse-avoidance-mode)) |
340 (and mode (> (prefix-numeric-value mode) 0))) | 355 (and mode (> (prefix-numeric-value mode) 0))) |
356 ;; XEmacs: FSF uses post-command-idle-hook | |
341 (add-hook 'post-command-hook 'mouse-avoidance-banish-hook) | 357 (add-hook 'post-command-hook 'mouse-avoidance-banish-hook) |
342 (setq mouse-avoidance-mode 'banish)) | 358 (setq mouse-avoidance-mode 'banish)) |
343 (t (setq mouse-avoidance-mode nil))) | 359 (t (setq mouse-avoidance-mode nil))) |
344 (force-mode-line-update)) | 360 (force-mode-line-update)) |
345 | 361 |