*** empty log message ***
[emacs.git] / lisp / frame.el
blob9722f32c4357d7d5bfaf365d831d11333de67840
1 ;;; frame.el --- multi-frame management independent of window systems.
3 ;; Maintainer: FSF
4 ;; Last-Modified: 09 Jul 92
6 ;;;; Copyright (C) 1990, 1992 Free Software Foundation, Inc.
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
12 ;;; the Free Software Foundation; either version 1, or (at your option)
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.
24 ;;; Code:
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
29 function, which should take an alist of parameters as its argument.")
31 ;;; The default value for this must ask for a minibuffer. There must
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.
36 These may be set in your init file, like this:
37 (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
38 These supercede the values given in frame-default-alist.")
40 (defvar minibuffer-frame-alist nil
41 "Alist of values to apply to a minibuffer frame.
42 These may be set in your init file, like this:
43 (setq minibuffer-frame-alist
44 '((top . 1) (left . 1) (width . 80) (height . 1)))
45 These supercede the values given in default-frame-alist.")
47 (defvar pop-up-frame-alist nil
48 "Alist of values used when creating pop-up frames.
49 Pop-up frames are used for completions, help, and the like.
50 This variable can be set in your init file, like this:
51 (setq pop-up-frame-alist '((width . 80) (height . 20)))
52 These supercede the values given in default-frame-alist.")
54 (setq pop-up-frame-function
55 (function (lambda ()
56 (new-frame pop-up-frame-alist))))
59 ;;;; Arrangement of frames at startup
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
63 ;;; file should create any frames specified in the window system defaults.
64 ;;;
65 ;;; 2) If no frames have been opened, we open an initial text frame.
66 ;;;
67 ;;; 3) Once the init file is done, we apply any newly set parameters
68 ;;; in initial-frame-alist to the frame.
70 (add-hook 'before-init-hook 'frame-initialize)
71 (add-hook 'window-setup-hook 'frame-notice-user-settings)
73 ;;; If we create the initial frame, this is it.
74 (defvar frame-initial-frame nil)
76 ;;; startup.el calls this function before loading the user's init
77 ;;; file - if there is no frame with a minibuffer open now, create
78 ;;; one to display messages while loading the init file.
79 (defun frame-initialize ()
81 ;; Are we actually running under a window system at all?
82 (if (and window-system (not noninteractive))
83 (let ((frames (frame-list)))
85 ;; Look for a frame that has a minibuffer.
86 (while (and frames
87 (or (eq (car frames) terminal-frame)
88 (not (cdr (assq 'minibuffer
89 (frame-parameters
90 (car frames)))))))
91 (setq frames (cdr frames)))
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))))
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))
104 ;; No, we're not running a window system. Arrange to cause errors.
105 (setq frame-creation-function
106 (function
107 (lambda (parameters)
108 (error
109 "Can't create multiple frames without a window system."))))))
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
113 ;;; need to see if it should go away or change. Create a text frame
114 ;;; here.
115 (defun frame-notice-user-settings ()
116 (if frame-initial-frame
117 (progn
119 ;; If the user wants a minibuffer-only frame, we'll have to
120 ;; make a new one; you can't remove or add a root window to/from
121 ;; an existing frame.
122 (if (eq (cdr (or (assq 'minibuffer initial-frame-alist)
123 '(minibuffer . t)))
124 'only)
125 (progn
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))))
134 ;; Make sure the initial frame can be GC'd if it is ever deleted.
135 (makunbound 'frame-initial-frame))
138 ;;;; Creation of additional frames
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).
143 (defun get-frame ()
144 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
145 (new-frame)
146 (next-frame (selected-frame)))))
149 (defun next-multiframe-window ()
150 "Select the next window, regardless of which frame it is on."
151 (interactive)
152 (select-window (next-window (selected-window)
153 (> (minibuffer-depth) 0)
154 t)))
156 (defun previous-multiframe-window ()
157 "Select the previous window, regardless of which frame it is on."
158 (interactive)
159 (select-window (previous-window (selected-window)
160 (> (minibuffer-depth) 0)
161 t)))
163 (defun new-frame (&optional parameters)
164 "Create a new frame, displaying the current buffer.
166 Optional argument PARAMETERS is an alist of parameters for the new
167 frame. Specifically, PARAMETERS is a list of pairs, each having one
168 of the following forms:
170 (name . STRING) - The frame should be named STRING.
172 (height . NUMBER) - The frame should be NUMBER text lines high. If
173 this parameter is present, the width parameter must also be
174 given.
176 (width . NUMBER) - The frame should be NUMBER characters in width.
177 If this parameter is present, the height parameter must also
178 be given.
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.
185 (NAME . VALUE), specifying the parameter and the value it should have.
186 NAME should be one of the following symbols:
187 name VALUE
189 The documentation for the function x-create-frame describes
190 additional frame parameters that Emacs will recognize when running
191 under the X Window System."
192 (interactive)
193 (funcall frame-creation-function parameters))
196 ;;;; Iconification
198 ;;; A possible enhancement for the below: if you iconify a surrogate
199 ;;; minibuffer frame, iconify all of its minibuffer's users too;
200 ;;; de-iconify them as a group. This will need to wait until frames
201 ;;; have mapping and unmapping hooks.
203 (defun iconify ()
204 "Iconify or deiconify the selected frame."
205 (interactive)
206 (let ((frame (selected-frame)))
207 (if (eq (frame-visible-p frame) t)
208 (iconify-frame frame)
209 (make-frame-visible frame))))
212 ;;;; Frame configurations
214 (defun current-frame-configuration ()
215 "Return a list describing the positions and states of all frames.
216 Each element is a list of the form (FRAME ALIST WINDOW-CONFIG), where
217 FRAME is a frame object, ALIST is an association list specifying
218 some of FRAME's parameters, and WINDOW-CONFIG is a window
219 configuration object for FRAME."
220 (mapcar (function
221 (lambda (frame)
222 (list frame
223 (frame-parameters frame)
224 (current-window-configuration frame))))
225 (frame-list)))
227 (defun set-frame-configuration (configuration)
228 "Restore the frames to the state described by CONFIGURATION.
229 Each frame listed in CONFIGURATION has its position, size, window
230 configuration, and other parameters set as specified in CONFIGURATION."
231 (let (frames-to-delete)
232 (mapcar (function
233 (lambda (frame)
234 (let ((parameters (assq frame configuration)))
235 (if parameters
236 (progn
237 (modify-frame-parameters frame (nth 1 parameters))
238 (set-window-configuration (nth 2 parameters)))
239 (setq frames-to-delete (cons frame frames-to-delete))))))
240 (frame-list))
241 (mapcar 'delete-frame frames-to-delete)))
244 ;;;; Convenience functions for accessing and interactively changing
245 ;;;; frame parameters.
247 (defun frame-width (&optional frame)
248 "Return number of lines available for display on FRAME.
249 If FRAME is omitted, describe the currently selected frame."
250 (cdr (assq 'width (frame-parameters frame))))
252 (defun frame-width (&optional frame)
253 "Return number of columns available for display on FRAME.
254 If FRAME is omitted, describe the currently selected frame."
255 (cdr (assq 'height (frame-parameters frame))))
257 (defun set-frame-height (h)
258 (interactive "NHeight: ")
259 (let* ((frame (selected-frame))
260 (width (cdr (assoc 'width (frame-parameters (selected-frame))))))
261 (set-frame-size (selected-frame) width h)))
263 (defun set-frame-width (w)
264 (interactive "NWidth: ")
265 (let* ((frame (selected-frame))
266 (height (cdr (assoc 'height (frame-parameters (selected-frame))))))
267 (set-frame-size (selected-frame) w height)))
269 (defun set-default-font (font-name)
270 (interactive "sFont name: ")
271 (modify-frame-parameters (selected-frame)
272 (list (cons 'font font-name))))
274 (defun set-frame-background (color-name)
275 (interactive "sColor: ")
276 (modify-frame-parameters (selected-frame)
277 (list (cons 'background-color color-name))))
279 (defun set-frame-foreground (color-name)
280 (interactive "sColor: ")
281 (modify-frame-parameters (selected-frame)
282 (list (cons 'foreground-color color-name))))
284 (defun set-cursor-color (color-name)
285 (interactive "sColor: ")
286 (modify-frame-parameters (selected-frame)
287 (list (cons 'cursor-color color-name))))
289 (defun set-pointer-color (color-name)
290 (interactive "sColor: ")
291 (modify-frame-parameters (selected-frame)
292 (list (cons 'mouse-color color-name))))
294 (defun set-auto-raise (toggle)
295 (interactive "xt or nil? ")
296 (modify-frame-parameters (selected-frame)
297 (list (cons 'auto-raise toggle))))
299 (defun set-auto-lower (toggle)
300 (interactive "xt or nil? ")
301 (modify-frame-parameters (selected-frame)
302 (list (cons 'auto-lower toggle))))
304 (defun set-vertical-bar (toggle)
305 (interactive "xt or nil? ")
306 (modify-frame-parameters (selected-frame)
307 (list (cons 'vertical-scroll-bar toggle))))
309 (defun set-horizontal-bar (toggle)
310 (interactive "xt or nil? ")
311 (modify-frame-parameters (selected-frame)
312 (list (cons 'horizontal-scroll-bar toggle))))
314 ;;;; Aliases for backward compatibility with Emacs 18.
315 (fset 'screen-height 'frame-height)
316 (fset 'screen-width 'frame-width)
317 (fset 'set-screen-width 'set-frame-width)
318 (fset 'set-screen-height 'set-frame-height)
321 ;;;; Key bindings
322 (defvar ctl-x-5-map (make-sparse-keymap)
323 "Keymap for frame commands.")
324 (fset 'ctl-x-5-prefix ctl-x-5-map)
325 (define-key ctl-x-map "5" 'ctl-x-5-prefix)
327 (define-key ctl-x-5-map "2" 'new-frame)
328 (define-key ctl-x-5-map "0" 'delete-frame)
330 (provide 'frame)
332 ;;; frame.el ends here