summaryrefslogtreecommitdiff
path: root/lisp/frame.el
blob: 930baab6ce19e20908a8369326f46dcf6bf8dade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
;;;; Multi-screen management that is independent of window systems.
;;;; Copyright (C) 1990, 1992 Free Software Foundation, Inc.

;;; This file is part of GNU Emacs.
;;;
;;; GNU Emacs is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 1, or (at your option)
;;; any later version.
;;;
;;; GNU Emacs is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Emacs; see the file COPYING.  If not, write to
;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

(defvar screen-creation-function nil
  "Window-system dependent function to call to create a new screen.
The window system startup file should set this to its screen creation
function, which should take an alist of parameters as its argument.")

;;; The default value for this must ask for a minibuffer.  There must
;;; always exist a screen with a minibuffer, and after we delete the
;;; terminal screen, this will be the only screen.
(defvar initial-screen-alist '((minibuffer . nil))
  "Alist of values used when creating the initial emacs text screen.
These may be set in your init file, like this:
 (setq initial-screen-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
These supercede the values given in screen-default-alist.")

(defvar minibuffer-screen-alist nil
  "Alist of values to apply to a minibuffer screen.
These may be set in your init file, like this:
 (setq minibuffer-screen-alist
   '((top . 1) (left . 1) (width . 80) (height . 1)))
These supercede the values given in default-screen-alist.")

(defvar pop-up-screen-alist nil
  "Alist of values used when creating pop-up screens.
Pop-up screens are used for completions, help, and the like.
This variable can be set in your init file, like this:
  (setq pop-up-screen-alist '((width . 80) (height . 20)))
These supercede the values given in default-screen-alist.")

(setq pop-up-screen-function
      (function (lambda ()
		  (new-screen pop-up-screen-alist))))


;;;; Arrangement of screens at startup

;;; 1) Load the window system startup file from the lisp library and read the
;;; high-priority arguments (-q and the like).  The window system startup
;;; file should create any screens specified in the window system defaults.
;;; 
;;; 2) If no screens have been opened, we open an initial text screen.
;;;
;;; 3) Once the init file is done, we apply any newly set parameters
;;; in initial-screen-alist to the screen.

(add-hook 'pre-init-hook 'screen-initialize)
(add-hook 'window-setup-hook 'screen-notice-user-settings)

;;; If we create the initial screen, this is it.
(defvar screen-initial-screen nil)

;;; startup.el calls this function before loading the user's init
;;; file - if there is no screen with a minibuffer open now, create
;;; one to display messages while loading the init file.
(defun screen-initialize ()
  
  ;; Are we actually running under a window system at all?
  (if (and window-system (not noninteractive))
      (let ((screens (screen-list)))
    
	;; Look for a screen that has a minibuffer.
	(while (and screens
		    (or (eq (car screens) terminal-screen)
			(not (cdr (assq 'minibuffer
					(screen-parameters
					 (car screens)))))))
	  (setq screens (cdr screens)))

	;; If there was none, then we need to create the opening screen.
	(or screens
	    (setq default-minibuffer-screen
		  (setq screen-initial-screen
			(new-screen initial-screen-alist))))
    
	;; At this point, we know that we have a screen open, so we 
	;; can delete the terminal screen.
	(delete-screen terminal-screen)
	(setq terminal-screen nil))
    
    ;; No, we're not running a window system.  Arrange to cause errors.
    (setq screen-creation-function
	  (function
	   (lambda (parameters)
	     (error
	      "Can't create multiple screens without a window system."))))))
					
;;; startup.el calls this function after loading the user's init file.
;;; If we created a minibuffer before knowing if we had permission, we
;;; need to see if it should go away or change.  Create a text screen
;;; here.
(defun screen-notice-user-settings ()
  (if screen-initial-screen
      (progn
	
	;; If the user wants a minibuffer-only screen, we'll have to
	;; make a new one; you can't remove or add a root window to/from
	;; an existing screen.
	(if (eq (cdr (or (assq 'minibuffer initial-screen-alist)
			 '(minibuffer . t)))
		     'only)
	    (progn
	      (setq default-minibuffer-screen
		    (new-screen
		     (append initial-screen-alist
			     (screen-parameters screen-initial-screen))))
	      (delete-screen screen-initial-screen))
	  (modify-screen-parameters screen-initial-screen
				    initial-screen-alist))))

  ;; Make sure the initial screen can be GC'd if it is ever deleted.
  (makunbound 'screen-initial-screen))


;;;; Creation of additional screens

;;; Return some screen other than the current screen,
;;; creating one if neccessary.  Note that the minibuffer screen, if
;;; separate, is not considered (see next-screen).
(defun get-screen ()
  (let ((s (if (equal (next-screen (selected-screen)) (selected-screen))
	       (new-screen)
	     (next-screen (selected-screen)))))
    s))

(defun next-multiscreen-window ()
  "Select the next window, regardless of which screen it is on."
  (interactive)
  (select-window (next-window (selected-window)
			      (> (minibuffer-depth) 0)
			      t)))

(defun previous-multiscreen-window ()
  "Select the previous window, regardless of which screen it is on."
  (interactive)
  (select-window (previous-window (selected-window)
				  (> (minibuffer-depth) 0)
				  t)))

(defun new-screen (&optional parameters)
  "Create a new screen, displaying the current buffer.

Optional argument PARAMETERS is an alist of parameters for the new
screen.  Specifically, PARAMETERS is a list of pairs, each having one
of the following forms:

(name . STRING)	- The screen should be named STRING.

(height . NUMBER) - The screen should be NUMBER text lines high.  If
	this parameter is present, the width parameter must also be
	given.

(width . NUMBER) - The screen should be NUMBER characters in width.
	If this parameter is present, the height parameter must also
	be given.

(minibuffer . t) - the screen should have a minibuffer
(minibuffer . none) - the screen should have no minibuffer
(minibuffer . only) - the screen should contain only a minibuffer
(minibuffer . WINDOW) - the screen should use WINDOW as its minibuffer window.

(NAME . VALUE), specifying the parameter and the value it should have.
NAME should be one of the following symbols:
  name		VALUE 

The documentation for the function x-create-screen describes
additional screen parameters that Emacs will recognize when running
under the X Window System."
  (interactive)
  (funcall screen-creation-function parameters))


;;;; Iconification

;;; A possible enhancement for the below: if you iconify a surrogate
;;; minibuffer screen, iconify all of its minibuffer's users too; 
;;; de-iconify them as a group.  This will need to wait until screens
;;; have mapping and unmapping hooks.

(defun iconify ()
  "Iconify or deiconify the selected screen."
  (interactive)
  (let ((screen (selected-screen)))
    (if (eq (screen-visible-p screen) t)
	(iconify-screen screen)
      (deiconify-screen screen))))


;;;; Convenience functions for dynamically changing screen parameters

(defun set-screen-height (h)
  (interactive "NHeight: ")
  (let* ((screen (selected-screen))
	 (width (cdr (assoc 'width (screen-parameters (selected-screen))))))
    (set-screen-size (selected-screen) width h)))

(defun set-screen-width (w)
  (interactive "NWidth: ")
  (let* ((screen (selected-screen))
	 (height (cdr (assoc 'height (screen-parameters (selected-screen))))))
    (set-screen-size (selected-screen) w height)))

(defun set-default-font (font-name)
  (interactive "sFont name: ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'font font-name))))

(defun set-screen-background (color-name)
  (interactive "sColor: ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'background-color color-name))))

(defun set-screen-foreground (color-name)
  (interactive "sColor: ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'foreground-color color-name))))

(defun set-cursor-color (color-name)
  (interactive "sColor: ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'cursor-color color-name))))

(defun set-pointer-color (color-name)
  (interactive "sColor: ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'mouse-color color-name))))

(defun set-auto-raise (toggle)
  (interactive "xt or nil? ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'auto-raise toggle))))

(defun set-auto-lower (toggle)
  (interactive "xt or nil? ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'auto-lower toggle))))

(defun set-vertical-bar (toggle)
  (interactive "xt or nil? ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'vertical-scroll-bar toggle))))

(defun set-horizontal-bar (toggle)
  (interactive "xt or nil? ")
  (modify-screen-parameters (selected-screen)
			    (list (cons 'horizontal-scroll-bar toggle))))

;;;; Key bindings
(define-prefix-command 'ctl-x-3-map)
(define-key ctl-x-map "3" 'ctl-x-3-map)

(define-key ctl-x-3-map "2" 'new-screen)
(define-key ctl-x-3-map "0" 'delete-screen)

(provide 'screen)