*** empty log message ***
[bpt/emacs.git] / lisp / frame.el
CommitLineData
c88ab9ce
ER
1;;; screen.el --- multi-screen management independent of window systems.
2
49116ac0 3;;;; Copyright (C) 1990, 1992 Free Software Foundation, Inc.
64c669bc
JB
4
5;;; This file is part of GNU Emacs.
6;;;
7;;; GNU Emacs is free software; you can redistribute it and/or modify
8;;; it under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 1, or (at your option)
10;;; any later version.
11;;;
12;;; GNU Emacs is distributed in the hope that it will be useful,
13;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Emacs; see the file COPYING. If not, write to
19;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
64c669bc
JB
21(defvar screen-creation-function nil
22 "Window-system dependent function to call to create a new screen.
23The window system startup file should set this to its screen creation
24function, which should take an alist of parameters as its argument.")
25
26;;; The default value for this must ask for a minibuffer. There must
27;;; always exist a screen with a minibuffer, and after we delete the
28;;; terminal screen, this will be the only screen.
29(defvar initial-screen-alist '((minibuffer . nil))
30 "Alist of values used when creating the initial emacs text screen.
31These may be set in your init file, like this:
32 (setq initial-screen-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
33These supercede the values given in screen-default-alist.")
34
35(defvar minibuffer-screen-alist nil
36 "Alist of values to apply to a minibuffer screen.
37These may be set in your init file, like this:
38 (setq minibuffer-screen-alist
39 '((top . 1) (left . 1) (width . 80) (height . 1)))
40These supercede the values given in default-screen-alist.")
41
42(defvar pop-up-screen-alist nil
43 "Alist of values used when creating pop-up screens.
44Pop-up screens are used for completions, help, and the like.
45This variable can be set in your init file, like this:
46 (setq pop-up-screen-alist '((width . 80) (height . 20)))
47These supercede the values given in default-screen-alist.")
48
49(setq pop-up-screen-function
50 (function (lambda ()
51 (new-screen pop-up-screen-alist))))
52
53\f
54;;;; Arrangement of screens at startup
55
56;;; 1) Load the window system startup file from the lisp library and read the
57;;; high-priority arguments (-q and the like). The window system startup
58;;; file should create any screens specified in the window system defaults.
59;;;
60;;; 2) If no screens have been opened, we open an initial text screen.
61;;;
62;;; 3) Once the init file is done, we apply any newly set parameters
63;;; in initial-screen-alist to the screen.
64
e3bd99f5 65(add-hook 'before-init-hook 'screen-initialize)
64c669bc
JB
66(add-hook 'window-setup-hook 'screen-notice-user-settings)
67
68;;; If we create the initial screen, this is it.
69(defvar screen-initial-screen nil)
70
71;;; startup.el calls this function before loading the user's init
72;;; file - if there is no screen with a minibuffer open now, create
73;;; one to display messages while loading the init file.
74(defun screen-initialize ()
75
76 ;; Are we actually running under a window system at all?
77 (if (and window-system (not noninteractive))
78 (let ((screens (screen-list)))
79
80 ;; Look for a screen that has a minibuffer.
81 (while (and screens
82 (or (eq (car screens) terminal-screen)
83 (not (cdr (assq 'minibuffer
84 (screen-parameters
85 (car screens)))))))
86 (setq screens (cdr screens)))
87
88 ;; If there was none, then we need to create the opening screen.
89 (or screens
df11cb7f 90 (setq default-minibuffer-screen
64c669bc
JB
91 (setq screen-initial-screen
92 (new-screen initial-screen-alist))))
93
94 ;; At this point, we know that we have a screen open, so we
95 ;; can delete the terminal screen.
96 (delete-screen terminal-screen)
97 (setq terminal-screen nil))
98
99 ;; No, we're not running a window system. Arrange to cause errors.
100 (setq screen-creation-function
9198945a
MB
101 (function
102 (lambda (parameters)
103 (error
104 "Can't create multiple screens without a window system."))))))
64c669bc
JB
105
106;;; startup.el calls this function after loading the user's init file.
107;;; If we created a minibuffer before knowing if we had permission, we
108;;; need to see if it should go away or change. Create a text screen
109;;; here.
110(defun screen-notice-user-settings ()
111 (if screen-initial-screen
112 (progn
113
114 ;; If the user wants a minibuffer-only screen, we'll have to
115 ;; make a new one; you can't remove or add a root window to/from
116 ;; an existing screen.
117 (if (eq (cdr (or (assq 'minibuffer initial-screen-alist)
118 '(minibuffer . t)))
119 'only)
120 (progn
df11cb7f
JB
121 (setq default-minibuffer-screen
122 (new-screen
123 (append initial-screen-alist
124 (screen-parameters screen-initial-screen))))
64c669bc
JB
125 (delete-screen screen-initial-screen))
126 (modify-screen-parameters screen-initial-screen
127 initial-screen-alist))))
128
129 ;; Make sure the initial screen can be GC'd if it is ever deleted.
130 (makunbound 'screen-initial-screen))
131
132\f
133;;;; Creation of additional screens
134
135;;; Return some screen other than the current screen,
136;;; creating one if neccessary. Note that the minibuffer screen, if
137;;; separate, is not considered (see next-screen).
138(defun get-screen ()
139 (let ((s (if (equal (next-screen (selected-screen)) (selected-screen))
140 (new-screen)
141 (next-screen (selected-screen)))))
142 s))
143
144(defun next-multiscreen-window ()
145 "Select the next window, regardless of which screen it is on."
146 (interactive)
147 (select-window (next-window (selected-window)
148 (> (minibuffer-depth) 0)
149 t)))
150
151(defun previous-multiscreen-window ()
152 "Select the previous window, regardless of which screen it is on."
153 (interactive)
154 (select-window (previous-window (selected-window)
155 (> (minibuffer-depth) 0)
156 t)))
157
158(defun new-screen (&optional parameters)
bc93c097
JB
159 "Create a new screen, displaying the current buffer.
160
43a2e52c
JB
161Optional argument PARAMETERS is an alist of parameters for the new
162screen. Specifically, PARAMETERS is a list of pairs, each having one
163of the following forms:
164
165(name . STRING) - The screen should be named STRING.
166
167(height . NUMBER) - The screen should be NUMBER text lines high. If
168 this parameter is present, the width parameter must also be
169 given.
170
171(width . NUMBER) - The screen should be NUMBER characters in width.
172 If this parameter is present, the height parameter must also
173 be given.
174
175(minibuffer . t) - the screen should have a minibuffer
176(minibuffer . none) - the screen should have no minibuffer
177(minibuffer . only) - the screen should contain only a minibuffer
178(minibuffer . WINDOW) - the screen should use WINDOW as its minibuffer window.
179
180(NAME . VALUE), specifying the parameter and the value it should have.
181NAME should be one of the following symbols:
182 name VALUE
183
184The documentation for the function x-create-screen describes
185additional screen parameters that Emacs will recognize when running
186under the X Window System."
64c669bc
JB
187 (interactive)
188 (funcall screen-creation-function parameters))
189
190\f
191;;;; Iconification
192
193;;; A possible enhancement for the below: if you iconify a surrogate
194;;; minibuffer screen, iconify all of its minibuffer's users too;
195;;; de-iconify them as a group. This will need to wait until screens
196;;; have mapping and unmapping hooks.
197
198(defun iconify ()
199 "Iconify or deiconify the selected screen."
200 (interactive)
201 (let ((screen (selected-screen)))
202 (if (eq (screen-visible-p screen) t)
203 (iconify-screen screen)
204 (deiconify-screen screen))))
205
206\f
207;;;; Convenience functions for dynamically changing screen parameters
208
209(defun set-screen-height (h)
210 (interactive "NHeight: ")
211 (let* ((screen (selected-screen))
212 (width (cdr (assoc 'width (screen-parameters (selected-screen))))))
213 (set-screen-size (selected-screen) width h)))
214
215(defun set-screen-width (w)
216 (interactive "NWidth: ")
217 (let* ((screen (selected-screen))
218 (height (cdr (assoc 'height (screen-parameters (selected-screen))))))
219 (set-screen-size (selected-screen) w height)))
220
221(defun set-default-font (font-name)
222 (interactive "sFont name: ")
223 (modify-screen-parameters (selected-screen)
224 (list (cons 'font font-name))))
225
226(defun set-screen-background (color-name)
227 (interactive "sColor: ")
228 (modify-screen-parameters (selected-screen)
229 (list (cons 'background-color color-name))))
230
231(defun set-screen-foreground (color-name)
232 (interactive "sColor: ")
233 (modify-screen-parameters (selected-screen)
234 (list (cons 'foreground-color color-name))))
235
236(defun set-cursor-color (color-name)
237 (interactive "sColor: ")
238 (modify-screen-parameters (selected-screen)
239 (list (cons 'cursor-color color-name))))
240
241(defun set-pointer-color (color-name)
242 (interactive "sColor: ")
243 (modify-screen-parameters (selected-screen)
244 (list (cons 'mouse-color color-name))))
245
246(defun set-auto-raise (toggle)
247 (interactive "xt or nil? ")
248 (modify-screen-parameters (selected-screen)
249 (list (cons 'auto-raise toggle))))
250
251(defun set-auto-lower (toggle)
252 (interactive "xt or nil? ")
253 (modify-screen-parameters (selected-screen)
254 (list (cons 'auto-lower toggle))))
255
256(defun set-vertical-bar (toggle)
257 (interactive "xt or nil? ")
258 (modify-screen-parameters (selected-screen)
259 (list (cons 'vertical-scroll-bar toggle))))
260
261(defun set-horizontal-bar (toggle)
262 (interactive "xt or nil? ")
263 (modify-screen-parameters (selected-screen)
264 (list (cons 'horizontal-scroll-bar toggle))))
265\f
266;;;; Key bindings
daa37602
JB
267(defvar ctl-x-5-map (make-sparse-keymap)
268 "Keymap for screen commands.")
269(fset 'ctl-x-5-prefix ctl-x-5-map)
270(define-key ctl-x-map "5" 'ctl-x-5-prefix)
64c669bc 271
87ef29fd
JB
272(define-key ctl-x-5-map "2" 'new-screen)
273(define-key ctl-x-5-map "0" 'delete-screen)
49116ac0
JB
274
275(provide 'screen)
c88ab9ce
ER
276
277;;; screen.el ends here