-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemacs-window-focus-mouse.el
31 lines (24 loc) · 1.15 KB
/
emacs-window-focus-mouse.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(defun window-follow-mouse ()
(unless (active-minibuffer-window)
(destructuring-bind (frame column . row) (mouse-position)
(let ((mse-window (window-at column row frame))
(cur-window (selected-window)))
(unless (eql mse-window cur-window)
(select-window mse-window))))))
(defadvice select-window (after select-window/window-follow-mouse disable)
(destructuring-bind (left top right bottom) (window-edges (selected-window) :body)
(let ((frame (selected-frame))
(column (truncate (+ left right) 2))
(row (truncate (+ top bottom) 2)))
(set-mouse-position frame column row))))
(defvar *window-follow-mouse-timer* nil)
(defun schedule-window-follow-mouse ()
(interactive)
(ad-add-advice 'select-window 'after 'select-window/window-follow-mouse 'last)
(setf *window-follow-mouse-timer* (run-at-time 1 0.1 'window-follow-mouse)))
(defun unschedule-window-follow-mouse ()
(interactive)
(when *window-follow-mouse-timer*
(ad-remove-advice 'select-window 'after 'select-window/window-follow-mouse)
(cancel-timer *window-follow-mouse-timer*)
(setf *window-follow-mouse-timer* nil)))