Commit | Line | Data |
---|---|---|
dc6d9681 | 1 | ;;; frame.el --- multi-frame management independent of window systems. |
c88ab9ce | 2 | |
8f1204db | 3 | ;;;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. |
3a801d0c | 4 | |
fc68affa | 5 | ;; Maintainer: FSF |
fd7fa35a | 6 | ;; Keywords: internal |
fc68affa | 7 | |
64c669bc JB |
8 | ;;; This file is part of GNU Emacs. |
9 | ;;; | |
10 | ;;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;;; it under the terms of the GNU General Public License as published by | |
de49a6d3 | 12 | ;;; the Free Software Foundation; either version 2, or (at your option) |
64c669bc JB |
13 | ;;; any later version. |
14 | ;;; | |
15 | ;;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;;; GNU General Public License for more details. | |
19 | ;;; | |
20 | ;;; You should have received a copy of the GNU General Public License | |
21 | ;;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 | ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | ||
fc68affa ER |
24 | ;;; Code: |
25 | ||
dc6d9681 JB |
26 | (defvar frame-creation-function nil |
27 | "Window-system dependent function to call to create a new frame. | |
28 | The window system startup file should set this to its frame creation | |
64c669bc JB |
29 | function, which should take an alist of parameters as its argument.") |
30 | ||
7eadab74 JB |
31 | ;;; The initial value given here for this must ask for a minibuffer. |
32 | ;;; There must always exist a frame with a minibuffer, and after we | |
33 | ;;; delete the terminal frame, this will be the only frame. | |
9e2b097b | 34 | (defvar initial-frame-alist '((minibuffer . t)) |
eaa974e1 JB |
35 | "Alist of frame parameters for creating the initial X window frame. |
36 | You can set this in your `.emacs' file; for example, | |
dc6d9681 | 37 | (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55))) |
de17da15 RS |
38 | Parameters specified here supersede the values given in `default-frame-alist'. |
39 | ||
40 | If the value calls for a frame without a minibuffer, and you have not created | |
41 | a minibuffer frame on your own, one is created according to | |
7eadab74 | 42 | `minibuffer-frame-alist'. |
de17da15 RS |
43 | |
44 | You can specify geometry-related options for just the initial frame | |
45 | by setting this variable in your `.emacs' file; however, they won't | |
46 | take affect until Emacs reads `.emacs', which happens after first creating | |
47 | the frame. If you want the frame to have the proper geometry as soon | |
48 | as it appears, you need to use this three-step process: | |
49 | * Specify X resources to give the geometry you want. | |
50 | * Set `default-frame-alist' to override these options so that they | |
51 | don't affect subsequent frames. | |
52 | * Set `initial-frame-alist' in a way that matches the X resources, | |
53 | to override what you put in `default-frame-alist'.") | |
64c669bc | 54 | |
7eadab74 | 55 | (defvar minibuffer-frame-alist '((width . 80) (height . 2)) |
eaa974e1 JB |
56 | "Alist of frame parameters for initially creating a minibuffer frame. |
57 | You can set this in your `.emacs' file; for example, | |
dc6d9681 | 58 | (setq minibuffer-frame-alist |
7eadab74 | 59 | '((top . 1) (left . 1) (width . 80) (height . 2))) |
eaa974e1 JB |
60 | Parameters specified here supersede the values given in |
61 | `default-frame-alist'.") | |
64c669bc | 62 | |
dc6d9681 | 63 | (defvar pop-up-frame-alist nil |
eaa974e1 | 64 | "Alist of frame parameters used when creating pop-up frames. |
dc6d9681 | 65 | Pop-up frames are used for completions, help, and the like. |
64c669bc | 66 | This variable can be set in your init file, like this: |
dc6d9681 | 67 | (setq pop-up-frame-alist '((width . 80) (height . 20))) |
eb8c3be9 | 68 | These supersede the values given in `default-frame-alist'.") |
64c669bc | 69 | |
dc6d9681 | 70 | (setq pop-up-frame-function |
64c669bc | 71 | (function (lambda () |
6eb018ba | 72 | (make-frame pop-up-frame-alist)))) |
64c669bc | 73 | |
8a9e86e6 RS |
74 | (defvar special-display-frame-alist |
75 | '((height . 14) (width . 80) (unsplittable . t)) | |
76 | "*Alist of frame parameters used when creating special frames. | |
77 | Special frames are used for buffers whose names are in | |
78 | `special-display-buffer-names' and for buffers whose names match | |
79 | one of the regular expressions in `special-display-regexps'. | |
80 | This variable can be set in your init file, like this: | |
81 | (setq special-display-frame-alist '((width . 80) (height . 20))) | |
82 | These supersede the values given in `default-frame-alist'.") | |
83 | ||
84 | ;; Display BUFFER in its own frame, reusing an existing window if any. | |
85 | ;; Return the window chosen. | |
86 | ;; Currently we do not insist on selecting the window within its frame. | |
95e6cf39 RS |
87 | ;; If ARGS is an alist, use it as a list of frame parameter specs. |
88 | ;; If ARGS is a list whose car is a symbol. | |
89 | ;; use (car ARGS) as a function to do the work. | |
90 | ;; Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args. | |
91 | (defun special-display-popup-frame (buffer &optional args) | |
92 | (if (and args (symbolp (car args))) | |
93 | (apply (car args) buffer (cdr args)) | |
94 | (let ((window (get-buffer-window buffer t))) | |
95 | (if window | |
96 | ;; If we have a window already, make it visible. | |
97 | (let ((frame (window-frame window))) | |
98 | (make-frame-visible frame) | |
99 | (raise-frame frame) | |
100 | window) | |
101 | ;; If no window yet, make one in a new frame. | |
102 | (let ((frame (make-frame (append args special-display-frame-alist)))) | |
103 | (set-window-buffer (frame-selected-window frame) buffer) | |
104 | (set-window-dedicated-p (frame-selected-window frame) t) | |
105 | (frame-selected-window frame)))))) | |
8a9e86e6 RS |
106 | |
107 | (setq special-display-function 'special-display-popup-frame) | |
924be53a RS |
108 | |
109 | ;; Handle delete-frame events from the X server. | |
110 | (defun handle-delete-frame (event) | |
111 | (interactive "e") | |
112 | (let ((frame (posn-window (event-start event))) | |
113 | (i 0) | |
114 | (tail (frame-list))) | |
115 | (while tail | |
116 | (and (frame-visible-p (car tail)) | |
117 | (not (eq (car tail) frame)) | |
118 | (setq i (1+ i))) | |
119 | (setq tail (cdr tail))) | |
120 | (if (> i 0) | |
121 | (delete-frame frame t) | |
122 | (kill-emacs)))) | |
64c669bc | 123 | \f |
dc6d9681 | 124 | ;;;; Arrangement of frames at startup |
64c669bc JB |
125 | |
126 | ;;; 1) Load the window system startup file from the lisp library and read the | |
127 | ;;; high-priority arguments (-q and the like). The window system startup | |
dc6d9681 | 128 | ;;; file should create any frames specified in the window system defaults. |
64c669bc | 129 | ;;; |
dc6d9681 | 130 | ;;; 2) If no frames have been opened, we open an initial text frame. |
64c669bc JB |
131 | ;;; |
132 | ;;; 3) Once the init file is done, we apply any newly set parameters | |
dc6d9681 | 133 | ;;; in initial-frame-alist to the frame. |
64c669bc | 134 | |
fc4d4afb RS |
135 | ;; These are now called explicitly at the proper times, |
136 | ;; since that is easier to understand. | |
137 | ;; Actually using hooks within Emacs is bad for future maintenance. --rms. | |
138 | ;; (add-hook 'before-init-hook 'frame-initialize) | |
139 | ;; (add-hook 'window-setup-hook 'frame-notice-user-settings) | |
64c669bc | 140 | |
dc6d9681 JB |
141 | ;;; If we create the initial frame, this is it. |
142 | (defvar frame-initial-frame nil) | |
64c669bc | 143 | |
3f2f8c83 RS |
144 | ;; Record the parameters used in frame-initialize to make the initial frame. |
145 | (defvar frame-initial-frame-alist) | |
146 | ||
791e09d8 RS |
147 | (defvar frame-initial-geometry-arguments nil) |
148 | ||
64c669bc | 149 | ;;; startup.el calls this function before loading the user's init |
dc6d9681 | 150 | ;;; file - if there is no frame with a minibuffer open now, create |
64c669bc | 151 | ;;; one to display messages while loading the init file. |
dc6d9681 | 152 | (defun frame-initialize () |
64c669bc JB |
153 | |
154 | ;; Are we actually running under a window system at all? | |
155 | (if (and window-system (not noninteractive)) | |
7eadab74 JB |
156 | (progn |
157 | ;; If there is no frame with a minibuffer besides the terminal | |
158 | ;; frame, then we need to create the opening frame. Make sure | |
159 | ;; it has a minibuffer, but let initial-frame-alist omit the | |
160 | ;; minibuffer spec. | |
161 | (or (delq terminal-frame (minibuffer-frame-list)) | |
36fc9c9f | 162 | (progn |
3f2f8c83 RS |
163 | (setq frame-initial-frame-alist |
164 | (append initial-frame-alist default-frame-alist)) | |
a8bb5882 RS |
165 | ;; Record these with their default values |
166 | ;; if they don't have any values explicitly. | |
167 | (or (assq 'vertical-scroll-bars frame-initial-frame-alist) | |
168 | (setq frame-initial-frame-alist | |
169 | (cons '(vertical-scroll-bars . t) | |
170 | frame-initial-frame-alist))) | |
171 | (or (assq 'horizontal-scroll-bars frame-initial-frame-alist) | |
172 | (setq frame-initial-frame-alist | |
173 | (cons '(horizontal-scroll-bars . t) | |
174 | frame-initial-frame-alist))) | |
36fc9c9f RS |
175 | (setq default-minibuffer-frame |
176 | (setq frame-initial-frame | |
6eb018ba | 177 | (make-frame initial-frame-alist))) |
11281034 RS |
178 | ;; Delete any specifications for window geometry parameters |
179 | ;; so that we won't reapply them in frame-notice-user-settings. | |
180 | ;; It would be wrong to reapply them then, | |
181 | ;; because that would override explicit user resizing. | |
58bf6042 | 182 | (setq initial-frame-alist |
c2079f0a | 183 | (frame-remove-geometry-params initial-frame-alist)))) |
dc6d9681 JB |
184 | ;; At this point, we know that we have a frame open, so we |
185 | ;; can delete the terminal frame. | |
186 | (delete-frame terminal-frame) | |
187 | (setq terminal-frame nil)) | |
64c669bc JB |
188 | |
189 | ;; No, we're not running a window system. Arrange to cause errors. | |
dc6d9681 | 190 | (setq frame-creation-function |
9198945a MB |
191 | (function |
192 | (lambda (parameters) | |
193 | (error | |
8290babd | 194 | "Can't create multiple frames without a window system")))))) |
64c669bc | 195 | |
7eadab74 JB |
196 | ;;; startup.el calls this function after loading the user's init |
197 | ;;; file. Now default-frame-alist and initial-frame-alist contain | |
198 | ;;; information to which we must react; do what needs to be done. | |
dc6d9681 | 199 | (defun frame-notice-user-settings () |
7eadab74 | 200 | |
2ffa6186 RS |
201 | ;; Make menu-bar-mode and default-frame-alist consistent. |
202 | (let ((default (assq 'menu-bar-lines default-frame-alist))) | |
203 | (if default | |
204 | (setq menu-bar-mode (not (eq (cdr default) 0))) | |
205 | (setq default-frame-alist | |
206 | (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0)) | |
207 | default-frame-alist)))) | |
208 | ||
7eadab74 JB |
209 | ;; Creating and deleting frames may shift the selected frame around, |
210 | ;; and thus the current buffer. Protect against that. We don't | |
211 | ;; want to use save-excursion here, because that may also try to set | |
212 | ;; the buffer of the selected window, which fails when the selected | |
213 | ;; window is the minibuffer. | |
214 | (let ((old-buffer (current-buffer))) | |
215 | ||
216 | ;; If the initial frame is still around, apply initial-frame-alist | |
217 | ;; and default-frame-alist to it. | |
218 | (if (frame-live-p frame-initial-frame) | |
219 | ||
220 | ;; The initial frame we create above always has a minibuffer. | |
221 | ;; If the user wants to remove it, or make it a minibuffer-only | |
222 | ;; frame, then we'll have to delete the current frame and make a | |
223 | ;; new one; you can't remove or add a root window to/from an | |
224 | ;; existing frame. | |
225 | ;; | |
ec558adc JB |
226 | ;; NOTE: default-frame-alist was nil when we created the |
227 | ;; existing frame. We need to explicitly include | |
228 | ;; default-frame-alist in the parameters of the screen we | |
229 | ;; create here, so that its new value, gleaned from the user's | |
230 | ;; .emacs file, will be applied to the existing screen. | |
7eadab74 JB |
231 | (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist) |
232 | (assq 'minibuffer default-frame-alist) | |
233 | '(minibuffer . t))) | |
234 | t)) | |
235 | ;; Create the new frame. | |
b65e2f74 RS |
236 | (let (parms new) |
237 | ;; If the frame isn't visible yet, wait till it is. | |
238 | ;; If the user has to position the window, | |
239 | ;; Emacs doesn't know its real position until | |
240 | ;; the frame is seen to be visible. | |
241 | (while (not (cdr (assq 'visibility | |
242 | (frame-parameters frame-initial-frame)))) | |
243 | (sleep-for 1)) | |
244 | (setq parms (append initial-frame-alist | |
6eb018ba RS |
245 | default-frame-alist |
246 | (frame-parameters frame-initial-frame) | |
247 | nil)) | |
c1e67401 RS |
248 | ;; Get rid of `reverse', because that was handled |
249 | ;; when we first made the frame. | |
250 | (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms))) | |
251 | (if (assq 'height frame-initial-geometry-arguments) | |
5b66a32f | 252 | (setq parms (frame-delete-all 'height parms))) |
c1e67401 | 253 | (if (assq 'width frame-initial-geometry-arguments) |
5b66a32f | 254 | (setq parms (frame-delete-all 'width parms))) |
c1e67401 | 255 | (if (assq 'left frame-initial-geometry-arguments) |
5b66a32f | 256 | (setq parms (frame-delete-all 'left parms))) |
c1e67401 | 257 | (if (assq 'top frame-initial-geometry-arguments) |
5b66a32f | 258 | (setq parms (frame-delete-all 'top parms))) |
c1e67401 RS |
259 | (setq new |
260 | (make-frame | |
261 | ;; Use the geometry args that created the existing | |
262 | ;; frame, rather than the parms we get for it. | |
263 | (append frame-initial-geometry-arguments parms))) | |
7eadab74 JB |
264 | ;; The initial frame, which we are about to delete, may be |
265 | ;; the only frame with a minibuffer. If it is, create a | |
266 | ;; new one. | |
267 | (or (delq frame-initial-frame (minibuffer-frame-list)) | |
6eb018ba | 268 | (make-frame (append minibuffer-frame-alist |
7eadab74 JB |
269 | '((minibuffer . only))))) |
270 | ||
271 | ;; If the initial frame is serving as a surrogate | |
272 | ;; minibuffer frame for any frames, we need to wean them | |
273 | ;; onto a new frame. The default-minibuffer-frame | |
274 | ;; variable must be handled similarly. | |
275 | (let ((users-of-initial | |
276 | (filtered-frame-list | |
277 | (function (lambda (frame) | |
278 | (and (not (eq frame frame-initial-frame)) | |
279 | (eq (window-frame | |
280 | (minibuffer-window frame)) | |
281 | frame-initial-frame))))))) | |
282 | (if (or users-of-initial | |
283 | (eq default-minibuffer-frame frame-initial-frame)) | |
284 | ||
285 | ;; Choose an appropriate frame. Prefer frames which | |
286 | ;; are only minibuffers. | |
287 | (let* ((new-surrogate | |
288 | (car | |
289 | (or (filtered-frame-list | |
290 | (function | |
291 | (lambda (frame) | |
292 | (eq (cdr (assq 'minibuffer | |
293 | (frame-parameters frame))) | |
294 | 'only)))) | |
295 | (minibuffer-frame-list)))) | |
296 | (new-minibuffer (minibuffer-window new-surrogate))) | |
297 | ||
298 | (if (eq default-minibuffer-frame frame-initial-frame) | |
299 | (setq default-minibuffer-frame new-surrogate)) | |
300 | ||
301 | ;; Wean the frames using frame-initial-frame as | |
302 | ;; their minibuffer frame. | |
303 | (mapcar | |
304 | (function | |
305 | (lambda (frame) | |
306 | (modify-frame-parameters | |
307 | frame (list (cons 'minibuffer new-minibuffer))))) | |
308 | users-of-initial)))) | |
ec558adc JB |
309 | |
310 | ;; Redirect events enqueued at this frame to the new frame. | |
311 | ;; Is this a good idea? | |
7eadab74 | 312 | (redirect-frame-focus frame-initial-frame new) |
ec558adc | 313 | |
7eadab74 | 314 | ;; Finally, get rid of the old frame. |
0cffbbb9 | 315 | (delete-frame frame-initial-frame t)) |
7eadab74 JB |
316 | |
317 | ;; Otherwise, we don't need all that rigamarole; just apply | |
318 | ;; the new parameters. | |
3f2f8c83 RS |
319 | (let (newparms allparms tail) |
320 | (setq allparms (append initial-frame-alist | |
321 | default-frame-alist)) | |
5b66a32f RS |
322 | (if (assq 'height frame-initial-geometry-arguments) |
323 | (setq allparms (frame-delete-all 'height allparms))) | |
324 | (if (assq 'width frame-initial-geometry-arguments) | |
325 | (setq allparms (frame-delete-all 'width allparms))) | |
326 | (if (assq 'left frame-initial-geometry-arguments) | |
327 | (setq allparms (frame-delete-all 'left allparms))) | |
328 | (if (assq 'top frame-initial-geometry-arguments) | |
329 | (setq allparms (frame-delete-all 'top allparms))) | |
3f2f8c83 RS |
330 | (setq tail allparms) |
331 | ;; Find just the parms that have changed since we first | |
332 | ;; made this frame. Those are the ones actually set by | |
333 | ;; the init file. For those parms whose values we already knew | |
334 | ;; (such as those spec'd by command line options) | |
335 | ;; it is undesirable to specify the parm again | |
336 | ;; once the user has seen the frame and been able to alter it | |
337 | ;; manually. | |
338 | (while tail | |
339 | (let (newval oldval) | |
340 | (setq oldval (cdr (assq (car (car tail)) | |
341 | frame-initial-frame-alist))) | |
342 | (setq newval (cdr (assq (car (car tail)) allparms))) | |
343 | (or (eq oldval newval) | |
344 | (setq newparms | |
345 | (cons (cons (car (car tail)) newval) newparms)))) | |
346 | (setq tail (cdr tail))) | |
86e58378 | 347 | (setq newparms (nreverse newparms)) |
3f2f8c83 | 348 | (modify-frame-parameters frame-initial-frame |
86e58378 RS |
349 | newparms) |
350 | (if (assq 'font newparms) | |
351 | (frame-update-faces frame-initial-frame))))) | |
64c669bc | 352 | |
7eadab74 JB |
353 | ;; Restore the original buffer. |
354 | (set-buffer old-buffer) | |
355 | ||
356 | ;; Make sure the initial frame can be GC'd if it is ever deleted. | |
d202f1f2 JB |
357 | ;; Make sure frame-notice-user-settings does nothing if called twice. |
358 | (setq frame-initial-frame nil))) | |
64c669bc | 359 | |
5b66a32f RS |
360 | ;; Delete from ALIST all elements whose car is KEY. |
361 | ;; Return the modified alist. | |
362 | (defun frame-delete-all (key alist) | |
9759578f | 363 | (setq alist (copy-sequence alist)) |
5b66a32f RS |
364 | (let ((tail alist)) |
365 | (while tail | |
366 | (if (eq (car (car tail)) key) | |
367 | (setq alist (delq (car tail) alist))) | |
368 | (setq tail (cdr tail))) | |
369 | alist)) | |
64c669bc | 370 | \f |
7eadab74 | 371 | ;;;; Creation of additional frames, and other frame miscellanea |
dc6d9681 | 372 | |
7eadab74 | 373 | ;;; Return some frame other than the current frame, creating one if |
eb8c3be9 | 374 | ;;; necessary. Note that the minibuffer frame, if separate, is not |
7eadab74 | 375 | ;;; considered (see next-frame). |
7253d8e0 | 376 | (defun get-other-frame () |
dc6d9681 | 377 | (let ((s (if (equal (next-frame (selected-frame)) (selected-frame)) |
6eb018ba | 378 | (make-frame) |
dc6d9681 | 379 | (next-frame (selected-frame))))) |
64c669bc JB |
380 | s)) |
381 | ||
dc6d9681 JB |
382 | (defun next-multiframe-window () |
383 | "Select the next window, regardless of which frame it is on." | |
64c669bc JB |
384 | (interactive) |
385 | (select-window (next-window (selected-window) | |
386 | (> (minibuffer-depth) 0) | |
387 | t))) | |
388 | ||
dc6d9681 JB |
389 | (defun previous-multiframe-window () |
390 | "Select the previous window, regardless of which frame it is on." | |
64c669bc JB |
391 | (interactive) |
392 | (select-window (previous-window (selected-window) | |
393 | (> (minibuffer-depth) 0) | |
394 | t))) | |
395 | ||
6d73e337 RS |
396 | (defun make-frame-on-display (display &optional parameters) |
397 | "Make a frame on display DISPLAY. | |
398 | The optional second argument PARAMETERS specifies additional frame parameters." | |
399 | (interactive "sMake frame on display: ") | |
400 | (make-frame (cons (cons 'display display) parameters))) | |
401 | ||
92e443b1 | 402 | ;; Alias, kept temporarily. |
31e1d920 | 403 | (defalias 'new-frame 'make-frame) |
92e443b1 | 404 | (defun make-frame (&optional parameters) |
dc6d9681 | 405 | "Create a new frame, displaying the current buffer. |
bc93c097 | 406 | |
43a2e52c | 407 | Optional argument PARAMETERS is an alist of parameters for the new |
dc6d9681 | 408 | frame. Specifically, PARAMETERS is a list of pairs, each having one |
43a2e52c JB |
409 | of the following forms: |
410 | ||
eaa974e1 | 411 | \(name . STRING) - The frame should be named STRING. |
43a2e52c | 412 | |
eaa974e1 | 413 | \(height . NUMBER) - The frame should be NUMBER text lines high. If |
43a2e52c JB |
414 | this parameter is present, the width parameter must also be |
415 | given. | |
416 | ||
eaa974e1 | 417 | \(width . NUMBER) - The frame should be NUMBER characters in width. |
43a2e52c JB |
418 | If this parameter is present, the height parameter must also |
419 | be given. | |
420 | ||
eaa974e1 | 421 | \(minibuffer . t) - the frame should have a minibuffer |
0ca90494 | 422 | \(minibuffer . nil) - the frame should have no minibuffer |
eaa974e1 | 423 | \(minibuffer . only) - the frame should contain only a minibuffer |
8dbd5c78 | 424 | \(minibuffer . WINDOW) - the frame should use WINDOW as its minibuffer window." |
64c669bc | 425 | (interactive) |
4133ab49 RS |
426 | (let ((nframe)) |
427 | (run-hooks 'before-make-frame-hook) | |
428 | (setq nframe (funcall frame-creation-function parameters)) | |
429 | (run-hooks 'after-make-frame-hook) | |
430 | nframe)) | |
64c669bc | 431 | |
7eadab74 JB |
432 | (defun filtered-frame-list (predicate) |
433 | "Return a list of all live frames which satisfy PREDICATE." | |
434 | (let ((frames (frame-list)) | |
435 | good-frames) | |
436 | (while (consp frames) | |
437 | (if (funcall predicate (car frames)) | |
438 | (setq good-frames (cons (car frames) good-frames))) | |
439 | (setq frames (cdr frames))) | |
440 | good-frames)) | |
441 | ||
442 | (defun minibuffer-frame-list () | |
443 | "Return a list of all frames with their own minibuffers." | |
444 | (filtered-frame-list | |
445 | (function (lambda (frame) | |
446 | (eq frame (window-frame (minibuffer-window frame))))))) | |
447 | ||
58bf6042 JB |
448 | (defun frame-remove-geometry-params (param-list) |
449 | "Return the parameter list PARAM-LIST, but with geometry specs removed. | |
450 | This deletes all bindings in PARAM-LIST for `top', `left', `width', | |
791e09d8 | 451 | `height', `user-size' and `user-position' parameters. |
58bf6042 JB |
452 | Emacs uses this to avoid overriding explicit moves and resizings from |
453 | the user during startup." | |
454 | (setq param-list (cons nil param-list)) | |
455 | (let ((tail param-list)) | |
456 | (while (consp (cdr tail)) | |
457 | (if (and (consp (car (cdr tail))) | |
791e09d8 RS |
458 | (memq (car (car (cdr tail))) |
459 | '(height width top left user-position user-size))) | |
460 | (progn | |
461 | (setq frame-initial-geometry-arguments | |
462 | (cons (car (cdr tail)) frame-initial-geometry-arguments)) | |
463 | (setcdr tail (cdr (cdr tail)))) | |
58bf6042 | 464 | (setq tail (cdr tail))))) |
e11c3dc2 KH |
465 | (setq frame-initial-geometry-arguments |
466 | (nreverse frame-initial-geometry-arguments)) | |
58bf6042 JB |
467 | (cdr param-list)) |
468 | ||
469 | ||
ceab6935 | 470 | (defun other-frame (arg) |
a569dbc3 | 471 | "Select the ARG'th different visible frame, and raise it. |
ceab6935 RM |
472 | All frames are arranged in a cyclic order. |
473 | This command selects the frame ARG steps away in that order. | |
474 | A negative ARG moves in the opposite order." | |
475 | (interactive "p") | |
476 | (let ((frame (selected-frame))) | |
477 | (while (> arg 0) | |
a569dbc3 RM |
478 | (setq frame (next-frame frame)) |
479 | (while (not (eq (frame-visible-p frame) t)) | |
480 | (setq frame (next-frame frame))) | |
481 | (setq arg (1- arg))) | |
ceab6935 | 482 | (while (< arg 0) |
a569dbc3 RM |
483 | (setq frame (previous-frame frame)) |
484 | (while (not (eq (frame-visible-p frame) t)) | |
485 | (setq frame (previous-frame frame))) | |
915cfd1f | 486 | (setq arg (1+ arg))) |
ceab6935 | 487 | (raise-frame frame) |
699213bc | 488 | (select-frame frame) |
2b88f7a0 | 489 | (set-mouse-position (selected-frame) (1- (frame-width)) 0) |
699213bc | 490 | (unfocus-frame))) |
64c669bc | 491 | \f |
dc6d9681 JB |
492 | ;;;; Frame configurations |
493 | ||
494 | (defun current-frame-configuration () | |
495 | "Return a list describing the positions and states of all frames. | |
376a7584 JB |
496 | Its car is `frame-configuration'. |
497 | Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG), | |
498 | where | |
499 | FRAME is a frame object, | |
500 | ALIST is an association list specifying some of FRAME's parameters, and | |
501 | WINDOW-CONFIG is a window configuration object for FRAME." | |
502 | (cons 'frame-configuration | |
503 | (mapcar (function | |
504 | (lambda (frame) | |
505 | (list frame | |
506 | (frame-parameters frame) | |
507 | (current-window-configuration frame)))) | |
508 | (frame-list)))) | |
dc6d9681 | 509 | |
68cd265f | 510 | (defun set-frame-configuration (configuration &optional nodelete) |
dc6d9681 JB |
511 | "Restore the frames to the state described by CONFIGURATION. |
512 | Each frame listed in CONFIGURATION has its position, size, window | |
68cd265f | 513 | configuration, and other parameters set as specified in CONFIGURATION. |
a78db71c RS |
514 | Ordinarily, this function deletes all existing frames not |
515 | listed in CONFIGURATION. But if optional second argument NODELETE | |
5da841d2 | 516 | is given and non-nil, the unwanted frames are iconified instead." |
376a7584 JB |
517 | (or (frame-configuration-p configuration) |
518 | (signal 'wrong-type-argument | |
519 | (list 'frame-configuration-p configuration))) | |
520 | (let ((config-alist (cdr configuration)) | |
521 | frames-to-delete) | |
06b1a5ef | 522 | (mapcar (function |
dc6d9681 | 523 | (lambda (frame) |
376a7584 | 524 | (let ((parameters (assq frame config-alist))) |
06b1a5ef JB |
525 | (if parameters |
526 | (progn | |
98e9d14b JB |
527 | (modify-frame-parameters |
528 | frame | |
529 | ;; Since we can't set a frame's minibuffer status, | |
530 | ;; we might as well omit the parameter altogether. | |
531 | (let* ((parms (nth 1 parameters)) | |
532 | (mini (assq 'minibuffer parms))) | |
533 | (if mini (setq parms (delq mini parms))) | |
534 | parms)) | |
06b1a5ef | 535 | (set-window-configuration (nth 2 parameters))) |
dc6d9681 JB |
536 | (setq frames-to-delete (cons frame frames-to-delete)))))) |
537 | (frame-list)) | |
a78db71c | 538 | (if nodelete |
5da841d2 RS |
539 | ;; Note: making frames invisible here was tried |
540 | ;; but led to some strange behavior--each time the frame | |
541 | ;; was made visible again, the window manager asked afresh | |
542 | ;; for where to put it. | |
543 | (mapcar 'iconify-frame frames-to-delete) | |
a78db71c | 544 | (mapcar 'delete-frame frames-to-delete)))) |
64c669bc | 545 | |
376a7584 JB |
546 | (defun frame-configuration-p (object) |
547 | "Return non-nil if OBJECT seems to be a frame configuration. | |
548 | Any list whose car is `frame-configuration' is assumed to be a frame | |
549 | configuration." | |
550 | (and (consp object) | |
551 | (eq (car object) 'frame-configuration))) | |
552 | ||
64c669bc | 553 | \f |
dc6d9681 JB |
554 | ;;;; Convenience functions for accessing and interactively changing |
555 | ;;;; frame parameters. | |
64c669bc | 556 | |
151bdc83 | 557 | (defun frame-height (&optional frame) |
dc6d9681 JB |
558 | "Return number of lines available for display on FRAME. |
559 | If FRAME is omitted, describe the currently selected frame." | |
151bdc83 | 560 | (cdr (assq 'height (frame-parameters frame)))) |
dc6d9681 JB |
561 | |
562 | (defun frame-width (&optional frame) | |
563 | "Return number of columns available for display on FRAME. | |
564 | If FRAME is omitted, describe the currently selected frame." | |
151bdc83 | 565 | (cdr (assq 'width (frame-parameters frame)))) |
dc6d9681 | 566 | |
64c669bc | 567 | (defun set-default-font (font-name) |
7eadab74 JB |
568 | "Set the font of the selected frame to FONT. |
569 | When called interactively, prompt for the name of the font to use." | |
64c669bc | 570 | (interactive "sFont name: ") |
dc6d9681 | 571 | (modify-frame-parameters (selected-frame) |
4033f46b RS |
572 | (list (cons 'font font-name))) |
573 | ;; Update faces that want a bold or italic version of the default font. | |
574 | (frame-update-faces (selected-frame))) | |
64c669bc | 575 | |
8290babd | 576 | (defun set-background-color (color-name) |
7eadab74 JB |
577 | "Set the background color of the selected frame to COLOR. |
578 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 579 | (interactive "sColor: ") |
dc6d9681 | 580 | (modify-frame-parameters (selected-frame) |
7eadab74 | 581 | (list (cons 'background-color color-name)))) |
64c669bc | 582 | |
8290babd | 583 | (defun set-foreground-color (color-name) |
7eadab74 JB |
584 | "Set the foreground color of the selected frame to COLOR. |
585 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 586 | (interactive "sColor: ") |
dc6d9681 | 587 | (modify-frame-parameters (selected-frame) |
7eadab74 | 588 | (list (cons 'foreground-color color-name)))) |
64c669bc JB |
589 | |
590 | (defun set-cursor-color (color-name) | |
7eadab74 JB |
591 | "Set the text cursor color of the selected frame to COLOR. |
592 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 593 | (interactive "sColor: ") |
dc6d9681 | 594 | (modify-frame-parameters (selected-frame) |
7eadab74 | 595 | (list (cons 'cursor-color color-name)))) |
64c669bc | 596 | |
eaa974e1 | 597 | (defun set-mouse-color (color-name) |
7eadab74 JB |
598 | "Set the color of the mouse pointer of the selected frame to COLOR. |
599 | When called interactively, prompt for the name of the color to use." | |
64c669bc | 600 | (interactive "sColor: ") |
dc6d9681 | 601 | (modify-frame-parameters (selected-frame) |
7eadab74 JB |
602 | (list (cons 'mouse-color color-name)))) |
603 | ||
eaa974e1 JB |
604 | (defun set-border-color (color-name) |
605 | "Set the color of the border of the selected frame to COLOR. | |
606 | When called interactively, prompt for the name of the color to use." | |
607 | (interactive "sColor: ") | |
608 | (modify-frame-parameters (selected-frame) | |
609 | (list (cons 'border-color color-name)))) | |
610 | ||
611 | (defun auto-raise-mode (arg) | |
7eadab74 | 612 | "Toggle whether or not the selected frame should auto-raise. |
79e6ae33 RS |
613 | With arg, turn auto-raise mode on if and only if arg is positive. |
614 | Note that this controls Emacs's own auto-raise feature. | |
615 | Some window managers allow you to enable auto-raise for certain windows. | |
616 | You can use that for Emacs windows if you wish, but if you do, | |
617 | that is beyond the control of Emacs and this command has no effect on it." | |
7eadab74 JB |
618 | (interactive "P") |
619 | (if (null arg) | |
620 | (setq arg | |
621 | (if (cdr (assq 'auto-raise (frame-parameters (selected-frame)))) | |
622 | -1 1))) | |
dc6d9681 | 623 | (modify-frame-parameters (selected-frame) |
7eadab74 JB |
624 | (list (cons 'auto-raise (> arg 0))))) |
625 | ||
eaa974e1 | 626 | (defun auto-lower-mode (arg) |
7eadab74 | 627 | "Toggle whether or not the selected frame should auto-lower. |
79e6ae33 RS |
628 | With arg, turn auto-lower mode on if and only if arg is positive. |
629 | Note that this controls Emacs's own auto-lower feature. | |
630 | Some window managers allow you to enable auto-lower for certain windows. | |
631 | You can use that for Emacs windows if you wish, but if you do, | |
632 | that is beyond the control of Emacs and this command has no effect on it." | |
7eadab74 JB |
633 | (interactive "P") |
634 | (if (null arg) | |
635 | (setq arg | |
636 | (if (cdr (assq 'auto-lower (frame-parameters (selected-frame)))) | |
637 | -1 1))) | |
dc6d9681 | 638 | (modify-frame-parameters (selected-frame) |
7eadab74 JB |
639 | (list (cons 'auto-lower (> arg 0))))) |
640 | ||
7e85c6b5 | 641 | (defun toggle-scroll-bar (arg) |
0ca90494 JB |
642 | "Toggle whether or not the selected frame has vertical scroll bars. |
643 | With arg, turn vertical scroll bars on if and only if arg is positive." | |
7eadab74 JB |
644 | (interactive "P") |
645 | (if (null arg) | |
646 | (setq arg | |
0ca90494 | 647 | (if (cdr (assq 'vertical-scroll-bars |
7eadab74 JB |
648 | (frame-parameters (selected-frame)))) |
649 | -1 1))) | |
dc6d9681 | 650 | (modify-frame-parameters (selected-frame) |
0ca90494 | 651 | (list (cons 'vertical-scroll-bars (> arg 0))))) |
7eadab74 | 652 | |
8290babd | 653 | (defun toggle-horizontal-scroll-bar (arg) |
0ca90494 JB |
654 | "Toggle whether or not the selected frame has horizontal scroll bars. |
655 | With arg, turn horizontal scroll bars on if and only if arg is positive. | |
656 | Horizontal scroll bars aren't implemented yet." | |
7eadab74 | 657 | (interactive "P") |
8290babd | 658 | (error "Horizontal scroll bars aren't implemented yet")) |
64c669bc | 659 | |
64c669bc | 660 | \f |
dc6d9681 | 661 | ;;;; Aliases for backward compatibility with Emacs 18. |
31e1d920 ER |
662 | (defalias 'screen-height 'frame-height) |
663 | (defalias 'screen-width 'frame-width) | |
9e2b097b JB |
664 | |
665 | (defun set-screen-width (cols &optional pretend) | |
666 | "Obsolete function to change the size of the screen to COLS columns.\n\ | |
667 | Optional second arg non-nil means that redisplay should use COLS columns\n\ | |
668 | but that the idea of the actual width of the frame should not be changed.\n\ | |
669 | This function is provided only for compatibility with Emacs 18; new code\n\ | |
fe668515 | 670 | should use `set-frame-width instead'." |
9e2b097b JB |
671 | (set-frame-width (selected-frame) cols pretend)) |
672 | ||
673 | (defun set-screen-height (lines &optional pretend) | |
674 | "Obsolete function to change the height of the screen to LINES lines.\n\ | |
675 | Optional second arg non-nil means that redisplay should use LINES lines\n\ | |
676 | but that the idea of the actual height of the screen should not be changed.\n\ | |
677 | This function is provided only for compatibility with Emacs 18; new code\n\ | |
fe668515 | 678 | should use `set-frame-width' instead." |
9e2b097b JB |
679 | (set-frame-height (selected-frame) lines pretend)) |
680 | ||
681 | (make-obsolete 'screen-height 'frame-height) | |
682 | (make-obsolete 'screen-width 'frame-width) | |
683 | (make-obsolete 'set-screen-width 'set-frame-width) | |
684 | (make-obsolete 'set-screen-height 'set-frame-height) | |
dc6d9681 JB |
685 | |
686 | \f | |
64c669bc | 687 | ;;;; Key bindings |
daa37602 | 688 | (defvar ctl-x-5-map (make-sparse-keymap) |
dc6d9681 | 689 | "Keymap for frame commands.") |
31e1d920 | 690 | (defalias 'ctl-x-5-prefix ctl-x-5-map) |
daa37602 | 691 | (define-key ctl-x-map "5" 'ctl-x-5-prefix) |
64c669bc | 692 | |
6eb018ba | 693 | (define-key ctl-x-5-map "2" 'make-frame) |
dc6d9681 | 694 | (define-key ctl-x-5-map "0" 'delete-frame) |
ceab6935 | 695 | (define-key ctl-x-5-map "o" 'other-frame) |
49116ac0 | 696 | |
dc6d9681 | 697 | (provide 'frame) |
c88ab9ce | 698 | |
dc6d9681 | 699 | ;;; frame.el ends here |