entered into RCS
[bpt/emacs.git] / lisp / frame.el
CommitLineData
dc6d9681 1;;; frame.el --- multi-frame management independent of window systems.
c88ab9ce 2
3a801d0c
ER
3;;;; Copyright (C) 1990, 1992 Free Software Foundation, Inc.
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
31;;; The default value for this must ask for a minibuffer. There must
dc6d9681
JB
32;;; always exist a frame with a minibuffer, and after we delete the
33;;; terminal frame, this will be the only frame.
34(defvar initial-frame-alist '((minibuffer . nil))
35 "Alist of values used when creating the initial emacs text frame.
64c669bc 36These may be set in your init file, like this:
dc6d9681
JB
37 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
38These supercede the values given in frame-default-alist.")
64c669bc 39
dc6d9681
JB
40(defvar minibuffer-frame-alist nil
41 "Alist of values to apply to a minibuffer frame.
64c669bc 42These may be set in your init file, like this:
dc6d9681 43 (setq minibuffer-frame-alist
64c669bc 44 '((top . 1) (left . 1) (width . 80) (height . 1)))
dc6d9681 45These supercede the values given in default-frame-alist.")
64c669bc 46
dc6d9681
JB
47(defvar pop-up-frame-alist nil
48 "Alist of values used when creating pop-up frames.
49Pop-up frames are used for completions, help, and the like.
64c669bc 50This variable can be set in your init file, like this:
dc6d9681
JB
51 (setq pop-up-frame-alist '((width . 80) (height . 20)))
52These supercede the values given in default-frame-alist.")
64c669bc 53
dc6d9681 54(setq pop-up-frame-function
64c669bc 55 (function (lambda ()
dc6d9681 56 (new-frame pop-up-frame-alist))))
64c669bc
JB
57
58\f
dc6d9681 59;;;; Arrangement of frames at startup
64c669bc
JB
60
61;;; 1) Load the window system startup file from the lisp library and read the
62;;; high-priority arguments (-q and the like). The window system startup
dc6d9681 63;;; file should create any frames specified in the window system defaults.
64c669bc 64;;;
dc6d9681 65;;; 2) If no frames have been opened, we open an initial text frame.
64c669bc
JB
66;;;
67;;; 3) Once the init file is done, we apply any newly set parameters
dc6d9681 68;;; in initial-frame-alist to the frame.
64c669bc 69
dc6d9681
JB
70(add-hook 'before-init-hook 'frame-initialize)
71(add-hook 'window-setup-hook 'frame-notice-user-settings)
64c669bc 72
dc6d9681
JB
73;;; If we create the initial frame, this is it.
74(defvar frame-initial-frame nil)
64c669bc
JB
75
76;;; startup.el calls this function before loading the user's init
dc6d9681 77;;; file - if there is no frame with a minibuffer open now, create
64c669bc 78;;; one to display messages while loading the init file.
dc6d9681 79(defun frame-initialize ()
64c669bc
JB
80
81 ;; Are we actually running under a window system at all?
82 (if (and window-system (not noninteractive))
dc6d9681 83 (let ((frames (frame-list)))
64c669bc 84
dc6d9681
JB
85 ;; Look for a frame that has a minibuffer.
86 (while (and frames
87 (or (eq (car frames) terminal-frame)
64c669bc 88 (not (cdr (assq 'minibuffer
dc6d9681
JB
89 (frame-parameters
90 (car frames)))))))
91 (setq frames (cdr frames)))
92
93 ;; If there was none, then we need to create the opening frame.
94 (or frames
95 (setq default-minibuffer-frame
96 (setq frame-initial-frame
97 (new-frame initial-frame-alist))))
64c669bc 98
dc6d9681
JB
99 ;; At this point, we know that we have a frame open, so we
100 ;; can delete the terminal frame.
101 (delete-frame terminal-frame)
102 (setq terminal-frame nil))
64c669bc
JB
103
104 ;; No, we're not running a window system. Arrange to cause errors.
dc6d9681 105 (setq frame-creation-function
9198945a
MB
106 (function
107 (lambda (parameters)
108 (error
dc6d9681 109 "Can't create multiple frames without a window system."))))))
64c669bc
JB
110
111;;; startup.el calls this function after loading the user's init file.
112;;; If we created a minibuffer before knowing if we had permission, we
dc6d9681 113;;; need to see if it should go away or change. Create a text frame
64c669bc 114;;; here.
dc6d9681
JB
115(defun frame-notice-user-settings ()
116 (if frame-initial-frame
64c669bc
JB
117 (progn
118
dc6d9681 119 ;; If the user wants a minibuffer-only frame, we'll have to
64c669bc 120 ;; make a new one; you can't remove or add a root window to/from
dc6d9681
JB
121 ;; an existing frame.
122 (if (eq (cdr (or (assq 'minibuffer initial-frame-alist)
64c669bc
JB
123 '(minibuffer . t)))
124 'only)
125 (progn
dc6d9681
JB
126 (setq default-minibuffer-frame
127 (new-frame
128 (append initial-frame-alist
129 (frame-parameters frame-initial-frame))))
130 (delete-frame frame-initial-frame))
131 (modify-frame-parameters frame-initial-frame
132 initial-frame-alist))))
64c669bc 133
dc6d9681
JB
134 ;; Make sure the initial frame can be GC'd if it is ever deleted.
135 (makunbound 'frame-initial-frame))
64c669bc
JB
136
137\f
dc6d9681
JB
138;;;; Creation of additional frames
139
140;;; Return some frame other than the current frame,
141;;; creating one if neccessary. Note that the minibuffer frame, if
142;;; separate, is not considered (see next-frame).
7253d8e0 143(defun get-other-frame ()
dc6d9681
JB
144 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
145 (new-frame)
146 (next-frame (selected-frame)))))
64c669bc
JB
147 s))
148
dc6d9681
JB
149(defun next-multiframe-window ()
150 "Select the next window, regardless of which frame it is on."
64c669bc
JB
151 (interactive)
152 (select-window (next-window (selected-window)
153 (> (minibuffer-depth) 0)
154 t)))
155
dc6d9681
JB
156(defun previous-multiframe-window ()
157 "Select the previous window, regardless of which frame it is on."
64c669bc
JB
158 (interactive)
159 (select-window (previous-window (selected-window)
160 (> (minibuffer-depth) 0)
161 t)))
162
dc6d9681
JB
163(defun new-frame (&optional parameters)
164 "Create a new frame, displaying the current buffer.
bc93c097 165
43a2e52c 166Optional argument PARAMETERS is an alist of parameters for the new
dc6d9681 167frame. Specifically, PARAMETERS is a list of pairs, each having one
43a2e52c
JB
168of the following forms:
169
dc6d9681 170(name . STRING) - The frame should be named STRING.
43a2e52c 171
dc6d9681 172(height . NUMBER) - The frame should be NUMBER text lines high. If
43a2e52c
JB
173 this parameter is present, the width parameter must also be
174 given.
175
dc6d9681 176(width . NUMBER) - The frame should be NUMBER characters in width.
43a2e52c
JB
177 If this parameter is present, the height parameter must also
178 be given.
179
dc6d9681
JB
180(minibuffer . t) - the frame should have a minibuffer
181(minibuffer . none) - the frame should have no minibuffer
182(minibuffer . only) - the frame should contain only a minibuffer
183(minibuffer . WINDOW) - the frame should use WINDOW as its minibuffer window.
43a2e52c
JB
184
185(NAME . VALUE), specifying the parameter and the value it should have.
186NAME should be one of the following symbols:
187 name VALUE
188
dc6d9681
JB
189The documentation for the function x-create-frame describes
190additional frame parameters that Emacs will recognize when running
43a2e52c 191under the X Window System."
64c669bc 192 (interactive)
dc6d9681 193 (funcall frame-creation-function parameters))
64c669bc
JB
194
195\f
dc6d9681
JB
196;;;; Frame configurations
197
198(defun current-frame-configuration ()
199 "Return a list describing the positions and states of all frames.
200Each element is a list of the form (FRAME ALIST WINDOW-CONFIG), where
201FRAME is a frame object, ALIST is an association list specifying
202some of FRAME's parameters, and WINDOW-CONFIG is a window
203configuration object for FRAME."
06b1a5ef 204 (mapcar (function
dc6d9681
JB
205 (lambda (frame)
206 (list frame
207 (frame-parameters frame)
208 (current-window-configuration frame))))
209 (frame-list)))
210
211(defun set-frame-configuration (configuration)
212 "Restore the frames to the state described by CONFIGURATION.
213Each frame listed in CONFIGURATION has its position, size, window
06b1a5ef 214configuration, and other parameters set as specified in CONFIGURATION."
dc6d9681 215 (let (frames-to-delete)
06b1a5ef 216 (mapcar (function
dc6d9681
JB
217 (lambda (frame)
218 (let ((parameters (assq frame configuration)))
06b1a5ef
JB
219 (if parameters
220 (progn
dc6d9681 221 (modify-frame-parameters frame (nth 1 parameters))
06b1a5ef 222 (set-window-configuration (nth 2 parameters)))
dc6d9681
JB
223 (setq frames-to-delete (cons frame frames-to-delete))))))
224 (frame-list))
225 (mapcar 'delete-frame frames-to-delete)))
64c669bc
JB
226
227\f
dc6d9681
JB
228;;;; Convenience functions for accessing and interactively changing
229;;;; frame parameters.
64c669bc 230
151bdc83 231(defun frame-height (&optional frame)
dc6d9681
JB
232 "Return number of lines available for display on FRAME.
233If FRAME is omitted, describe the currently selected frame."
151bdc83 234 (cdr (assq 'height (frame-parameters frame))))
dc6d9681
JB
235
236(defun frame-width (&optional frame)
237 "Return number of columns available for display on FRAME.
238If FRAME is omitted, describe the currently selected frame."
151bdc83 239 (cdr (assq 'width (frame-parameters frame))))
dc6d9681 240
64c669bc
JB
241(defun set-default-font (font-name)
242 (interactive "sFont name: ")
dc6d9681 243 (modify-frame-parameters (selected-frame)
64c669bc
JB
244 (list (cons 'font font-name))))
245
dc6d9681 246(defun set-frame-background (color-name)
64c669bc 247 (interactive "sColor: ")
dc6d9681 248 (modify-frame-parameters (selected-frame)
64c669bc
JB
249 (list (cons 'background-color color-name))))
250
dc6d9681 251(defun set-frame-foreground (color-name)
64c669bc 252 (interactive "sColor: ")
dc6d9681 253 (modify-frame-parameters (selected-frame)
64c669bc
JB
254 (list (cons 'foreground-color color-name))))
255
256(defun set-cursor-color (color-name)
257 (interactive "sColor: ")
dc6d9681 258 (modify-frame-parameters (selected-frame)
64c669bc
JB
259 (list (cons 'cursor-color color-name))))
260
261(defun set-pointer-color (color-name)
262 (interactive "sColor: ")
dc6d9681 263 (modify-frame-parameters (selected-frame)
64c669bc
JB
264 (list (cons 'mouse-color color-name))))
265
266(defun set-auto-raise (toggle)
267 (interactive "xt or nil? ")
dc6d9681 268 (modify-frame-parameters (selected-frame)
64c669bc
JB
269 (list (cons 'auto-raise toggle))))
270
271(defun set-auto-lower (toggle)
272 (interactive "xt or nil? ")
dc6d9681 273 (modify-frame-parameters (selected-frame)
64c669bc
JB
274 (list (cons 'auto-lower toggle))))
275
276(defun set-vertical-bar (toggle)
277 (interactive "xt or nil? ")
dc6d9681 278 (modify-frame-parameters (selected-frame)
64c669bc
JB
279 (list (cons 'vertical-scroll-bar toggle))))
280
281(defun set-horizontal-bar (toggle)
282 (interactive "xt or nil? ")
dc6d9681 283 (modify-frame-parameters (selected-frame)
64c669bc
JB
284 (list (cons 'horizontal-scroll-bar toggle))))
285\f
dc6d9681
JB
286;;;; Aliases for backward compatibility with Emacs 18.
287(fset 'screen-height 'frame-height)
288(fset 'screen-width 'frame-width)
289(fset 'set-screen-width 'set-frame-width)
290(fset 'set-screen-height 'set-frame-height)
291
292\f
64c669bc 293;;;; Key bindings
daa37602 294(defvar ctl-x-5-map (make-sparse-keymap)
dc6d9681 295 "Keymap for frame commands.")
daa37602
JB
296(fset 'ctl-x-5-prefix ctl-x-5-map)
297(define-key ctl-x-map "5" 'ctl-x-5-prefix)
64c669bc 298
dc6d9681
JB
299(define-key ctl-x-5-map "2" 'new-frame)
300(define-key ctl-x-5-map "0" 'delete-frame)
49116ac0 301
dc6d9681 302(provide 'frame)
c88ab9ce 303
dc6d9681 304;;; frame.el ends here