Subject: Re: bug#10165: [PATCH] Allow setting corner in mouse avoidance mode.

From: Thierry Volpiatto <[email-masked]>
Date: Fri, 02 Dec 2011 08:30:23 +0100

Juri Linkov <[email-masked]> writes:

>>>> FWIW, I have in my .emacs:
>>>>
>>>>   ;; Move the mouse to the screen corner on any keypress.
>>>>   (when (and (display-mouse-p) (require 'avoid nil t))
>>>>     ;; Move the mouse to the lower-right corner instead of default upper-right
>>>>     (defun mouse-avoidance-banish-destination ()
>>>>       (cons (+ 3 (frame-width)) (- (frame-height) 1)))
>>>>     (mouse-avoidance-mode 'banish))
>>>>
>>>> It would be better to allow users to replace such code with customization.
>>> Yes, it is what my patch does:
>>> Instead of your code you can just say:
>>> (setq mouse-avoidance-banish-destination '(right . bottom))
>>> or of course setting that through customize interface.
>>
>> Also, I have added a new user variable to this patch that allow setting
>> the distance from window's edge:
>>
>> (defcustom mouse-avoidance-banish-distance-from-edge 2
>>   "Set the distance from edge of window in Mouse Avoidance mode `banish'."
>>   :group 'avoid
>>   :type 'integer)
>
> Thanks, but in my settings the distance is relative to frame's edge
> instead of window's edge.  Is it possible to express this setting
> with a user variable?
Here the improved version of the patch:

##Merge of all patches applied from revision 118094
## patch-r118037: * lisp/avoid.el:  Allow setting in which corner banish move the mouse.
## patch-r118084: * lisp/avoid.el (mouse-avoidance-banish-distance-from-edge): Allow banishing mouse in frame or window corner.
## 
diff --git a/lisp/avoid.el b/lisp/avoid.el
--- a/lisp/avoid.el
+++ b/lisp/avoid.el
@@ -115,6 +115,23 @@
   :type 'integer
   :group 'avoid)
 
+(defcustom mouse-avoidance-banish-destination '(right . top)
+  "Position to which Mouse Avoidance mode `banish' moves the mouse.
+
+Valid possible values can be:
+\'(right . top\), \'(left . top\), \'(right . bottom\) or \'(left . bottom\)."
+  :group 'avoid
+  :type 'list)
+
+(defcustom mouse-avoidance-banish-distance-from-edge '(window . 2)
+  "Distance from edge of window or frame in Mouse Avoidance mode `banish'.
+
+It is a cons cell where the car can be 'window or 'frame
+and the cdr and integer representing the distance
+from edge of window or frame."
+  :group 'avoid
+  :type 'list)
+
 ;; Internal variables
 (defvar mouse-avoidance-state nil)
 (defvar mouse-avoidance-pointer-shapes nil)
@@ -183,10 +200,24 @@
 
 (defun mouse-avoidance-banish-destination ()
   "The position to which Mouse Avoidance mode `banish' moves the mouse.
-You can redefine this if you want the mouse banished to a different corner."
-  (let* ((pos (window-edges)))
-    (cons (- (nth 2 pos) 2)
-	  (nth 1 pos))))
+
+If you want the mouse banished to a different corner set
+`mouse-avoidance-banish-destination' and
+`mouse-avoidance-banish-distance-from-edge' as you need."
+  (let* ((fra-or-win (case (car mouse-avoidance-banish-distance-from-edge)
+                       (frame (list 0 0 (frame-width) (frame-height)))
+                       (window (window-edges))))
+         (pos        (loop for v in fra-or-win
+                           for k in '(left top right bottom)
+                           collect (cons k v)))
+         (side       (car mouse-avoidance-banish-destination))
+         (up-down    (cdr mouse-avoidance-banish-destination))
+         (fn         (case side
+                       (left '+)
+                       (right '-))))
+    (cons (funcall fn (assoc-default side pos 'eq)
+                   (cdr mouse-avoidance-banish-distance-from-edge))
+	  (assoc-default up-down pos 'eq))))
 
 (defun mouse-avoidance-banish-mouse ()
   ;; Put the mouse pointer in the upper-right corner of the current frame.

-- 
  Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997