Commit 1f31a9f1 authored by Boris Goldowsky's avatar Boris Goldowsky
Browse files

avoid.el Add autoload cookies; doc fixes.

 (mouse-avoidance-set-pointer-shape): New function.
(mouse-avoidance-nudge-mouse): Use it.
(mouse-avoidance-fancy-hook): streamline args to set-mouse-pos.
parent 3e043944
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
;; Author: Boris Goldowsky <boris@cs.rochester.edu> ;; Author: Boris Goldowsky <boris@cs.rochester.edu>
;; Keywords: mouse ;; Keywords: mouse
;; Version: 1.10
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
...@@ -28,12 +27,9 @@ ...@@ -28,12 +27,9 @@
;;; this mode moves the mouse pointer - either just a little out of ;;; this mode moves the mouse pointer - either just a little out of
;;; the way, or all the way to the corner of the frame. ;;; the way, or all the way to the corner of the frame.
;;; To use, load or evaluate this file and type M-x mouse-avoidance-mode . ;;; To use, load or evaluate this file and type M-x mouse-avoidance-mode .
;;; To set up permanently, put this file on your load-path and put the ;;; To set up permanently, put the following in your .emacs:
;;; following in your .emacs:
;;; ;;;
;;; (cond (window-system ;;; (if window-system (mouse-avoidance-mode 'animate))
;;; (require 'avoid)
;;; (mouse-avoidance-mode 'animate)))
;;; ;;;
;;; The 'animate can be 'jump or 'banish or 'exile or 'protean if you prefer. ;;; The 'animate can be 'jump or 'banish or 'exile or 'protean if you prefer.
;;; See the documentation for function `mouse-avoidance-mode' for ;;; See the documentation for function `mouse-avoidance-mode' for
...@@ -42,12 +38,11 @@ ...@@ -42,12 +38,11 @@
;;; For added silliness, make the animatee animate... ;;; For added silliness, make the animatee animate...
;;; put something similar to the following into your .emacs: ;;; put something similar to the following into your .emacs:
;;; ;;;
;;; (cond (window-system ;;; (if window-system
;;; (setq x-pointer-shape ;;; (mouse-avoidance-set-pointer-shape
;;; (eval (nth (random 4) ;;; (eval (nth (random 4)
;;; '(x-pointer-man x-pointer-spider ;;; '(x-pointer-man x-pointer-spider
;;; x-pointer-gobbler x-pointer-gumby)))) ;;; x-pointer-gobbler x-pointer-gumby)))))
;;; (set-mouse-color (cdr (assoc 'mouse-color (frame-parameters))))))
;;; ;;;
;;; For completely random pointer shape, replace the setq above with: ;;; For completely random pointer shape, replace the setq above with:
;;; (setq x-pointer-shape (mouse-avoidance-random-shape)) ;;; (setq x-pointer-shape (mouse-avoidance-random-shape))
...@@ -55,10 +50,9 @@ ...@@ -55,10 +50,9 @@
;;; Bugs / Warnings / To-Do: ;;; Bugs / Warnings / To-Do:
;;; ;;;
;;; - Using this code does slow emacs down. "banish" mode shouldn't ;;; - Using this code does slow emacs down. "banish" mode shouldn't
;;; ever be too bad though, and on my workstation even "animate" doesn't ;;; be too bad, and on my workstation even "animate" is reasonable.
;;; seem to have a noticable effect during editing.
;;; ;;;
;;; - It should find out where any overlapping frames are and avoid them, ;;; - It ought to find out where any overlapping frames are and avoid them,
;;; rather than always raising the frame. ;;; rather than always raising the frame.
;;; Credits: ;;; Credits:
...@@ -103,6 +97,11 @@ Only applies in mouse-avoidance-modes `animate' and `jump'.") ...@@ -103,6 +97,11 @@ Only applies in mouse-avoidance-modes `animate' and `jump'.")
;;; Functions: ;;; Functions:
(defsubst mouse-avoidance-set-pointer-shape (shape)
"Set the shape of the mouse pointer to SHAPE."
(setq x-pointer-shape shape)
(set-mouse-color nil))
(defun mouse-avoidance-point-position () (defun mouse-avoidance-point-position ()
"Return the position of point as (FRAME X . Y). "Return the position of point as (FRAME X . Y).
Analogous to mouse-position." Analogous to mouse-position."
...@@ -205,17 +204,15 @@ You can redefine this if you want the mouse banished to a different corner." ...@@ -205,17 +204,15 @@ You can redefine this if you want the mouse banished to a different corner."
(+ (cdr mouse-avoidance-state) deltay))) (+ (cdr mouse-avoidance-state) deltay)))
(if (or (eq mouse-avoidance-mode 'animate) (if (or (eq mouse-avoidance-mode 'animate)
(eq mouse-avoidance-mode 'proteus)) (eq mouse-avoidance-mode 'proteus))
(let ((i 0.0) (let ((i 0.0))
(color (cdr (assoc 'mouse-color (frame-parameters)))))
(while (<= i 1) (while (<= i 1)
(mouse-avoidance-set-mouse-position (mouse-avoidance-set-mouse-position
(cons (+ (car cur-pos) (round (* i deltax))) (cons (+ (car cur-pos) (round (* i deltax)))
(+ (cdr cur-pos) (round (* i deltay))))) (+ (cdr cur-pos) (round (* i deltay)))))
(setq i (+ i (max .1 (/ 1.0 mouse-avoidance-nudge-dist)))) (setq i (+ i (max .1 (/ 1.0 mouse-avoidance-nudge-dist))))
(if (eq mouse-avoidance-mode 'proteus) (if (eq mouse-avoidance-mode 'proteus)
(progn (mouse-avoidance-set-pointer-shape
(setq x-pointer-shape (mouse-avoidance-random-shape)) (mouse-avoidance-random-shape)))
(set-mouse-color color)))
(sit-for mouse-avoidance-animation-delay))) (sit-for mouse-avoidance-animation-delay)))
(mouse-avoidance-set-mouse-position (cons (+ (car (cdr cur)) deltax) (mouse-avoidance-set-mouse-position (cons (+ (car (cdr cur)) deltax)
(+ (cdr (cdr cur)) deltay)))))) (+ (cdr (cdr cur)) deltay))))))
...@@ -270,10 +267,9 @@ redefine this function to suit your own tastes." ...@@ -270,10 +267,9 @@ redefine this function to suit your own tastes."
(mouse-avoidance-too-close-p (mouse-position))) (mouse-avoidance-too-close-p (mouse-position)))
(let ((old-pos (mouse-position))) (let ((old-pos (mouse-position)))
(mouse-avoidance-nudge-mouse) (mouse-avoidance-nudge-mouse)
(if (not (eq (selected-frame) (car old-pos))) ; move went awry (if (not (eq (selected-frame) (car old-pos)))
(set-mouse-position old-pos (car old-pos) ; sigh.. ;; This should never happen.
(car (cdr old-pos)) (apply 'set-mouse-position old-pos)))))
(cdr (cdr old-pos)))))))
(defun mouse-avoidance-kbd-command (key) (defun mouse-avoidance-kbd-command (key)
"Return t if the KEYSEQENCE is composed of keyboard events only. "Return t if the KEYSEQENCE is composed of keyboard events only.
...@@ -290,6 +286,7 @@ Return nil if there are any lists in the key sequence." ...@@ -290,6 +286,7 @@ Return nil if there are any lists in the key sequence."
(setq i (1+ i)))) (setq i (1+ i))))
t)))) t))))
;;;###autoload
(defun mouse-avoidance-mode (&optional mode) (defun mouse-avoidance-mode (&optional mode)
"Set cursor avoidance mode to MODE. "Set cursor avoidance mode to MODE.
MODE should be one of the symbols `banish', `exile', `jump', `animate', MODE should be one of the symbols `banish', `exile', `jump', `animate',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment