• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/

Lines Matching defs:mouse

1 ;;; avoid.el --- make mouse pointer stay out of the way of editing
7 ;; Keywords: mouse
28 ;; For those who are annoyed by the mouse pointer obscuring text,
29 ;; this mode moves the mouse pointer - either just a little out of
31 ;; To use, load or evaluate this file and type M-x mouse-avoidance-mode .
34 ;; (if (display-mouse-p) (mouse-avoidance-mode 'animate))
37 ;; `banish', `exile', `jump', `cat-and-mouse', and `proteus'.
39 ;; See the documentation for function `mouse-avoidance-mode' for
46 ;; (mouse-avoidance-set-pointer-shape
52 ;; (setq x-pointer-shape (mouse-avoidance-random-shape))
67 ;; Richard Stallman, for the awful cat-and-mouse pun, among other things.
76 "Make mouse pointer stay out of the way of editing."
77 :prefix "mouse-avoidance-"
78 :group 'mouse)
81 (defcustom mouse-avoidance-mode nil
82 "Activate mouse avoidance mode.
83 See function `mouse-avoidance-mode' for possible values.
85 use either \\[customize] or the function `mouse-avoidance-mode'."
88 (mouse-avoidance-mode (or value 'none)))
98 (defcustom mouse-avoidance-nudge-dist 15
99 "*Average distance that mouse will be moved when approached by cursor.
101 For best results make this larger than `mouse-avoidance-threshold'."
105 (defcustom mouse-avoidance-nudge-var 10
106 "*Variability of `mouse-avoidance-nudge-dist' (which see)."
110 (defcustom mouse-avoidance-animation-delay .01
115 (defcustom mouse-avoidance-threshold 5
117 If the cursor gets closer than this, the mouse pointer will move away.
118 Only applies in mouse-avoidance-modes `animate' and `jump'."
123 (defvar mouse-avoidance-state nil)
124 (defvar mouse-avoidance-pointer-shapes nil)
125 (defvar mouse-avoidance-n-pointer-shapes 0)
126 (defvar mouse-avoidance-old-pointer-shape nil)
127 (defvar mouse-avoidance-animating-pointer nil)
130 (defvar mouse-avoidance-timer nil)
134 (defsubst mouse-avoidance-set-pointer-shape (shape)
135 "Set the shape of the mouse pointer to SHAPE."
138 (set-mouse-color nil)))
140 (defun mouse-avoidance-point-position ()
142 Analogous to `mouse-position'."
151 ;(defun mouse-avoidance-point-position-test ()
153 ; (message (format "point=%s mouse=%s"
154 ; (cdr (mouse-avoidance-point-position))
155 ; (cdr (mouse-position)))))
157 (defun mouse-avoidance-set-mouse-position (pos)
158 ;; Carefully set mouse position to given position (X . Y)
160 ;; leave the mouse where it was. However, this is currently
162 ;; Returns t if it moved the mouse.
165 (set-mouse-position f (car pos) (cdr pos))
168 (defun mouse-avoidance-too-close-p (mouse)
169 "Return t if mouse pointer and point cursor are too close.
170 MOUSE is the current mouse position as returned by `mouse-position'.
171 Acceptable distance is defined by `mouse-avoidance-threshold'."
172 (let* ((frame (car mouse))
173 (mouse-y (cdr (cdr mouse)))
177 (if (and mouse-y (< mouse-y tool-bar-lines))
179 (let ((point (mouse-avoidance-point-position))
180 (mouse-x (car (cdr mouse))))
182 (not (null mouse-x))
183 (< (abs (- mouse-x (car (cdr point))))
184 mouse-avoidance-threshold)
185 (< (abs (- mouse-y (cdr (cdr point))))
186 mouse-avoidance-threshold))))))
188 (defun mouse-avoidance-banish-destination ()
189 "The position to which Mouse-Avoidance mode `banish' moves the mouse.
190 You can redefine this if you want the mouse banished to a different corner."
195 (defun mouse-avoidance-banish-mouse ()
196 ;; Put the mouse pointer in the upper-right corner of the current frame.
197 (mouse-avoidance-set-mouse-position (mouse-avoidance-banish-destination)))
199 (defsubst mouse-avoidance-delta (cur delta dist var min max)
220 (defun mouse-avoidance-nudge-mouse ()
221 ;; Push the mouse a little way away, possibly animating the move.
224 (let* ((cur (mouse-position))
232 (deltax (mouse-avoidance-delta
233 (car cur-pos) (- (random mouse-avoidance-nudge-var)
234 (car mouse-avoidance-state))
235 mouse-avoidance-nudge-dist mouse-avoidance-nudge-var
237 (deltay (mouse-avoidance-delta
238 (cdr cur-pos) (- (random mouse-avoidance-nudge-var)
239 (cdr mouse-avoidance-state))
240 mouse-avoidance-nudge-dist mouse-avoidance-nudge-var
242 (setq mouse-avoidance-state
243 (cons (+ (car mouse-avoidance-state) deltax)
244 (+ (cdr mouse-avoidance-state) deltay)))
245 (if (or (eq mouse-avoidance-mode 'animate)
246 (eq mouse-avoidance-mode 'proteus))
248 (incr (max .1 (/ 1.0 mouse-avoidance-nudge-dist))))
249 (setq mouse-avoidance-animating-pointer t)
251 (mouse-avoidance-set-mouse-position
255 (if (eq mouse-avoidance-mode 'proteus)
256 (mouse-avoidance-set-pointer-shape
257 (mouse-avoidance-random-shape)))
258 (sit-for mouse-avoidance-animation-delay))
259 (setq mouse-avoidance-animating-pointer nil))
260 (mouse-avoidance-set-mouse-position (cons (+ (car (cdr cur)) deltax)
263 (defun mouse-avoidance-random-shape ()
268 (if (null mouse-avoidance-pointer-shapes)
270 (setq mouse-avoidance-pointer-shapes
276 (setq mouse-avoidance-n-pointer-shapes
277 (length mouse-avoidance-pointer-shapes))))
278 (nth (random mouse-avoidance-n-pointer-shapes)
279 mouse-avoidance-pointer-shapes))
281 (defun mouse-avoidance-ignore-p ()
282 (let ((mp (mouse-position)))
286 ;; Don't do anything if last event was a mouse event.
287 ;; FIXME: this code fails in the case where the mouse was moved
293 '(mouse-movement scroll-bar-movement
301 (defun mouse-avoidance-banish ()
302 (if (not (mouse-avoidance-ignore-p))
303 (mouse-avoidance-banish-mouse)))
305 (defun mouse-avoidance-exile ()
306 ;; For exile mode, the state is nil when the mouse is in its normal
307 ;; position, and set to the old mouse-position when the mouse is in exile.
308 (if (not (mouse-avoidance-ignore-p))
309 (let ((mp (mouse-position)))
310 (cond ((and (not mouse-avoidance-state)
311 (mouse-avoidance-too-close-p mp))
312 (setq mouse-avoidance-state mp)
313 (mouse-avoidance-banish-mouse))
314 ((and mouse-avoidance-state
315 (not (mouse-avoidance-too-close-p mouse-avoidance-state)))
317 (equal (cdr mp) (mouse-avoidance-banish-destination)))
318 (mouse-avoidance-set-mouse-position
319 ;; move back only if user has not moved mouse
320 (cdr mouse-avoidance-state)))
322 (setq mouse-avoidance-state nil))))))
324 (defun mouse-avoidance-fancy ()
326 (if (and (not mouse-avoidance-animating-pointer)
327 (not (mouse-avoidance-ignore-p))
328 (mouse-avoidance-too-close-p (mouse-position)))
329 (let ((old-pos (mouse-position)))
330 (mouse-avoidance-nudge-mouse)
333 (apply 'set-mouse-position old-pos)))))
336 (defun mouse-avoidance-mode (&optional mode)
339 `cat-and-mouse', `proteus', or `none'.
341 If MODE is nil, toggle mouse avoidance between `none' and `banish'
346 * banish: Move the mouse to the upper-right corner on any keypress.
347 * exile: Move the mouse to the corner only if the cursor gets too close,
349 * jump: If the cursor gets too close to the mouse, displace the mouse
352 * cat-and-mouse: Same as `animate'.
353 * proteus: As `animate', but changes the shape of the mouse pointer too.
355 Whenever the mouse is moved, the frame is also raised.
357 \(see `mouse-avoidance-threshold' for definition of \"too close\",
358 and `mouse-avoidance-nudge-dist' and `mouse-avoidance-nudge-var' for
364 ("cat-and-mouse") ("proteus") ("none"))
366 (if (eq mode 'cat-and-mouse)
368 (if mouse-avoidance-timer
369 (cancel-timer mouse-avoidance-timer))
370 (setq mouse-avoidance-timer nil)
373 (if (eq mouse-avoidance-mode 'proteus)
374 (mouse-avoidance-set-pointer-shape mouse-avoidance-old-pointer-shape))
378 (setq mouse-avoidance-mode nil))
382 (setq mouse-avoidance-timer
383 (run-with-idle-timer 0.1 t 'mouse-avoidance-fancy))
384 (setq mouse-avoidance-mode mode
385 mouse-avoidance-state (cons 0 0)
386 mouse-avoidance-old-pointer-shape
389 (setq mouse-avoidance-timer
390 (run-with-idle-timer 0.1 t 'mouse-avoidance-exile))
391 (setq mouse-avoidance-mode mode
392 mouse-avoidance-state nil))
395 (and (null mode) (null mouse-avoidance-mode))
397 (setq mouse-avoidance-timer
398 (run-with-idle-timer 0.1 t 'mouse-avoidance-banish))
399 (setq mouse-avoidance-mode 'banish))
400 (t (setq mouse-avoidance-mode nil)))
405 ;;(or (assq 'mouse-avoidance-mode minor-mode-alist)
406 ;; (setq minor-mode-alist (cons '(mouse-avoidance-mode " Avoid")
410 (if mouse-avoidance-mode
411 (mouse-avoidance-mode mouse-avoidance-mode))