Commit | Line | Data |
---|---|---|
dc6d9681 | 1 | ;;; frame.el --- multi-frame management independent of window systems. |
c88ab9ce | 2 | |
a6c411ff GM |
3 | ;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001 |
4 | ;; Free Software Foundation, Inc. | |
3a801d0c | 5 | |
fc68affa | 6 | ;; Maintainer: FSF |
fd7fa35a | 7 | ;; Keywords: internal |
fc68affa | 8 | |
b578f267 EN |
9 | ;; This file is part of GNU Emacs. |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
14 | ;; any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
64c669bc | 25 | |
fc68affa ER |
26 | ;;; Code: |
27 | ||
dc6d9681 JB |
28 | (defvar frame-creation-function nil |
29 | "Window-system dependent function to call to create a new frame. | |
30 | The window system startup file should set this to its frame creation | |
64c669bc JB |
31 | function, which should take an alist of parameters as its argument.") |
32 | ||
216f1169 RS |
33 | ;;; The initial value given here for used to ask for a minibuffer. |
34 | ;;; But that's not necessary, because the default is to have one. | |
35 | ;;; By not specifying it here, we let an X resource specify it. | |
0c966f88 | 36 | (defcustom initial-frame-alist nil |
0b9d32af | 37 | "*Alist of frame parameters for creating the initial X window frame. |
eaa974e1 | 38 | You can set this in your `.emacs' file; for example, |
dc6d9681 | 39 | (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55))) |
de17da15 RS |
40 | Parameters specified here supersede the values given in `default-frame-alist'. |
41 | ||
42 | If the value calls for a frame without a minibuffer, and you have not created | |
43 | a minibuffer frame on your own, one is created according to | |
7eadab74 | 44 | `minibuffer-frame-alist'. |
de17da15 RS |
45 | |
46 | You can specify geometry-related options for just the initial frame | |
47 | by setting this variable in your `.emacs' file; however, they won't | |
85557d7e | 48 | take effect until Emacs reads `.emacs', which happens after first creating |
de17da15 RS |
49 | the frame. If you want the frame to have the proper geometry as soon |
50 | as it appears, you need to use this three-step process: | |
51 | * Specify X resources to give the geometry you want. | |
52 | * Set `default-frame-alist' to override these options so that they | |
53 | don't affect subsequent frames. | |
54 | * Set `initial-frame-alist' in a way that matches the X resources, | |
0c966f88 RS |
55 | to override what you put in `default-frame-alist'." |
56 | :type '(repeat (cons :format "%v" | |
57 | (symbol :tag "Parameter") | |
58 | (sexp :tag "Value"))) | |
59 | :group 'frames) | |
64c669bc | 60 | |
0b9d32af RS |
61 | (defcustom minibuffer-frame-alist '((width . 80) (height . 2)) |
62 | "*Alist of frame parameters for initially creating a minibuffer frame. | |
eaa974e1 | 63 | You can set this in your `.emacs' file; for example, |
dc6d9681 | 64 | (setq minibuffer-frame-alist |
7eadab74 | 65 | '((top . 1) (left . 1) (width . 80) (height . 2))) |
eaa974e1 | 66 | Parameters specified here supersede the values given in |
0b9d32af RS |
67 | `default-frame-alist', for a minibuffer frame." |
68 | :type '(repeat (cons :format "%v" | |
69 | (symbol :tag "Parameter") | |
70 | (sexp :tag "Value"))) | |
71 | :group 'frames) | |
64c669bc | 72 | |
0b9d32af RS |
73 | (defcustom pop-up-frame-alist nil |
74 | "*Alist of frame parameters used when creating pop-up frames. | |
dc6d9681 | 75 | Pop-up frames are used for completions, help, and the like. |
64c669bc | 76 | This variable can be set in your init file, like this: |
dc6d9681 | 77 | (setq pop-up-frame-alist '((width . 80) (height . 20))) |
0b9d32af RS |
78 | These supersede the values given in `default-frame-alist', |
79 | for pop-up frames." | |
80 | :type '(repeat (cons :format "%v" | |
81 | (symbol :tag "Parameter") | |
82 | (sexp :tag "Value"))) | |
83 | :group 'frames) | |
64c669bc | 84 | |
dc6d9681 | 85 | (setq pop-up-frame-function |
64c669bc | 86 | (function (lambda () |
6eb018ba | 87 | (make-frame pop-up-frame-alist)))) |
64c669bc | 88 | |
30e19aee | 89 | (defcustom special-display-frame-alist |
8a9e86e6 RS |
90 | '((height . 14) (width . 80) (unsplittable . t)) |
91 | "*Alist of frame parameters used when creating special frames. | |
92 | Special frames are used for buffers whose names are in | |
93 | `special-display-buffer-names' and for buffers whose names match | |
94 | one of the regular expressions in `special-display-regexps'. | |
95 | This variable can be set in your init file, like this: | |
96 | (setq special-display-frame-alist '((width . 80) (height . 20))) | |
30e19aee RS |
97 | These supersede the values given in `default-frame-alist'." |
98 | :type '(repeat (cons :format "%v" | |
99 | (symbol :tag "Parameter") | |
100 | (sexp :tag "Value"))) | |
101 | :group 'frames) | |
8a9e86e6 | 102 | |
95e6cf39 | 103 | (defun special-display-popup-frame (buffer &optional args) |
40d34803 DL |
104 | "Display BUFFER in its own frame, reusing an existing window if any. |
105 | Return the window chosen. | |
106 | Currently we do not insist on selecting the window within its frame. | |
107 | If ARGS is an alist, use it as a list of frame parameter specs. | |
108 | If ARGS is a list whose car is a symbol, | |
109 | use (car ARGS) as a function to do the work. | |
110 | Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args." | |
95e6cf39 RS |
111 | (if (and args (symbolp (car args))) |
112 | (apply (car args) buffer (cdr args)) | |
113 | (let ((window (get-buffer-window buffer t))) | |
114 | (if window | |
115 | ;; If we have a window already, make it visible. | |
116 | (let ((frame (window-frame window))) | |
117 | (make-frame-visible frame) | |
118 | (raise-frame frame) | |
119 | window) | |
120 | ;; If no window yet, make one in a new frame. | |
121 | (let ((frame (make-frame (append args special-display-frame-alist)))) | |
122 | (set-window-buffer (frame-selected-window frame) buffer) | |
123 | (set-window-dedicated-p (frame-selected-window frame) t) | |
124 | (frame-selected-window frame)))))) | |
8a9e86e6 | 125 | |
924be53a | 126 | (defun handle-delete-frame (event) |
40d34803 | 127 | "Handle delete-frame events from the X server." |
924be53a RS |
128 | (interactive "e") |
129 | (let ((frame (posn-window (event-start event))) | |
130 | (i 0) | |
131 | (tail (frame-list))) | |
132 | (while tail | |
133 | (and (frame-visible-p (car tail)) | |
134 | (not (eq (car tail) frame)) | |
135 | (setq i (1+ i))) | |
136 | (setq tail (cdr tail))) | |
137 | (if (> i 0) | |
138 | (delete-frame frame t) | |
a9562d19 RS |
139 | ;; Gildea@x.org says it is ok to ask questions before terminating. |
140 | (save-buffers-kill-emacs)))) | |
64c669bc | 141 | \f |
dc6d9681 | 142 | ;;;; Arrangement of frames at startup |
64c669bc JB |
143 | |
144 | ;;; 1) Load the window system startup file from the lisp library and read the | |
145 | ;;; high-priority arguments (-q and the like). The window system startup | |
dc6d9681 | 146 | ;;; file should create any frames specified in the window system defaults. |
85557d7e | 147 | ;;; |
dc6d9681 | 148 | ;;; 2) If no frames have been opened, we open an initial text frame. |
64c669bc JB |
149 | ;;; |
150 | ;;; 3) Once the init file is done, we apply any newly set parameters | |
dc6d9681 | 151 | ;;; in initial-frame-alist to the frame. |
64c669bc | 152 | |
85557d7e | 153 | ;; These are now called explicitly at the proper times, |
fc4d4afb RS |
154 | ;; since that is easier to understand. |
155 | ;; Actually using hooks within Emacs is bad for future maintenance. --rms. | |
156 | ;; (add-hook 'before-init-hook 'frame-initialize) | |
157 | ;; (add-hook 'window-setup-hook 'frame-notice-user-settings) | |
64c669bc | 158 | |
dc6d9681 JB |
159 | ;;; If we create the initial frame, this is it. |
160 | (defvar frame-initial-frame nil) | |
64c669bc | 161 | |
3f2f8c83 RS |
162 | ;; Record the parameters used in frame-initialize to make the initial frame. |
163 | (defvar frame-initial-frame-alist) | |
164 | ||
791e09d8 RS |
165 | (defvar frame-initial-geometry-arguments nil) |
166 | ||
64c669bc | 167 | ;;; startup.el calls this function before loading the user's init |
dc6d9681 | 168 | ;;; file - if there is no frame with a minibuffer open now, create |
64c669bc | 169 | ;;; one to display messages while loading the init file. |
dc6d9681 | 170 | (defun frame-initialize () |
ff2a1c79 | 171 | "Create an initial frame if necessary." |
64c669bc | 172 | ;; Are we actually running under a window system at all? |
004f057a | 173 | (if (and window-system (not noninteractive) (not (eq window-system 'pc))) |
7eadab74 | 174 | (progn |
62642af9 RS |
175 | ;; Turn on special-display processing only if there's a window system. |
176 | (setq special-display-function 'special-display-popup-frame) | |
177 | ||
7eadab74 JB |
178 | ;; If there is no frame with a minibuffer besides the terminal |
179 | ;; frame, then we need to create the opening frame. Make sure | |
180 | ;; it has a minibuffer, but let initial-frame-alist omit the | |
181 | ;; minibuffer spec. | |
182 | (or (delq terminal-frame (minibuffer-frame-list)) | |
36fc9c9f | 183 | (progn |
3f2f8c83 | 184 | (setq frame-initial-frame-alist |
9688894d | 185 | (append initial-frame-alist default-frame-alist nil)) |
a8bb5882 RS |
186 | (or (assq 'horizontal-scroll-bars frame-initial-frame-alist) |
187 | (setq frame-initial-frame-alist | |
188 | (cons '(horizontal-scroll-bars . t) | |
189 | frame-initial-frame-alist))) | |
36fc9c9f RS |
190 | (setq default-minibuffer-frame |
191 | (setq frame-initial-frame | |
96a84970 | 192 | (make-frame frame-initial-frame-alist))) |
11281034 RS |
193 | ;; Delete any specifications for window geometry parameters |
194 | ;; so that we won't reapply them in frame-notice-user-settings. | |
195 | ;; It would be wrong to reapply them then, | |
196 | ;; because that would override explicit user resizing. | |
58bf6042 | 197 | (setq initial-frame-alist |
c2079f0a | 198 | (frame-remove-geometry-params initial-frame-alist)))) |
85557d7e | 199 | ;; At this point, we know that we have a frame open, so we |
dc6d9681 JB |
200 | ;; can delete the terminal frame. |
201 | (delete-frame terminal-frame) | |
202 | (setq terminal-frame nil)) | |
85557d7e | 203 | |
0759c4d0 KH |
204 | ;; No, we're not running a window system. Use make-terminal-frame if |
205 | ;; we support that feature, otherwise arrange to cause errors. | |
004f057a RS |
206 | (or (eq window-system 'pc) |
207 | (setq frame-creation-function | |
81b99826 GM |
208 | (if (fboundp 'tty-create-frame-with-faces) |
209 | 'tty-create-frame-with-faces | |
004f057a RS |
210 | (function |
211 | (lambda (parameters) | |
212 | (error | |
213 | "Can't create multiple frames without a window system")))))))) | |
85557d7e | 214 | |
8f2a992b GM |
215 | (defvar frame-notice-user-settings t |
216 | "Non-nil means function `frame-notice-user-settings' wasn't run yet.") | |
217 | ||
7eadab74 JB |
218 | ;;; startup.el calls this function after loading the user's init |
219 | ;;; file. Now default-frame-alist and initial-frame-alist contain | |
220 | ;;; information to which we must react; do what needs to be done. | |
dc6d9681 | 221 | (defun frame-notice-user-settings () |
40d34803 DL |
222 | "Act on user's init file settings of frame parameters. |
223 | React to settings of `default-frame-alist', `initial-frame-alist' there." | |
2ffa6186 | 224 | ;; Make menu-bar-mode and default-frame-alist consistent. |
61f2bcd7 GM |
225 | (when (boundp 'menu-bar-mode) |
226 | (let ((default (assq 'menu-bar-lines default-frame-alist))) | |
227 | (if default | |
228 | (setq menu-bar-mode (not (eq (cdr default) 0))) | |
229 | (setq default-frame-alist | |
230 | (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0)) | |
231 | default-frame-alist))))) | |
232 | ||
33a33c06 GM |
233 | ;; Make tool-bar-mode and default-frame-alist consistent. Don't do |
234 | ;; it in batch mode since that would leave a tool-bar-lines | |
235 | ;; parameter in default-frame-alist in a dumped Emacs, which is not | |
9688894d | 236 | ;; what we want. |
33a33c06 GM |
237 | (when (and (boundp 'tool-bar-mode) |
238 | (not noninteractive)) | |
61f2bcd7 GM |
239 | (let ((default (assq 'tool-bar-lines default-frame-alist))) |
240 | (if default | |
241 | (setq tool-bar-mode (not (eq (cdr default) 0))) | |
242 | (setq default-frame-alist | |
243 | (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0)) | |
244 | default-frame-alist))))) | |
2ffa6186 | 245 | |
7eadab74 JB |
246 | ;; Creating and deleting frames may shift the selected frame around, |
247 | ;; and thus the current buffer. Protect against that. We don't | |
248 | ;; want to use save-excursion here, because that may also try to set | |
249 | ;; the buffer of the selected window, which fails when the selected | |
250 | ;; window is the minibuffer. | |
251 | (let ((old-buffer (current-buffer))) | |
252 | ||
8f2a992b GM |
253 | (when (and frame-notice-user-settings |
254 | (null frame-initial-frame)) | |
42002db5 EZ |
255 | ;; This case happens when we don't have a window system, and |
256 | ;; also for MS-DOS frames. | |
8f2a992b GM |
257 | (let ((parms (frame-parameters frame-initial-frame))) |
258 | ;; Don't change the frame names. | |
259 | (setq parms (delq (assq 'name parms) parms)) | |
260 | ;; Can't modify the minibuffer parameter, so don't try. | |
261 | (setq parms (delq (assq 'minibuffer parms) parms)) | |
262 | (modify-frame-parameters nil | |
42002db5 EZ |
263 | (if (null window-system) |
264 | (append initial-frame-alist | |
265 | default-frame-alist | |
266 | parms | |
267 | nil) | |
268 | ;; initial-frame-alist and | |
269 | ;; default-frame-alist were already | |
270 | ;; applied in pc-win.el. | |
271 | parms)) | |
272 | (if (null window-system) ;; MS-DOS does this differently in pc-win.el | |
273 | (let ((newparms (frame-parameters)) | |
274 | (frame (selected-frame))) | |
275 | (tty-handle-reverse-video frame newparms) | |
276 | ;; If we changed the background color, we need to update | |
277 | ;; the background-mode parameter, and maybe some faces, | |
278 | ;; too. | |
279 | (when (assq 'background-color newparms) | |
280 | (unless (or (assq 'background-mode initial-frame-alist) | |
281 | (assq 'background-mode default-frame-alist)) | |
282 | (frame-set-background-mode frame)) | |
283 | (face-set-after-frame-default frame)))))) | |
8f2a992b | 284 | |
7eadab74 JB |
285 | ;; If the initial frame is still around, apply initial-frame-alist |
286 | ;; and default-frame-alist to it. | |
9688894d GM |
287 | (when (frame-live-p frame-initial-frame) |
288 | ||
289 | ;; When tool-bar has been switched off, correct the frame size | |
290 | ;; by the lines added in x-create-frame for the tool-bar and | |
291 | ;; switch `tool-bar-mode' off. | |
085ef9b3 GM |
292 | (when (display-graphic-p) |
293 | (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist) | |
294 | (assq 'tool-bar-lines default-frame-alist)))) | |
5c39a60f JR |
295 | (when (and tool-bar-originally-present |
296 | (or (null tool-bar-lines) | |
297 | (null (cdr tool-bar-lines)) | |
298 | (eq 0 (cdr tool-bar-lines)))) | |
085ef9b3 | 299 | (let* ((char-height (frame-char-height frame-initial-frame)) |
5c39a60f | 300 | (image-height tool-bar-images-pixel-height) |
085ef9b3 GM |
301 | (margin (cond ((and (consp tool-bar-button-margin) |
302 | (integerp (cdr tool-bar-button-margin)) | |
303 | (> tool-bar-button-margin 0)) | |
304 | (cdr tool-bar-button-margin)) | |
305 | ((and (integerp tool-bar-button-margin) | |
306 | (> tool-bar-button-margin 0)) | |
307 | tool-bar-button-margin) | |
308 | (t 0))) | |
309 | (relief (if (and (integerp tool-bar-button-relief) | |
310 | (> tool-bar-button-relief 0)) | |
311 | tool-bar-button-relief 3)) | |
312 | (lines (/ (+ image-height | |
313 | (* 2 margin) | |
314 | (* 2 relief) | |
315 | (1- char-height)) | |
316 | char-height)) | |
317 | (height (frame-parameter frame-initial-frame 'height)) | |
318 | (newparms (list (cons 'height (- height lines)))) | |
319 | (initial-top (cdr (assq 'top | |
320 | frame-initial-geometry-arguments))) | |
321 | (top (frame-parameter frame-initial-frame 'top))) | |
322 | (when (and (consp initial-top) (eq '- (car initial-top))) | |
323 | (setq newparms | |
324 | (append newparms | |
325 | `((top . ,(+ top (* lines char-height)))) | |
326 | nil))) | |
327 | (modify-frame-parameters frame-initial-frame newparms) | |
328 | (tool-bar-mode -1))))) | |
9688894d GM |
329 | |
330 | ;; The initial frame we create above always has a minibuffer. | |
331 | ;; If the user wants to remove it, or make it a minibuffer-only | |
332 | ;; frame, then we'll have to delete the current frame and make a | |
333 | ;; new one; you can't remove or add a root window to/from an | |
334 | ;; existing frame. | |
335 | ;; | |
336 | ;; NOTE: default-frame-alist was nil when we created the | |
337 | ;; existing frame. We need to explicitly include | |
338 | ;; default-frame-alist in the parameters of the screen we | |
339 | ;; create here, so that its new value, gleaned from the user's | |
340 | ;; .emacs file, will be applied to the existing screen. | |
de2f5dbe GM |
341 | (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist) |
342 | (assq 'minibuffer default-frame-alist) | |
343 | '(minibuffer . t))) | |
344 | t)) | |
345 | ;; Create the new frame. | |
346 | (let (parms new) | |
347 | ;; If the frame isn't visible yet, wait till it is. | |
348 | ;; If the user has to position the window, | |
349 | ;; Emacs doesn't know its real position until | |
350 | ;; the frame is seen to be visible. | |
351 | (while (not (cdr (assq 'visibility | |
352 | (frame-parameters frame-initial-frame)))) | |
353 | (sleep-for 1)) | |
354 | (setq parms (frame-parameters frame-initial-frame)) | |
9688894d GM |
355 | |
356 | ;; Get rid of `name' unless it was specified explicitly before. | |
de2f5dbe GM |
357 | (or (assq 'name frame-initial-frame-alist) |
358 | (setq parms (delq (assq 'name parms) parms))) | |
359 | ||
360 | (setq parms (append initial-frame-alist | |
361 | default-frame-alist | |
362 | parms | |
363 | nil)) | |
364 | ||
365 | ;; Get rid of `reverse', because that was handled | |
366 | ;; when we first made the frame. | |
367 | (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms))) | |
368 | ||
369 | (if (assq 'height frame-initial-geometry-arguments) | |
370 | (setq parms (assq-delete-all 'height parms))) | |
371 | (if (assq 'width frame-initial-geometry-arguments) | |
372 | (setq parms (assq-delete-all 'width parms))) | |
373 | (if (assq 'left frame-initial-geometry-arguments) | |
374 | (setq parms (assq-delete-all 'left parms))) | |
375 | (if (assq 'top frame-initial-geometry-arguments) | |
376 | (setq parms (assq-delete-all 'top parms))) | |
377 | (setq new | |
378 | (make-frame | |
379 | ;; Use the geometry args that created the existing | |
380 | ;; frame, rather than the parms we get for it. | |
381 | (append frame-initial-geometry-arguments | |
382 | '((user-size . t) (user-position . t)) | |
383 | parms))) | |
384 | ;; The initial frame, which we are about to delete, may be | |
385 | ;; the only frame with a minibuffer. If it is, create a | |
386 | ;; new one. | |
387 | (or (delq frame-initial-frame (minibuffer-frame-list)) | |
388 | (make-initial-minibuffer-frame nil)) | |
389 | ||
390 | ;; If the initial frame is serving as a surrogate | |
391 | ;; minibuffer frame for any frames, we need to wean them | |
392 | ;; onto a new frame. The default-minibuffer-frame | |
393 | ;; variable must be handled similarly. | |
394 | (let ((users-of-initial | |
395 | (filtered-frame-list | |
396 | (function (lambda (frame) | |
397 | (and (not (eq frame frame-initial-frame)) | |
398 | (eq (window-frame | |
399 | (minibuffer-window frame)) | |
400 | frame-initial-frame))))))) | |
401 | (if (or users-of-initial | |
402 | (eq default-minibuffer-frame frame-initial-frame)) | |
403 | ||
404 | ;; Choose an appropriate frame. Prefer frames which | |
405 | ;; are only minibuffers. | |
406 | (let* ((new-surrogate | |
407 | (car | |
408 | (or (filtered-frame-list | |
409 | (function | |
410 | (lambda (frame) | |
411 | (eq (cdr (assq 'minibuffer | |
412 | (frame-parameters frame))) | |
413 | 'only)))) | |
414 | (minibuffer-frame-list)))) | |
415 | (new-minibuffer (minibuffer-window new-surrogate))) | |
416 | ||
417 | (if (eq default-minibuffer-frame frame-initial-frame) | |
418 | (setq default-minibuffer-frame new-surrogate)) | |
419 | ||
420 | ;; Wean the frames using frame-initial-frame as | |
421 | ;; their minibuffer frame. | |
422 | (mapcar | |
423 | (function | |
424 | (lambda (frame) | |
425 | (modify-frame-parameters | |
426 | frame (list (cons 'minibuffer new-minibuffer))))) | |
427 | users-of-initial)))) | |
428 | ||
429 | ;; Redirect events enqueued at this frame to the new frame. | |
430 | ;; Is this a good idea? | |
431 | (redirect-frame-focus frame-initial-frame new) | |
432 | ||
433 | ;; Finally, get rid of the old frame. | |
434 | (delete-frame frame-initial-frame t)) | |
9688894d GM |
435 | |
436 | ;; Otherwise, we don't need all that rigamarole; just apply | |
437 | ;; the new parameters. | |
438 | (let (newparms allparms tail) | |
439 | (setq allparms (append initial-frame-alist | |
440 | default-frame-alist nil)) | |
441 | (if (assq 'height frame-initial-geometry-arguments) | |
442 | (setq allparms (assq-delete-all 'height allparms))) | |
443 | (if (assq 'width frame-initial-geometry-arguments) | |
444 | (setq allparms (assq-delete-all 'width allparms))) | |
445 | (if (assq 'left frame-initial-geometry-arguments) | |
446 | (setq allparms (assq-delete-all 'left allparms))) | |
447 | (if (assq 'top frame-initial-geometry-arguments) | |
448 | (setq allparms (assq-delete-all 'top allparms))) | |
449 | (setq tail allparms) | |
450 | ;; Find just the parms that have changed since we first | |
451 | ;; made this frame. Those are the ones actually set by | |
452 | ;; the init file. For those parms whose values we already knew | |
453 | ;; (such as those spec'd by command line options) | |
454 | ;; it is undesirable to specify the parm again | |
455 | ;; once the user has seen the frame and been able to alter it | |
456 | ;; manually. | |
457 | (while tail | |
458 | (let (newval oldval) | |
459 | (setq oldval (assq (car (car tail)) | |
460 | frame-initial-frame-alist)) | |
461 | (setq newval (cdr (assq (car (car tail)) allparms))) | |
462 | (or (and oldval (eq (cdr oldval) newval)) | |
463 | (setq newparms | |
464 | (cons (cons (car (car tail)) newval) newparms)))) | |
465 | (setq tail (cdr tail))) | |
466 | (setq newparms (nreverse newparms)) | |
467 | (modify-frame-parameters frame-initial-frame | |
468 | newparms) | |
469 | ;; If we changed the background color, | |
470 | ;; we need to update the background-mode parameter | |
471 | ;; and maybe some faces too. | |
472 | (when (assq 'background-color newparms) | |
473 | (unless (assq 'background-mode newparms) | |
474 | (frame-set-background-mode frame-initial-frame)) | |
475 | (face-set-after-frame-default frame-initial-frame))))) | |
64c669bc | 476 | |
7eadab74 JB |
477 | ;; Restore the original buffer. |
478 | (set-buffer old-buffer) | |
479 | ||
480 | ;; Make sure the initial frame can be GC'd if it is ever deleted. | |
d202f1f2 | 481 | ;; Make sure frame-notice-user-settings does nothing if called twice. |
8f2a992b | 482 | (setq frame-notice-user-settings nil) |
d202f1f2 | 483 | (setq frame-initial-frame nil))) |
64c669bc | 484 | |
746bd265 KH |
485 | (defun make-initial-minibuffer-frame (display) |
486 | (let ((parms (append minibuffer-frame-alist '((minibuffer . only))))) | |
487 | (if display | |
488 | (make-frame-on-display display parms) | |
489 | (make-frame parms)))) | |
490 | ||
7eadab74 | 491 | ;;;; Creation of additional frames, and other frame miscellanea |
dc6d9681 | 492 | |
7253d8e0 | 493 | (defun get-other-frame () |
40d34803 DL |
494 | "Return some frame other than the current frame. |
495 | Create one if necessary. Note that the minibuffer frame, if separate, | |
496 | is not considered (see `next-frame')." | |
dc6d9681 | 497 | (let ((s (if (equal (next-frame (selected-frame)) (selected-frame)) |
6eb018ba | 498 | (make-frame) |
dc6d9681 | 499 | (next-frame (selected-frame))))) |
64c669bc JB |
500 | s)) |
501 | ||
dc6d9681 JB |
502 | (defun next-multiframe-window () |
503 | "Select the next window, regardless of which frame it is on." | |
64c669bc JB |
504 | (interactive) |
505 | (select-window (next-window (selected-window) | |
506 | (> (minibuffer-depth) 0) | |
507 | t))) | |
508 | ||
dc6d9681 JB |
509 | (defun previous-multiframe-window () |
510 | "Select the previous window, regardless of which frame it is on." | |
64c669bc JB |
511 | (interactive) |
512 | (select-window (previous-window (selected-window) | |
513 | (> (minibuffer-depth) 0) | |
514 | t))) | |
515 | ||
6d73e337 RS |
516 | (defun make-frame-on-display (display &optional parameters) |
517 | "Make a frame on display DISPLAY. | |
518 | The optional second argument PARAMETERS specifies additional frame parameters." | |
519 | (interactive "sMake frame on display: ") | |
a9ca74cd RS |
520 | (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display) |
521 | (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN")) | |
6d73e337 RS |
522 | (make-frame (cons (cons 'display display) parameters))) |
523 | ||
6238bfaf RS |
524 | (defun make-frame-command () |
525 | "Make a new frame, and select it if the terminal displays only one frame." | |
526 | (interactive) | |
c1b1350b | 527 | (if (and window-system (not (eq window-system 'pc))) |
6238bfaf RS |
528 | (make-frame) |
529 | (select-frame (make-frame)))) | |
530 | ||
45c4fdeb SM |
531 | (defvar before-make-frame-hook nil |
532 | "Functions to run before a frame is created.") | |
533 | ||
534 | (defvar after-make-frame-functions nil | |
535 | "Functions to run after a frame is created. | |
536 | The functions are run with one arg, the newly created frame.") | |
537 | ||
72bf1a8b | 538 | (defvar after-setting-font-hook nil |
81b99826 GM |
539 | "Functions to run after a frame's font has been changed.") |
540 | ||
92e443b1 | 541 | ;; Alias, kept temporarily. |
31e1d920 | 542 | (defalias 'new-frame 'make-frame) |
bc93c097 | 543 | |
45c4fdeb SM |
544 | (defun make-frame (&optional parameters) |
545 | "Return a newly created frame displaying the current buffer. | |
546 | Optional argument PARAMETERS is an alist of parameters for the new frame. | |
547 | Each element of PARAMETERS should have the form (NAME . VALUE), for example: | |
a105105a | 548 | |
45c4fdeb | 549 | (name . STRING) The frame should be named STRING. |
43a2e52c | 550 | |
45c4fdeb SM |
551 | (width . NUMBER) The frame should be NUMBER characters in width. |
552 | (height . NUMBER) The frame should be NUMBER text lines high. | |
43a2e52c | 553 | |
45c4fdeb | 554 | You cannot specify either `width' or `height', you must use neither or both. |
43a2e52c | 555 | |
45c4fdeb SM |
556 | (minibuffer . t) The frame should have a minibuffer. |
557 | (minibuffer . nil) The frame should have no minibuffer. | |
558 | (minibuffer . only) The frame should contain only a minibuffer. | |
559 | (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window. | |
43a2e52c | 560 | |
45c4fdeb SM |
561 | Before the frame is created (via `frame-creation-function'), functions on the |
562 | hook `before-make-frame-hook' are run. After the frame is created, functions | |
563 | on `after-make-frame-functions' are run with one arg, the newly created frame." | |
64c669bc | 564 | (interactive) |
45c4fdeb SM |
565 | (run-hooks 'before-make-frame-hook) |
566 | (let ((frame (funcall frame-creation-function parameters))) | |
567 | (run-hook-with-args 'after-make-frame-functions frame) | |
568 | frame)) | |
64c669bc | 569 | |
7eadab74 JB |
570 | (defun filtered-frame-list (predicate) |
571 | "Return a list of all live frames which satisfy PREDICATE." | |
047bc928 GM |
572 | (let* ((frames (frame-list)) |
573 | (list frames)) | |
7eadab74 | 574 | (while (consp frames) |
047bc928 GM |
575 | (unless (funcall predicate (car frames)) |
576 | (setcar frames nil)) | |
7eadab74 | 577 | (setq frames (cdr frames))) |
047bc928 | 578 | (delq nil list))) |
7eadab74 JB |
579 | |
580 | (defun minibuffer-frame-list () | |
581 | "Return a list of all frames with their own minibuffers." | |
582 | (filtered-frame-list | |
583 | (function (lambda (frame) | |
584 | (eq frame (window-frame (minibuffer-window frame))))))) | |
585 | ||
9911648b EZ |
586 | (defun frames-on-display-list (&optional display) |
587 | "Return a list of all frames on DISPLAY. | |
588 | DISPLAY is a name of a display, a string of the form HOST:SERVER.SCREEN. | |
589 | If DISPLAY is omitted or nil, it defaults to the selected frame's display." | |
047bc928 GM |
590 | (let* ((display (or display (frame-parameter nil 'display))) |
591 | (func #'(lambda (frame) | |
592 | (eq (frame-parameter frame 'display) display)))) | |
9911648b EZ |
593 | (filtered-frame-list func))) |
594 | ||
595 | (defun framep-on-display (&optional display) | |
596 | "Return the type of frames on DISPLAY. | |
597 | DISPLAY may be a display name or a frame. If it is a frame, its type is | |
598 | returned. | |
599 | If DISPLAY is omitted or nil, it defaults to the selected frame's display. | |
600 | All frames on a given display are of the same type." | |
601 | (or (framep display) | |
602 | (framep (car (frames-on-display-list display))))) | |
603 | ||
58bf6042 JB |
604 | (defun frame-remove-geometry-params (param-list) |
605 | "Return the parameter list PARAM-LIST, but with geometry specs removed. | |
606 | This deletes all bindings in PARAM-LIST for `top', `left', `width', | |
791e09d8 | 607 | `height', `user-size' and `user-position' parameters. |
58bf6042 JB |
608 | Emacs uses this to avoid overriding explicit moves and resizings from |
609 | the user during startup." | |
610 | (setq param-list (cons nil param-list)) | |
611 | (let ((tail param-list)) | |
612 | (while (consp (cdr tail)) | |
613 | (if (and (consp (car (cdr tail))) | |
791e09d8 RS |
614 | (memq (car (car (cdr tail))) |
615 | '(height width top left user-position user-size))) | |
616 | (progn | |
617 | (setq frame-initial-geometry-arguments | |
618 | (cons (car (cdr tail)) frame-initial-geometry-arguments)) | |
619 | (setcdr tail (cdr (cdr tail)))) | |
58bf6042 | 620 | (setq tail (cdr tail))))) |
e11c3dc2 KH |
621 | (setq frame-initial-geometry-arguments |
622 | (nreverse frame-initial-geometry-arguments)) | |
58bf6042 JB |
623 | (cdr param-list)) |
624 | ||
625 | ||
0ac18fb0 RS |
626 | (defcustom focus-follows-mouse t |
627 | "*Non-nil if window system changes focus when you move the mouse." | |
628 | :type 'boolean | |
cd32a7ba DN |
629 | :group 'frames |
630 | :version "20.3") | |
26ef026d | 631 | |
ceab6935 | 632 | (defun other-frame (arg) |
a569dbc3 | 633 | "Select the ARG'th different visible frame, and raise it. |
ceab6935 RM |
634 | All frames are arranged in a cyclic order. |
635 | This command selects the frame ARG steps away in that order. | |
636 | A negative ARG moves in the opposite order." | |
637 | (interactive "p") | |
638 | (let ((frame (selected-frame))) | |
639 | (while (> arg 0) | |
a569dbc3 RM |
640 | (setq frame (next-frame frame)) |
641 | (while (not (eq (frame-visible-p frame) t)) | |
642 | (setq frame (next-frame frame))) | |
643 | (setq arg (1- arg))) | |
ceab6935 | 644 | (while (< arg 0) |
a569dbc3 RM |
645 | (setq frame (previous-frame frame)) |
646 | (while (not (eq (frame-visible-p frame) t)) | |
647 | (setq frame (previous-frame frame))) | |
915cfd1f | 648 | (setq arg (1+ arg))) |
699213bc | 649 | (select-frame frame) |
9af0f4cd | 650 | (raise-frame frame) |
9d702ce6 | 651 | ;; Ensure, if possible, that frame gets input focus. |
5b620012 GM |
652 | (when (eq window-system 'w32) |
653 | (w32-focus-frame frame)) | |
654 | (cond (focus-follows-mouse | |
655 | (unless (eq window-system 'w32) | |
656 | (set-mouse-position (selected-frame) (1- (frame-width)) 0))) | |
657 | (t | |
658 | (when (eq window-system 'x) | |
659 | (x-focus-frame frame)))))) | |
845cde06 EZ |
660 | |
661 | (defun make-frame-names-alist () | |
662 | (let* ((current-frame (selected-frame)) | |
663 | (falist | |
664 | (cons | |
665 | (cons (frame-parameter current-frame 'name) current-frame) nil)) | |
666 | (frame (next-frame nil t))) | |
667 | (while (not (eq frame current-frame)) | |
668 | (progn | |
669 | (setq falist (cons (cons (frame-parameter frame 'name) frame) falist)) | |
670 | (setq frame (next-frame frame t)))) | |
671 | falist)) | |
672 | ||
673 | (defvar frame-name-history nil) | |
845cde06 EZ |
674 | (defun select-frame-by-name (name) |
675 | "Select the frame whose name is NAME and raise it. | |
676 | If there is no frame by that name, signal an error." | |
677 | (interactive | |
716ff1c9 RS |
678 | (let* ((frame-names-alist (make-frame-names-alist)) |
679 | (default (car (car frame-names-alist))) | |
680 | (input (completing-read | |
681 | (format "Select Frame (default %s): " default) | |
682 | frame-names-alist nil t nil 'frame-name-history))) | |
845cde06 EZ |
683 | (if (= (length input) 0) |
684 | (list default) | |
685 | (list input)))) | |
716ff1c9 RS |
686 | (let* ((frame-names-alist (make-frame-names-alist)) |
687 | (frame (cdr (assoc name frame-names-alist)))) | |
845cde06 EZ |
688 | (or frame |
689 | (error "There is no frame named `%s'" name)) | |
690 | (make-frame-visible frame) | |
691 | (raise-frame frame) | |
880a9ae1 AI |
692 | (select-frame frame) |
693 | ;; Ensure, if possible, that frame gets input focus. | |
694 | (if (eq window-system 'w32) | |
695 | (w32-focus-frame frame) | |
696 | (when focus-follows-mouse | |
697 | (set-mouse-position (selected-frame) (1- (frame-width)) 0))))) | |
64c669bc | 698 | \f |
dc6d9681 JB |
699 | ;;;; Frame configurations |
700 | ||
701 | (defun current-frame-configuration () | |
702 | "Return a list describing the positions and states of all frames. | |
376a7584 JB |
703 | Its car is `frame-configuration'. |
704 | Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG), | |
705 | where | |
706 | FRAME is a frame object, | |
707 | ALIST is an association list specifying some of FRAME's parameters, and | |
708 | WINDOW-CONFIG is a window configuration object for FRAME." | |
709 | (cons 'frame-configuration | |
710 | (mapcar (function | |
711 | (lambda (frame) | |
712 | (list frame | |
713 | (frame-parameters frame) | |
714 | (current-window-configuration frame)))) | |
715 | (frame-list)))) | |
dc6d9681 | 716 | |
68cd265f | 717 | (defun set-frame-configuration (configuration &optional nodelete) |
dc6d9681 JB |
718 | "Restore the frames to the state described by CONFIGURATION. |
719 | Each frame listed in CONFIGURATION has its position, size, window | |
68cd265f | 720 | configuration, and other parameters set as specified in CONFIGURATION. |
a78db71c RS |
721 | Ordinarily, this function deletes all existing frames not |
722 | listed in CONFIGURATION. But if optional second argument NODELETE | |
5da841d2 | 723 | is given and non-nil, the unwanted frames are iconified instead." |
376a7584 JB |
724 | (or (frame-configuration-p configuration) |
725 | (signal 'wrong-type-argument | |
726 | (list 'frame-configuration-p configuration))) | |
727 | (let ((config-alist (cdr configuration)) | |
728 | frames-to-delete) | |
06b1a5ef | 729 | (mapcar (function |
dc6d9681 | 730 | (lambda (frame) |
376a7584 | 731 | (let ((parameters (assq frame config-alist))) |
06b1a5ef JB |
732 | (if parameters |
733 | (progn | |
98e9d14b JB |
734 | (modify-frame-parameters |
735 | frame | |
85557d7e | 736 | ;; Since we can't set a frame's minibuffer status, |
98e9d14b JB |
737 | ;; we might as well omit the parameter altogether. |
738 | (let* ((parms (nth 1 parameters)) | |
739 | (mini (assq 'minibuffer parms))) | |
740 | (if mini (setq parms (delq mini parms))) | |
741 | parms)) | |
06b1a5ef | 742 | (set-window-configuration (nth 2 parameters))) |
dc6d9681 JB |
743 | (setq frames-to-delete (cons frame frames-to-delete)))))) |
744 | (frame-list)) | |
a78db71c | 745 | (if nodelete |
5da841d2 RS |
746 | ;; Note: making frames invisible here was tried |
747 | ;; but led to some strange behavior--each time the frame | |
748 | ;; was made visible again, the window manager asked afresh | |
749 | ;; for where to put it. | |
750 | (mapcar 'iconify-frame frames-to-delete) | |
a78db71c | 751 | (mapcar 'delete-frame frames-to-delete)))) |
64c669bc | 752 | \f |
dc6d9681 JB |
753 | ;;;; Convenience functions for accessing and interactively changing |
754 | ;;;; frame parameters. | |
64c669bc | 755 | |
151bdc83 | 756 | (defun frame-height (&optional frame) |
dc6d9681 JB |
757 | "Return number of lines available for display on FRAME. |
758 | If FRAME is omitted, describe the currently selected frame." | |
151bdc83 | 759 | (cdr (assq 'height (frame-parameters frame)))) |
dc6d9681 JB |
760 | |
761 | (defun frame-width (&optional frame) | |
762 | "Return number of columns available for display on FRAME. | |
763 | If FRAME is omitted, describe the currently selected frame." | |
151bdc83 | 764 | (cdr (assq 'width (frame-parameters frame)))) |
dc6d9681 | 765 | |
889611f0 RS |
766 | (defalias 'set-default-font 'set-frame-font) |
767 | (defun set-frame-font (font-name) | |
40d34803 | 768 | "Set the font of the selected frame to FONT-NAME. |
61298010 RS |
769 | When called interactively, prompt for the name of the font to use. |
770 | To get the frame's current default font, use `frame-parameters'." | |
faaf40e4 MB |
771 | (interactive |
772 | (list | |
773 | (let ((completion-ignore-case t)) | |
774 | (completing-read "Font name: " | |
775 | (mapcar #'list | |
776 | ;; x-list-fonts will fail with an error | |
777 | ;; if this frame doesn't support fonts. | |
778 | (x-list-fonts "*" nil (selected-frame))))))) | |
dc6d9681 | 779 | (modify-frame-parameters (selected-frame) |
4033f46b | 780 | (list (cons 'font font-name))) |
72bf1a8b | 781 | (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)) |
64c669bc | 782 | |
8290babd | 783 | (defun set-background-color (color-name) |
40d34803 | 784 | "Set the background color of the selected frame to COLOR-NAME. |
61298010 RS |
785 | When called interactively, prompt for the name of the color to use. |
786 | To get the frame's current background color, use `frame-parameters'." | |
40d34803 | 787 | (interactive (list (facemenu-read-color))) |
dc6d9681 | 788 | (modify-frame-parameters (selected-frame) |
c9dc8173 | 789 | (list (cons 'background-color color-name)))) |
64c669bc | 790 | |
8290babd | 791 | (defun set-foreground-color (color-name) |
40d34803 | 792 | "Set the foreground color of the selected frame to COLOR-NAME. |
61298010 RS |
793 | When called interactively, prompt for the name of the color to use. |
794 | To get the frame's current foreground color, use `frame-parameters'." | |
40d34803 | 795 | (interactive (list (facemenu-read-color))) |
dc6d9681 | 796 | (modify-frame-parameters (selected-frame) |
c9dc8173 | 797 | (list (cons 'foreground-color color-name)))) |
64c669bc JB |
798 | |
799 | (defun set-cursor-color (color-name) | |
40d34803 | 800 | "Set the text cursor color of the selected frame to COLOR-NAME. |
61298010 RS |
801 | When called interactively, prompt for the name of the color to use. |
802 | To get the frame's current cursor color, use `frame-parameters'." | |
40d34803 | 803 | (interactive (list (facemenu-read-color))) |
dc6d9681 | 804 | (modify-frame-parameters (selected-frame) |
7eadab74 | 805 | (list (cons 'cursor-color color-name)))) |
64c669bc | 806 | |
eaa974e1 | 807 | (defun set-mouse-color (color-name) |
40d34803 | 808 | "Set the color of the mouse pointer of the selected frame to COLOR-NAME. |
61298010 RS |
809 | When called interactively, prompt for the name of the color to use. |
810 | To get the frame's current mouse color, use `frame-parameters'." | |
40d34803 | 811 | (interactive (list (facemenu-read-color))) |
dc6d9681 | 812 | (modify-frame-parameters (selected-frame) |
ec6d4463 KH |
813 | (list (cons 'mouse-color |
814 | (or color-name | |
815 | (cdr (assq 'mouse-color | |
816 | (frame-parameters)))))))) | |
7eadab74 | 817 | |
eaa974e1 | 818 | (defun set-border-color (color-name) |
40d34803 | 819 | "Set the color of the border of the selected frame to COLOR-NAME. |
61298010 RS |
820 | When called interactively, prompt for the name of the color to use. |
821 | To get the frame's current border color, use `frame-parameters'." | |
40d34803 | 822 | (interactive (list (facemenu-read-color))) |
eaa974e1 JB |
823 | (modify-frame-parameters (selected-frame) |
824 | (list (cons 'border-color color-name)))) | |
825 | ||
826 | (defun auto-raise-mode (arg) | |
7eadab74 | 827 | "Toggle whether or not the selected frame should auto-raise. |
79e6ae33 RS |
828 | With arg, turn auto-raise mode on if and only if arg is positive. |
829 | Note that this controls Emacs's own auto-raise feature. | |
830 | Some window managers allow you to enable auto-raise for certain windows. | |
831 | You can use that for Emacs windows if you wish, but if you do, | |
832 | that is beyond the control of Emacs and this command has no effect on it." | |
7eadab74 JB |
833 | (interactive "P") |
834 | (if (null arg) | |
835 | (setq arg | |
836 | (if (cdr (assq 'auto-raise (frame-parameters (selected-frame)))) | |
837 | -1 1))) | |
9626b928 GM |
838 | (if (> arg 0) |
839 | (raise-frame (selected-frame))) | |
dc6d9681 | 840 | (modify-frame-parameters (selected-frame) |
7eadab74 JB |
841 | (list (cons 'auto-raise (> arg 0))))) |
842 | ||
eaa974e1 | 843 | (defun auto-lower-mode (arg) |
7eadab74 | 844 | "Toggle whether or not the selected frame should auto-lower. |
79e6ae33 RS |
845 | With arg, turn auto-lower mode on if and only if arg is positive. |
846 | Note that this controls Emacs's own auto-lower feature. | |
847 | Some window managers allow you to enable auto-lower for certain windows. | |
848 | You can use that for Emacs windows if you wish, but if you do, | |
849 | that is beyond the control of Emacs and this command has no effect on it." | |
7eadab74 JB |
850 | (interactive "P") |
851 | (if (null arg) | |
852 | (setq arg | |
853 | (if (cdr (assq 'auto-lower (frame-parameters (selected-frame)))) | |
854 | -1 1))) | |
dc6d9681 | 855 | (modify-frame-parameters (selected-frame) |
7eadab74 | 856 | (list (cons 'auto-lower (> arg 0))))) |
7777d03b EZ |
857 | (defun set-frame-name (name) |
858 | "Set the name of the selected frame to NAME. | |
859 | When called interactively, prompt for the name of the frame. | |
860 | The frame name is displayed on the modeline if the terminal displays only | |
861 | one frame, otherwise the name is displayed on the frame's caption bar." | |
862 | (interactive "sFrame name: ") | |
863 | (modify-frame-parameters (selected-frame) | |
864 | (list (cons 'name name)))) | |
64c669bc | 865 | \f |
9911648b EZ |
866 | ;;;; Frame/display capabilities. |
867 | (defun display-mouse-p (&optional display) | |
868 | "Return non-nil if DISPLAY has a mouse available. | |
869 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
870 | frame's display)." | |
871 | (let ((frame-type (framep-on-display display))) | |
872 | (cond | |
873 | ((eq frame-type 'pc) | |
874 | (msdos-mouse-p)) | |
875 | ((eq system-type 'windows-nt) | |
876 | (> w32-num-mouse-buttons 0)) | |
877 | ((memq frame-type '(x mac)) | |
878 | t) ;; We assume X and Mac *always* have a pointing device | |
879 | (t | |
7565ee93 DL |
880 | (or (and (featurep 'xt-mouse) |
881 | xterm-mouse-mode) | |
882 | ;; t-mouse is distributed with the GPM package. It doesn't have | |
883 | ;; a toggle. | |
884 | (featurep 't-mouse)))))) | |
9911648b EZ |
885 | |
886 | (defun display-popup-menus-p (&optional display) | |
887 | "Return non-nil if popup menus are supported on DISPLAY. | |
888 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
889 | frame's display). | |
890 | Support for popup menus requires that the mouse be available." | |
891 | (and | |
892 | (let ((frame-type (framep-on-display display))) | |
893 | (memq frame-type '(x w32 pc mac))) | |
894 | (display-mouse-p display))) | |
895 | ||
896 | (defun display-graphic-p (&optional display) | |
897 | "Return non-nil if DISPLAY is a graphic display. | |
898 | Graphical displays are those which are capable of displaying several | |
899 | frames and several different fonts at once. This is true for displays | |
900 | that use a window system such as X, and false for text-only terminals. | |
901 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
902 | frame's display)." | |
903 | (not (null (memq (framep-on-display display) '(x w32 mac))))) | |
904 | ||
6693b279 EZ |
905 | (defalias 'display-multi-frame-p 'display-graphic-p) |
906 | (defalias 'display-multi-font-p 'display-graphic-p) | |
907 | ||
9911648b EZ |
908 | (defun display-selections-p (&optional display) |
909 | "Return non-nil if DISPLAY supports selections. | |
910 | A selection is a way to transfer text or other data between programs | |
911 | via special system buffers called `selection' or `cut buffer' or | |
912 | `clipboard'. | |
913 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
914 | frame's display)." | |
915 | (let ((frame-type (framep-on-display display))) | |
916 | (cond | |
917 | ((eq frame-type 'pc) | |
918 | ;; MS-DOG frames support selections when Emacs runs inside | |
919 | ;; the Windows' DOS Box. | |
920 | (not (null dos-windows-version))) | |
921 | ((memq frame-type '(x w32 mac)) | |
922 | t) ;; FIXME? | |
923 | (t | |
924 | nil)))) | |
925 | ||
926 | (defun display-screens (&optional display) | |
927 | "Return the number of screens associated with DISPLAY." | |
928 | (let ((frame-type (framep-on-display display))) | |
929 | (cond | |
930 | ((memq frame-type '(x w32)) | |
931 | (x-display-screens display)) | |
932 | (t ;; FIXME: is this correct for the Mac? | |
933 | 1)))) | |
934 | ||
935 | (defun display-pixel-height (&optional display) | |
936 | "Return the height of DISPLAY's screen in pixels. | |
937 | For character terminals, each character counts as a single pixel." | |
938 | (let ((frame-type (framep-on-display display))) | |
939 | (cond | |
940 | ((memq frame-type '(x w32 mac)) | |
941 | (x-display-pixel-height display)) | |
942 | (t | |
943 | (frame-height (if (framep display) display (selected-frame))))))) | |
944 | ||
945 | (defun display-pixel-width (&optional display) | |
946 | "Return the width of DISPLAY's screen in pixels. | |
947 | For character terminals, each character counts as a single pixel." | |
948 | (let ((frame-type (framep-on-display display))) | |
949 | (cond | |
950 | ((memq frame-type '(x w32 mac)) | |
951 | (x-display-pixel-width display)) | |
952 | (t | |
953 | (frame-width (if (framep display) display (selected-frame))))))) | |
954 | ||
955 | (defun display-mm-height (&optional display) | |
956 | "Return the height of DISPLAY's screen in millimeters. | |
957 | If the information is unavailable, value is nil." | |
958 | (and (memq (framep-on-display display) '(x w32 mac)) | |
959 | (x-display-mm-height display))) | |
960 | ||
961 | (defun display-mm-width (&optional display) | |
962 | "Return the width of DISPLAY's screen in millimeters. | |
963 | If the information is unavailable, value is nil." | |
964 | (and (memq (framep-on-display display) '(x w32 mac)) | |
965 | (x-display-mm-width display))) | |
966 | ||
967 | (defun display-backing-store (&optional display) | |
968 | "Return the backing store capability of DISPLAY's screen. | |
969 | The value may be `always', `when-mapped', `not-useful', or nil if | |
970 | the question is inapplicable to a certain kind of display." | |
971 | (let ((frame-type (framep-on-display display))) | |
972 | (cond | |
973 | ((memq frame-type '(x w32 mac)) | |
974 | (x-display-backing-store display)) | |
975 | (t | |
976 | 'not-useful)))) | |
977 | ||
978 | (defun display-save-under (&optional display) | |
979 | "Return non-nil if DISPLAY's screen supports the SaveUnder feature." | |
980 | (let ((frame-type (framep-on-display display))) | |
981 | (cond | |
982 | ((memq frame-type '(x w32 mac)) | |
983 | (x-display-save-under display)) | |
984 | (t | |
985 | 'not-useful)))) | |
986 | ||
987 | (defun display-planes (&optional display) | |
988 | "Return the number of planes supported by DISPLAY." | |
989 | (let ((frame-type (framep-on-display display))) | |
990 | (cond | |
991 | ((memq frame-type '(x w32 mac)) | |
992 | (x-display-planes display)) | |
993 | ((eq frame-type 'pc) | |
994 | 4) | |
995 | (t | |
996 | (truncate (log (length (tty-color-alist)) 2)))))) | |
997 | ||
998 | (defun display-color-cells (&optional display) | |
999 | "Return the number of color cells supported by DISPLAY." | |
1000 | (let ((frame-type (framep-on-display display))) | |
1001 | (cond | |
1002 | ((memq frame-type '(x w32 mac)) | |
1003 | (x-display-color-cells display)) | |
1004 | ((eq frame-type 'pc) | |
1005 | 16) | |
1006 | (t | |
1007 | (length (tty-color-alist)))))) | |
1008 | ||
1009 | (defun display-visual-class (&optional display) | |
1010 | "Returns the visual class of DISPLAY. | |
1011 | The value is one of the symbols `static-gray', `gray-scale', | |
1012 | `static-color', `pseudo-color', `true-color', or `direct-color'." | |
1013 | (let ((frame-type (framep-on-display display))) | |
1014 | (cond | |
1015 | ((memq frame-type '(x w32 mac)) | |
1016 | (x-display-visual-class display)) | |
1017 | ((and (memq frame-type '(pc t)) | |
1018 | (tty-display-color-p display)) | |
1019 | 'static-color) | |
1020 | (t | |
1021 | 'static-gray)))) | |
1022 | ||
1023 | \f | |
dc6d9681 | 1024 | ;;;; Aliases for backward compatibility with Emacs 18. |
31e1d920 ER |
1025 | (defalias 'screen-height 'frame-height) |
1026 | (defalias 'screen-width 'frame-width) | |
9e2b097b JB |
1027 | |
1028 | (defun set-screen-width (cols &optional pretend) | |
40d34803 DL |
1029 | "Obsolete function to change the size of the screen to COLS columns. |
1030 | Optional second arg non-nil means that redisplay should use COLS columns | |
1031 | but that the idea of the actual width of the frame should not be changed. | |
1032 | This function is provided only for compatibility with Emacs 18; new code | |
fe668515 | 1033 | should use `set-frame-width instead'." |
9e2b097b JB |
1034 | (set-frame-width (selected-frame) cols pretend)) |
1035 | ||
1036 | (defun set-screen-height (lines &optional pretend) | |
40d34803 DL |
1037 | "Obsolete function to change the height of the screen to LINES lines. |
1038 | Optional second arg non-nil means that redisplay should use LINES lines | |
1039 | but that the idea of the actual height of the screen should not be changed. | |
1040 | This function is provided only for compatibility with Emacs 18; new code | |
ef5a6345 | 1041 | should use `set-frame-height' instead." |
9e2b097b JB |
1042 | (set-frame-height (selected-frame) lines pretend)) |
1043 | ||
154a757e GM |
1044 | (defun delete-other-frames (&optional frame) |
1045 | "Delete all frames except FRAME. | |
1046 | FRAME nil or omitted means delete all frames except the selected frame." | |
1047 | (interactive) | |
1048 | (unless frame | |
1049 | (setq frame (selected-frame))) | |
1050 | (mapcar 'delete-frame (delq frame (frame-list)))) | |
1051 | ||
1052 | ||
2598a293 SM |
1053 | (make-obsolete 'screen-height 'frame-height) ;before 19.15 |
1054 | (make-obsolete 'screen-width 'frame-width) ;before 19.15 | |
1055 | (make-obsolete 'set-screen-width 'set-frame-width) ;before 19.15 | |
1056 | (make-obsolete 'set-screen-height 'set-frame-height) ;before 19.15 | |
dc6d9681 JB |
1057 | |
1058 | \f | |
81b99826 GM |
1059 | ;;; Highlighting trailing whitespace. |
1060 | ||
1061 | (make-variable-buffer-local 'show-trailing-whitespace) | |
1062 | ||
1063 | (defcustom show-trailing-whitespace nil | |
1064 | "*Non-nil means highlight trailing whitespace in face `trailing-whitespace'." | |
1065 | :tag "Highlight trailing whitespace." | |
1066 | :set #'(lambda (symbol value) (set-default symbol value)) | |
1067 | :type 'boolean | |
1068 | :group 'font-lock) | |
1069 | ||
1070 | ||
1071 | \f | |
79b14b94 GM |
1072 | ;;; Scrolling |
1073 | ||
1074 | (defgroup scrolling nil | |
1075 | "Scrolling windows." | |
1076 | :version "21.1" | |
1077 | :group 'frames) | |
1078 | ||
1079 | (defcustom automatic-hscrolling t | |
1080 | "*Allow or disallow autmatic scrolling windows horizontally. | |
9ea60c46 | 1081 | If non-nil, windows are automatically scrolled horizontally to make |
79b14b94 GM |
1082 | point visible." |
1083 | :version "21.1" | |
1084 | :type 'boolean | |
1085 | :group 'scrolling) | |
1086 | ||
1087 | \f | |
81b99826 GM |
1088 | ;;; Blinking cursor |
1089 | ||
1090 | (defgroup cursor nil | |
ca693be8 | 1091 | "Displaying text cursors." |
40d34803 | 1092 | :version "21.1" |
81b99826 GM |
1093 | :group 'frames) |
1094 | ||
1095 | (defcustom blink-cursor-delay 0.5 | |
ca693be8 | 1096 | "*Seconds of idle time after which cursor starts to blink." |
81b99826 GM |
1097 | :tag "Delay in seconds." |
1098 | :type 'number | |
1099 | :group 'cursor) | |
1100 | ||
1101 | (defcustom blink-cursor-interval 0.5 | |
1102 | "*Length of cursor blink interval in seconds." | |
1103 | :tag "Blink interval in seconds." | |
1104 | :type 'number | |
1105 | :group 'cursor) | |
1106 | ||
1107 | (defvar blink-cursor-idle-timer nil | |
ca693be8 GM |
1108 | "Timer started after `blink-cursor-delay' seconds of Emacs idle time. |
1109 | The function `blink-cursor-start' is called when the timer fires.") | |
81b99826 GM |
1110 | |
1111 | (defvar blink-cursor-timer nil | |
ca693be8 GM |
1112 | "Timer started from `blink-cursor-start'. |
1113 | This timer calls `blink-cursor' every `blink-cursor-interval' seconds.") | |
81b99826 GM |
1114 | |
1115 | (defvar blink-cursor-mode nil | |
1116 | "Non-nil means blinking cursor is active.") | |
1117 | ||
1118 | (defun blink-cursor-mode (arg) | |
1119 | "Toggle blinking cursor mode. | |
be6bbb55 | 1120 | With a numeric argument, turn blinking cursor mode on iff ARG is positive. |
81b99826 GM |
1121 | When blinking cursor mode is enabled, the cursor of the selected |
1122 | window blinks." | |
1123 | (interactive "P") | |
1124 | (let ((on-p (if (null arg) | |
1125 | (not blink-cursor-mode) | |
1126 | (> (prefix-numeric-value arg) 0)))) | |
1127 | (if blink-cursor-idle-timer | |
1128 | (cancel-timer blink-cursor-idle-timer)) | |
1129 | (if blink-cursor-timer | |
1130 | (cancel-timer blink-cursor-timer)) | |
1131 | (setq blink-cursor-idle-timer nil | |
1132 | blink-cursor-timer nil | |
1133 | blink-cursor-mode nil) | |
1134 | (if on-p | |
1135 | (progn | |
1136 | ;; Hide the cursor. | |
cae2c28e | 1137 | ;(internal-show-cursor nil nil) |
81b99826 GM |
1138 | (setq blink-cursor-idle-timer |
1139 | (run-with-idle-timer blink-cursor-delay | |
1140 | blink-cursor-delay | |
1141 | 'blink-cursor-start)) | |
d4ed0cba GM |
1142 | (setq blink-cursor-mode t)) |
1143 | (internal-show-cursor nil t)))) | |
81b99826 | 1144 | |
cae2c28e GM |
1145 | ;; Note that this is really initialized from startup.el before |
1146 | ;; the init-file is read. | |
1147 | ||
1148 | (defcustom blink-cursor nil | |
ca693be8 | 1149 | "*Non-nil means blinking cursor mode is active." |
cae2c28e | 1150 | :group 'cursor |
81b99826 GM |
1151 | :tag "Blinking cursor" |
1152 | :type 'boolean | |
81b99826 GM |
1153 | :set #'(lambda (symbol value) |
1154 | (set-default symbol value) | |
1155 | (blink-cursor-mode (or value 0)))) | |
1156 | ||
1157 | (defun blink-cursor-start () | |
ca693be8 GM |
1158 | "Timer function called from the timer `blink-cursor-idle-timer'. |
1159 | This starts the timer `blink-cursor-timer', which makes the cursor blink | |
1160 | if appropriate. It also arranges to cancel that timer when the next | |
1161 | command starts, by installing a pre-command hook." | |
81b99826 GM |
1162 | (when (null blink-cursor-timer) |
1163 | (add-hook 'pre-command-hook 'blink-cursor-end) | |
1164 | (setq blink-cursor-timer | |
1165 | (run-with-timer blink-cursor-interval blink-cursor-interval | |
0a5ebe4b GM |
1166 | 'blink-cursor-timer-function)))) |
1167 | ||
1168 | (defun blink-cursor-timer-function () | |
1169 | "Timer function of timer `blink-cursor-timer'." | |
1170 | (internal-show-cursor nil (not (internal-show-cursor-p)))) | |
81b99826 GM |
1171 | |
1172 | (defun blink-cursor-end () | |
1173 | "Stop cursor blinking. | |
ca693be8 GM |
1174 | This is installed as a pre-command hook by `blink-cursor-start'. |
1175 | When run, it cancels the timer `blink-cursor-timer' and removes | |
1176 | itself as a pre-command hook." | |
81b99826 | 1177 | (remove-hook 'pre-command-hook 'blink-cursor-end) |
0a5ebe4b | 1178 | (internal-show-cursor nil t) |
81b99826 GM |
1179 | (cancel-timer blink-cursor-timer) |
1180 | (setq blink-cursor-timer nil)) | |
1181 | ||
1182 | ||
1183 | \f | |
a6c411ff | 1184 | ;;; Hourglass pointer |
81b99826 | 1185 | |
a6c411ff GM |
1186 | (defcustom display-hourglass t |
1187 | "*Non-nil means show an hourglass pointer when running under a window system." | |
1188 | :tag "Hourglass pointer" | |
81b99826 | 1189 | :type 'boolean |
a6c411ff | 1190 | :group 'cursor) |
81b99826 | 1191 | |
a6c411ff GM |
1192 | (defcustom hourglass-delay 1 |
1193 | "*Seconds to wait before displaying an hourglass pointer." | |
1194 | :tag "Hourglass delay" | |
0a86e779 | 1195 | :type 'number |
a6c411ff | 1196 | :group 'cursor) |
1d0a3ef4 | 1197 | |
5b2c5477 | 1198 | \f |
c0eb3c10 | 1199 | (defcustom cursor-in-non-selected-windows t |
5b2c5477 | 1200 | "*Non-nil means show a hollow box cursor in non-selected-windows. |
e053c60f | 1201 | If nil, don't show a cursor except in the selected window. |
c0eb3c10 | 1202 | Use Custom to set this variable to get the display updated." |
5b2c5477 GM |
1203 | :tag "Cursor in non-selected windows" |
1204 | :type 'boolean | |
1205 | :group 'cursor | |
5b2c5477 GM |
1206 | :set #'(lambda (symbol value) |
1207 | (set-default symbol value) | |
5b2c5477 GM |
1208 | (force-mode-line-update t))) |
1209 | ||
81b99826 | 1210 | \f |
64c669bc | 1211 | ;;;; Key bindings |
64c669bc | 1212 | |
6238bfaf | 1213 | (define-key ctl-x-5-map "2" 'make-frame-command) |
154a757e | 1214 | (define-key ctl-x-5-map "1" 'delete-other-frames) |
dc6d9681 | 1215 | (define-key ctl-x-5-map "0" 'delete-frame) |
ceab6935 | 1216 | (define-key ctl-x-5-map "o" 'other-frame) |
49116ac0 | 1217 | |
dc6d9681 | 1218 | (provide 'frame) |
c88ab9ce | 1219 | |
dc6d9681 | 1220 | ;;; frame.el ends here |