bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Thierry Volpiatto
Subject: bug#10165: [PATCH] Allow setting corner in mouse avoidance mode.
Date: Thu, 01 Dec 2011 09:45:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Juri Linkov <juri@jurta.org> 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?
Try this:

#+BEGIN_SRC lisp
(defun mouse-avoidance-banish-destination ()
  "The position to which Mouse Avoidance mode `banish' moves the mouse.
If you want the mouse banished to a different corner set
`mouse-avoidance-banish-destination' 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)
                   (cdr mouse-avoidance-banish-distance-from-edge))
          (assoc-default up-down pos))))

(defcustom mouse-avoidance-banish-destination '(right . top)
  "Set the position to which Mouse Avoidance mode `banish' moves the mouse."
  :group 'avoid
  :type 'list)

(defcustom mouse-avoidance-banish-distance-from-edge '(window . 3)
  "Set the distance from edge of window in Mouse Avoidance mode `banish'."
  :group 'avoid
  :type 'list)

#+END_SRC

And to fit your settings:

(setq mouse-avoidance-banish-destination '(right . bottom))
(setq mouse-avoidance-banish-distance-from-edge '(frame . 3))

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]