annotate lisp/avoid.el @ 5923:ee06aa87f729

Fix misspelled symbol LD_SWITCH_X_SITE_AUX.
author Karl Heuer <kwzh@gnu.org>
date Sat, 12 Feb 1994 02:26:44 +0000
parents 01628c0b2646
children b8026de94b3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; avoid.el -- make mouse pointer stay out of the way of editing.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
3 ;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Boris Goldowsky <boris@cs.rochester.edu>
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: mouse
5145
78323ca35d6f Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
7 ;; Version: 1.10
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; For those who are annoyed by the mouse pointer obscuring text,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; this mode moves the mouse pointer - either just a little out of
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; the way, or all the way to the corner of the frame.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; To use, load or evaluate this file and type M-x mouse-avoidance-mode .
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; To set up permanently, put this file on your load-path and put the
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; following in your .emacs:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; (cond (window-system
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; (require 'avoid)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; (mouse-avoidance-mode 'cat-and-mouse)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; The 'animate can be 'jump or 'banish or 'protean if you prefer.
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
39 ;;; See the documentation for function `mouse-avoidance-mode' for
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
40 ;;; details of the different modes.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;; For added silliness, make the animatee animate...
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; put something similar to the following into your .emacs:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; (cond (window-system
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; (setq x-pointer-shape
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; (eval (nth (random 4)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; '(x-pointer-man x-pointer-spider
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; x-pointer-gobbler x-pointer-gumby))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;; (set-mouse-color (cdr (assoc 'mouse-color (frame-parameters))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;; For completely random pointer shape, replace the setq above with:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; (setq x-pointer-shape (mouse-avoidance-random-shape))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; Bugs & Warnings:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;;
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
57 ;;; - Due to a bug in (mouse-position), this code can cause emacs
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
58 ;;; 19.22 to crash when deleting a frame if the mouse has not moved
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
59 ;;; since creating the frame. Versions earlier than 19.21 will
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
60 ;;; crash more easily; this program should not be used with them.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;; - Using this code does slow emacs down. "banish" mode shouldn't
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; ever be too bad though, and on my workstation even "animate" doesn't
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;; seem to have a noticable effect.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;; - There are some situations where it doesn't do what you expect,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;; notably when there are long wrapped lines in the buffer. Since
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; there is no low-level command for finding point's position
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;; on the screen, it can fail to move the pointer when on such a line.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; Credits:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; This code was helped by all those who contributed suggestions, fixes, and
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;; additions:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;; Joe Harrington (and his advisor), for the original inspiration
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;; Ken Manheimer, for dreaming up the Protean mode
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;; Richard Stallman, for the awful cat-and-mouse pun, among other things
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; Mike Williams, Denis Howe, Bill Benedetto, Chris Moore, Don Morris,
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;; Simon Marshall, and M.S. Ashton, for their feedback.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;; Code:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (provide 'avoid)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (defvar mouse-avoidance-mode nil
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 "Value is t or a symbol if the mouse pointer should avoid the cursor.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 See function mouse-avoidance-mode for possible values. Changing this
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 variable is NOT the recommended way to change modes; use the function
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 instead.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defvar mouse-avoidance-nudge-dist 4
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 "*Average distance that mouse will be moved when approached by cursor.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 Only applies in mode-avoidance-modes `animate' and `jump'.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (defvar mouse-avoidance-nudge-var 3
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 "*Variability of mouse-avoidance-nudge-dist (which see).")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defvar mouse-avoidance-animation-delay .01
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 "Delay between animation steps, in seconds.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (defvar mouse-avoidance-threshhold 5
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 "*Mouse-pointer's flight distance.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 If the cursor gets closer than this, the mouse pointer will move away.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 Only applies in mouse-avoidance-modes `animate' and `jump'.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; Internal variables for mouse-avoidance-random-shape
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (defvar mouse-avoidance-pointer-shapes nil)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (defvar mouse-avoidance-n-pointer-shapes 0)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;;; Functions:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defun mouse-avoidance-too-close-p ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; Return t if mouse pointer and point cursor are too close.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;; Acceptable distance is defined by mouse-avoidance-threshhold.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (let ((mouse (mouse-position)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (and (car (cdr mouse))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (< (abs (- (car (cdr mouse)) (current-column)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 mouse-avoidance-threshhold)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (< (abs (- (cdr (cdr mouse))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (+ (car (cdr (window-edges)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (count-lines (window-start) (point)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 mouse-avoidance-threshhold))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defun mouse-avoidance-banish-mouse ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; Put the mouse pointer in the upper-right corner of the current frame.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (set-mouse-position (selected-frame) (1- (frame-width)) 0))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defun mouse-avoidance-nudge-mouse ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; Push the mouse a little way away, possibly animating the move
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (let* ((cur (mouse-position))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (deltax (* (+ mouse-avoidance-nudge-dist
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (random mouse-avoidance-nudge-var))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (if (zerop (random 2)) 1 -1)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (deltay (* (+ mouse-avoidance-nudge-dist
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (random mouse-avoidance-nudge-var))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (if (zerop (random 2)) 1 -1))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (if (or (eq mouse-avoidance-mode 'animate)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (eq mouse-avoidance-mode 'proteus))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (let ((i 0.0)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (color (cdr (assoc 'mouse-color (frame-parameters)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (while (<= i 1)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (set-mouse-position
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (car cur)
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
143 (mod (+ (car (cdr cur)) (round (* i deltax))) (frame-width))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
144 (mod (+ (cdr (cdr cur)) (round (* i deltay))) (frame-height)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (setq i (+ i (/ 1.0 mouse-avoidance-nudge-dist)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (if (eq mouse-avoidance-mode 'proteus)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (progn
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (setq x-pointer-shape (mouse-avoidance-random-shape))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (set-mouse-color color)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (sit-for mouse-avoidance-animation-delay)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (set-mouse-position
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (car cur)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (mod (+ (car (cdr cur)) deltax) (window-width))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (mod (+ (cdr (cdr cur)) deltay) (window-height))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (defun mouse-avoidance-random-shape ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 "Return a random cursor shape.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 This assumes that any variable whose name begins with x-pointer- and
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 has an integer value is a valid cursor shape. You might want to
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 redefine this function to suit your own tastes."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (if (null mouse-avoidance-pointer-shapes)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (progn
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (setq mouse-avoidance-pointer-shapes
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (mapcar '(lambda (x) (symbol-value (intern x)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (all-completions "x-pointer-" obarray
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 '(lambda (x)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (and (boundp x)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (integerp (symbol-value x)))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (setq mouse-avoidance-n-pointer-shapes
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (length mouse-avoidance-pointer-shapes))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (nth (random mouse-avoidance-n-pointer-shapes)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 mouse-avoidance-pointer-shapes))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (defun mouse-avoidance-simple-hook ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (if (and (mouse-avoidance-keyboard-command (this-command-keys)))
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
176 (progn
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
177 (raise-frame (selected-frame))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
178 (mouse-avoidance-banish-mouse))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (defun mouse-avoidance-fancy-hook ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (if (and (mouse-avoidance-keyboard-command (this-command-keys))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (mouse-avoidance-too-close-p))
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
183 (let ((old-pos (mouse-position)))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
184 (mouse-avoidance-nudge-mouse)
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
185 (if (not (eq (selected-frame) (car old-pos)))
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
186 (apply 'set-mouse-position old-pos)))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defun mouse-avoidance-keyboard-command (key)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "Return t if the KEYSEQENCE is composed of keyboard events only.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 Returns nil if there are any lists in the key sequence."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (cond ((null key) nil) ; Null event seems to be
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ; returned occasionally.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ((not (vectorp key)) t) ; Strings are keyboard events.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ((catch 'done
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (let ((i 0)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (l (length key)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (while (< i l)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (if (listp (aref key i))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (throw 'done nil))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (setq i (1+ i))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 t))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (defun mouse-avoidance-mode (&optional mode)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 "Set cursor avoidance mode to MODE.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 MODE should be one of the symbols `banish', `jump', `animate',
5745
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
206 `cat-and-mouse', `proteus', or `none'.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
207
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
208 If MODE is nil, toggle mouse avoidance between `none' and `banish'
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
209 modes. Positive numbers and symbols other than the above are treated
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
210 as equivalent to `banish'; negative numbers and `-' are equivalent to `none'.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
211
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
212 Effects of the different modes:
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
213 * BANISH: Move the mouse to the upper-right corner on any keypress.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
214 Also raises the frame.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
215 * JUMP: If the cursor gets too close to the mouse, displace the mouse
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
216 a random distance & direction. If this would put it in another,
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
217 overlapping frame, it is put back \(until the next keypress).
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
218 * ANIMATE: As `jump', but shows steps along the way for illusion of motion.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
219 * CAT-AND-MOUSE: Same as `animate'.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
220 * PROTEUS: As `animate', but changes the shape of the mouse pointer too.
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
221
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
222 \(see `mouse-avoidance-threshhold' for definition of \"too close\",
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
223 and `mouse-avoidance-nudge-dist' and `mouse-avoidance-nudge-var' for
01628c0b2646 Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5145
diff changeset
224 definition of \"random distance\".)"
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (interactive
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (list (intern (completing-read
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 "Select cursor avoidance technique (SPACE for list): "
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 '(("banish") ("jump") ("animate") ("cat-and-mouse")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ("proteus") ("none"))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 nil t))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (if (eq mode 'cat-and-mouse)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (setq mode 'animate))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (setq post-command-hook
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (delete 'mouse-avoidance-simple-hook (append post-command-hook nil)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (setq post-command-hook
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (delete 'mouse-avoidance-fancy-hook (append post-command-hook nil)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (cond ((eq mode 'none)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (setq mouse-avoidance-mode nil))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ((or (eq mode 'jump)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (eq mode 'animate)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (eq mode 'proteus))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (add-hook 'post-command-hook 'mouse-avoidance-fancy-hook)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (setq mouse-avoidance-mode mode))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ((or (eq mode 'banish)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (eq mode t)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (and (null mode) (null mouse-avoidance-mode))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (and mode (> (prefix-numeric-value mode) 0)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (add-hook 'post-command-hook 'mouse-avoidance-simple-hook)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (setq mouse-avoidance-mode 'banish))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (t (setq mouse-avoidance-mode nil))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (or (assq 'mouse-avoidance-mode minor-mode-alist)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (setq minor-mode-alist (cons '(mouse-avoidance-mode " Avoid")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 minor-mode-alist)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;;; End of avoid.el
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257