3
;;;; follow-mouse.el -- Automatically select the window under the mouse.
5
;;; RCS $Id: follow-mouse.el,v 1.1 2002/07/21 14:05:54 joerg Exp $
8
;;; By default, a window within an Emacs frame must be selected by
9
;;; typing `C-x o' (other-window) or by clicking [mouse-1] on the mode
10
;;; line or the buffer itself (mouse-set-point); this corresponds to a
11
;;; "click to type" window manager policy. follow-mouse.el implements a
12
;;; "focus follows mouse" window manager policy, so that a window is
13
;;; selected when the mouse moves over it.
15
;;; To enable follow-mouse, put this in your ~/.emacs file:
16
;;; (turn-on-follow-mouse)
18
;;; follow-mouse can be enabled or disabled interactively with the
19
;;; `M-x turn-on-follow-mouse', `M-x turn-off-follow-mouse', and
20
;;; `M-x toggle-follow-mouse' commands.
22
;;; By default, follow-mouse will deselect an active minibuffer window;
23
;;; to prevent that, just unset the
24
;;; `follow-mouse-deselect-active-minibuffer' option.
26
;;; By default, follow-mouse also raises the frame whose window is
27
;;; selected; to disable that, just unset the
28
;;; `follow-mouse-auto-raise-frame' option.
32
;;; Copyright � 1998,2000 Kevin Rodgers
34
;;; This program is free software; you can redistribute it and/or modify
35
;;; it under the terms of the GNU General Public License as published by
36
;;; the Free Software Foundation; either version 2 of the License, or
37
;;; at your option) any later version.
39
;;; This program is distributed in the hope that it will be useful,
40
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
41
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42
;;; GNU General Public License for more details.
44
;;; You should have received a copy of the GNU General Public License
45
;;; along with this program; if not, write to the Free Software
46
;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
48
;;; My employer (Information Handling Services) has not disclaimed any
49
;;; copyright interest in follow-mouse.el.
51
;;; Kevin Rodgers <kevinr@ihs.com> Lead Software Engineer
52
;;; Information Handling Services Electronic Systems Development
53
;;; 15 Inverness Way East, M/S A114 GO BUFFS!
54
;;; Englewood CO 80112-5776 USA 1+ (303) 397-2807
56
;;; LCD Archive Entry:
58
;;; follow-mouse|Kevin Rodgers|kevinr@ihs.com|
59
;;; Automatically select the window under the mouse|
60
;;; $Date: 2002/07/21 14:05:54 $|$Revision: 1.1 $||
63
(provide 'follow-mouse)
65
(defvar follow-mouse nil
66
"If non-nil, `\\<special-event-map>\\[follow-mouse-select-window]' \
67
selects the window under the mouse.
68
Don't set this variable directly; use `\\[toggle-follow-mouse]' instead")
70
(defvar follow-mouse-deselect-active-minibuffer t
71
"*If non-nil, `\\<special-event-map>\\[follow-mouse-select-window]' \
72
deselects an active minibuffer window.")
73
(put 'follow-mouse-deselect-active-minibuffer 'variable-interactive
74
"XLeave active minibuffer window? (t or nil): ")
76
(defvar follow-mouse-auto-raise-frame t
77
"*If non-nil, `\\<special-event-map>\\[follow-mouse-select-window]' \
78
raises the frame as well.")
79
(put 'follow-mouse-auto-raise-frame 'variable-interactive
80
"XAutomatically raise the selected window's frame? (t or nil): ")
83
(defun turn-on-follow-mouse ()
84
"Moving the mouse will automatically select the window under it."
86
(toggle-follow-mouse 1 (interactive-p)))
89
(defun turn-off-follow-mouse ()
90
"Moving the mouse will not automatically select the window under it."
92
(toggle-follow-mouse 0 (interactive-p)))
95
(defun toggle-follow-mouse (&optional arg verbose)
96
"Toggle whether moving the mouse automatically selects the window under it.
97
If the optional prefix ARG is specified, follow-mouse is enabled if it is
98
positive, and disabled otherwise. If called interactively, or the optional
99
VERBOSE argument is non-nil, display a confirmation message."
100
(interactive (list current-prefix-arg t))
102
(if (> (prefix-numeric-value arg) 0)
107
(cond ((setq follow-mouse (not follow-mouse))
108
;; Save the current value of track-mouse before (re)setting it:
109
(put 'follow-mouse 'track-mouse track-mouse)
111
;; Save the current binding of [mouse-movement] before
113
(put 'follow-mouse 'mouse-movement
114
(lookup-key special-event-map [mouse-movement]))
115
(define-key special-event-map [mouse-movement]
116
'follow-mouse-select-window))
118
;; Restore the previous value of track-mouse:
119
(setq track-mouse (get 'follow-mouse 'track-mouse))
120
;; Restore the previous binding of [mouse-movement]:
121
(define-key special-event-map [mouse-movement]
122
(get 'follow-mouse 'mouse-movement))))
123
(if (or (interactive-p) verbose)
124
(message "Follow mouse is %s"
125
(if follow-mouse "enabled" "disabled"))))
126
(if (or (interactive-p) verbose)
127
(message "Follow mouse is already %s"
128
(if follow-mouse "enabled" "disabled"))))
129
;; Return the result:
132
(defun follow-mouse-select-window (event)
133
"*Like `mouse-select-window', if `follow-mouse' is set.
134
Otherwise, do nothing; in particular, don't generate an error if EVENT
135
occurs outside a window or in an inactive minibuffer window.
136
See `follow-mouse-deselect-active-minibuffer' and
137
`follow-mouse-auto-raise-frame'."
139
(prog1 (if follow-mouse
140
(let ((current-window (get-buffer-window (current-buffer)))
141
(event-window (posn-window (event-start event))))
142
(if (and (or (not (window-minibuffer-p current-window))
143
(not (minibuffer-window-active-p current-window))
144
follow-mouse-deselect-active-minibuffer)
145
(windowp event-window)
146
(or (not (window-minibuffer-p event-window))
147
(minibuffer-window-active-p event-window)))
148
(if follow-mouse-auto-raise-frame
149
(mouse-select-window event)
150
(select-window event-window)))))
152
(setq unread-command-events
153
(nconc unread-command-events (list event)))))
155
;;;; follow-mouse.el ends here
b'\\ No newline at end of file'