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