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