aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/avoid.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/avoid.el')
-rw-r--r--lisp/avoid.el66
1 files changed, 58 insertions, 8 deletions
diff --git a/lisp/avoid.el b/lisp/avoid.el
index 17d99fd6517..bfe15de0ca2 100644
--- a/lisp/avoid.el
+++ b/lisp/avoid.el
@@ -67,7 +67,7 @@
67 67
68;;; Code: 68;;; Code:
69 69
70(provide 'avoid) 70(eval-when-compile (require 'cl))
71 71
72(defgroup avoid nil 72(defgroup avoid nil
73 "Make mouse pointer stay out of the way of editing." 73 "Make mouse pointer stay out of the way of editing."
@@ -80,7 +80,7 @@
80See function `mouse-avoidance-mode' for possible values. 80See function `mouse-avoidance-mode' for possible values.
81Setting this variable directly does not take effect; 81Setting this variable directly does not take effect;
82use either \\[customize] or the function `mouse-avoidance-mode'." 82use either \\[customize] or the function `mouse-avoidance-mode'."
83 :set (lambda (symbol value) 83 :set (lambda (_symbol value)
84 ;; 'none below prevents toggling when value is nil. 84 ;; 'none below prevents toggling when value is nil.
85 (mouse-avoidance-mode (or value 'none))) 85 (mouse-avoidance-mode (or value 'none)))
86 :initialize 'custom-initialize-default 86 :initialize 'custom-initialize-default
@@ -115,6 +115,23 @@ Only applies in Mouse Avoidance modes `animate' and `jump'."
115 :type 'integer 115 :type 'integer
116 :group 'avoid) 116 :group 'avoid)
117 117
118(defcustom mouse-avoidance-banish-position '((frame-or-window . frame)
119 (side . right)
120 (side-pos . 3)
121 (top-or-bottom . top)
122 (top-or-bottom-pos . 0))
123 "Position to which Mouse Avoidance mode `banish' moves the mouse.
124An alist where keywords mean:
125FRAME-OR-WINDOW: banish the mouse to corner of frame or window.
126SIDE: banish the mouse on right or left corner of frame or window.
127SIDE-POS: Distance from right or left edge of frame or window.
128TOP-OR-BOTTOM: banish the mouse to top or bottom of frame or window.
129TOP-OR-BOTTOM-POS: Distance from top or bottom edge of frame or window."
130 :group 'avoid
131 :type '(alist :key-type symbol :value-type symbol)
132 :options '(frame-or-window side (side-pos integer)
133 top-or-bottom (top-or-bottom-pos integer)))
134
118;; Internal variables 135;; Internal variables
119(defvar mouse-avoidance-state nil) 136(defvar mouse-avoidance-state nil)
120(defvar mouse-avoidance-pointer-shapes nil) 137(defvar mouse-avoidance-pointer-shapes nil)
@@ -183,13 +200,45 @@ Acceptable distance is defined by `mouse-avoidance-threshold'."
183 200
184(defun mouse-avoidance-banish-destination () 201(defun mouse-avoidance-banish-destination ()
185 "The position to which Mouse Avoidance mode `banish' moves the mouse. 202 "The position to which Mouse Avoidance mode `banish' moves the mouse.
186You can redefine this if you want the mouse banished to a different corner." 203
187 (let* ((pos (window-edges))) 204If you want the mouse banished to a different corner set
188 (cons (- (nth 2 pos) 2) 205`mouse-avoidance-banish-position' as you need."
189 (nth 1 pos)))) 206 (let* ((fra-or-win (assoc-default
207 'frame-or-window
208 mouse-avoidance-banish-position 'eq))
209 (list-values (case fra-or-win
210 (frame (list 0 0 (frame-width) (frame-height)))
211 (window (window-edges))))
212 (alist (loop for v in list-values
213 for k in '(left top right bottom)
214 collect (cons k v)))
215 (side (assoc-default
216 'side
217 mouse-avoidance-banish-position 'eq))
218 (side-dist (assoc-default
219 'side-pos
220 mouse-avoidance-banish-position 'eq))
221 (top-or-bottom (assoc-default
222 'top-or-bottom
223 mouse-avoidance-banish-position 'eq))
224 (top-or-bottom-dist (assoc-default
225 'top-or-bottom-pos
226 mouse-avoidance-banish-position 'eq))
227 (side-fn (case side
228 (left '+)
229 (right '-)))
230 (top-or-bottom-fn (case top-or-bottom
231 (top '+)
232 (bottom '-))))
233 (cons (funcall side-fn ; -/+
234 (assoc-default side alist 'eq) ; right or left
235 side-dist) ; distance from side
236 (funcall top-or-bottom-fn ; -/+
237 (assoc-default top-or-bottom alist 'eq) ; top/bottom
238 top-or-bottom-dist)))) ; distance from top/bottom
190 239
191(defun mouse-avoidance-banish-mouse () 240(defun mouse-avoidance-banish-mouse ()
192 ;; Put the mouse pointer in the upper-right corner of the current frame. 241 "Put the mouse pointer to `mouse-avoidance-banish-position'."
193 (mouse-avoidance-set-mouse-position (mouse-avoidance-banish-destination))) 242 (mouse-avoidance-set-mouse-position (mouse-avoidance-banish-destination)))
194 243
195(defsubst mouse-avoidance-delta (cur delta dist var min max) 244(defsubst mouse-avoidance-delta (cur delta dist var min max)
@@ -218,7 +267,6 @@ You can redefine this if you want the mouse banished to a different corner."
218 ;; For these modes, state keeps track of the total offset that we've 267 ;; For these modes, state keeps track of the total offset that we've
219 ;; accumulated, and tries to keep it close to zero. 268 ;; accumulated, and tries to keep it close to zero.
220 (let* ((cur (mouse-position)) 269 (let* ((cur (mouse-position))
221 (cur-frame (car cur))
222 (cur-pos (cdr cur)) 270 (cur-pos (cdr cur))
223 (pos (window-edges)) 271 (pos (window-edges))
224 (wleft (pop pos)) 272 (wleft (pop pos))
@@ -408,4 +456,6 @@ definition of \"random distance\".)"
408(if mouse-avoidance-mode 456(if mouse-avoidance-mode
409 (mouse-avoidance-mode mouse-avoidance-mode)) 457 (mouse-avoidance-mode mouse-avoidance-mode))
410 458
459(provide 'avoid)
460
411;;; avoid.el ends here 461;;; avoid.el ends here