Commit | Line | Data |
---|---|---|
55535639 | 1 | ;;; frame.el --- multi-frame management independent of window systems |
c88ab9ce | 2 | |
ab422c4d PE |
3 | ;; Copyright (C) 1993-1994, 1996-1997, 2000-2013 Free Software |
4 | ;; Foundation, Inc. | |
3a801d0c | 5 | |
fc68affa | 6 | ;; Maintainer: FSF |
fd7fa35a | 7 | ;; Keywords: internal |
bd78fa1d | 8 | ;; Package: emacs |
fc68affa | 9 | |
b578f267 EN |
10 | ;; This file is part of GNU Emacs. |
11 | ||
eb3fa2cf | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
b578f267 | 13 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
b578f267 EN |
16 | |
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
64c669bc | 24 | |
55535639 PJ |
25 | ;;; Commentary: |
26 | ||
fc68affa | 27 | ;;; Code: |
efc3dd3c DC |
28 | (eval-when-compile (require 'cl-lib)) |
29 | ||
2246281f KL |
30 | (defvar frame-creation-function-alist |
31 | (list (cons nil | |
32 | (if (fboundp 'tty-create-frame-with-faces) | |
33 | 'tty-create-frame-with-faces | |
06b60517 | 34 | (lambda (_parameters) |
371fed4e | 35 | (error "Can't create multiple frames without a window system"))))) |
2246281f KL |
36 | "Alist of window-system dependent functions to call to create a new frame. |
37 | The window system startup file should add its frame creation | |
38 | function to this list, which should take an alist of parameters | |
39 | as its argument.") | |
114a8b8c | 40 | |
bf1ba39f | 41 | (defvar window-system-default-frame-alist nil |
5b95ee8a CY |
42 | "Window-system dependent default frame parameters. |
43 | The value should be an alist of elements (WINDOW-SYSTEM . ALIST), | |
44 | where WINDOW-SYSTEM is a window system symbol (see `window-system') | |
45 | and ALIST is a frame parameter alist like `default-frame-alist'. | |
46 | Then, for frames on WINDOW-SYSTEM, any parameters specified in | |
47 | ALIST supersede the corresponding parameters specified in | |
dca6c418 | 48 | `default-frame-alist'.") |
bf1ba39f | 49 | |
efc3dd3c DC |
50 | (defvar display-format-alist nil |
51 | "Alist of patterns to decode display names. | |
52 | The car of each entry is a regular expression matching a display | |
53 | name string. The cdr is a symbol giving the window-system that | |
54 | handles the corresponding kind of display.") | |
55 | ||
7e573c4a SM |
56 | ;; The initial value given here used to ask for a minibuffer. |
57 | ;; But that's not necessary, because the default is to have one. | |
58 | ;; By not specifying it here, we let an X resource specify it. | |
fac580eb | 59 | (defcustom initial-frame-alist nil |
dca6c418 MR |
60 | "Alist of parameters for the initial X window frame. |
61 | You can set this in your init file; for example, | |
62 | ||
63 | (setq initial-frame-alist | |
64 | '((top . 1) (left . 1) (width . 80) (height . 55))) | |
65 | ||
66 | Parameters specified here supersede the values given in | |
67 | `default-frame-alist'. | |
68 | ||
69 | If the value calls for a frame without a minibuffer, and you have | |
70 | not created a minibuffer frame on your own, a minibuffer frame is | |
71 | created according to `minibuffer-frame-alist'. | |
72 | ||
73 | You can specify geometry-related options for just the initial | |
74 | frame by setting this variable in your init file; however, they | |
75 | won't take effect until Emacs reads your init file, which happens | |
76 | after creating the initial frame. If you want the initial frame | |
77 | to have the proper geometry as soon as it appears, you need to | |
78 | use this three-step process: | |
de17da15 RS |
79 | * Specify X resources to give the geometry you want. |
80 | * Set `default-frame-alist' to override these options so that they | |
81 | don't affect subsequent frames. | |
82 | * Set `initial-frame-alist' in a way that matches the X resources, | |
0c966f88 RS |
83 | to override what you put in `default-frame-alist'." |
84 | :type '(repeat (cons :format "%v" | |
85 | (symbol :tag "Parameter") | |
86 | (sexp :tag "Value"))) | |
87 | :group 'frames) | |
64c669bc | 88 | |
0b9d32af | 89 | (defcustom minibuffer-frame-alist '((width . 80) (height . 2)) |
92e02072 CY |
90 | "Alist of parameters for the initial minibuffer frame. |
91 | This is the minibuffer frame created if `initial-frame-alist' | |
92 | calls for a frame without a minibuffer. The parameters specified | |
93 | here supersede those given in `default-frame-alist', for the | |
94 | initial minibuffer frame. | |
95 | ||
dca6c418 MR |
96 | You can set this in your init file; for example, |
97 | ||
dc6d9681 | 98 | (setq minibuffer-frame-alist |
dca6c418 MR |
99 | '((top . 1) (left . 1) (width . 80) (height . 2))) |
100 | ||
92e02072 CY |
101 | It is not necessary to include (minibuffer . only); that is |
102 | appended when the minibuffer frame is created." | |
0b9d32af RS |
103 | :type '(repeat (cons :format "%v" |
104 | (symbol :tag "Parameter") | |
105 | (sexp :tag "Value"))) | |
106 | :group 'frames) | |
64c669bc | 107 | |
924be53a | 108 | (defun handle-delete-frame (event) |
40d34803 | 109 | "Handle delete-frame events from the X server." |
924be53a RS |
110 | (interactive "e") |
111 | (let ((frame (posn-window (event-start event))) | |
112 | (i 0) | |
113 | (tail (frame-list))) | |
114 | (while tail | |
115 | (and (frame-visible-p (car tail)) | |
116 | (not (eq (car tail) frame)) | |
117 | (setq i (1+ i))) | |
118 | (setq tail (cdr tail))) | |
119 | (if (> i 0) | |
120 | (delete-frame frame t) | |
a9562d19 RS |
121 | ;; Gildea@x.org says it is ok to ask questions before terminating. |
122 | (save-buffers-kill-emacs)))) | |
64c669bc | 123 | \f |
dc6d9681 | 124 | ;;;; Arrangement of frames at startup |
64c669bc | 125 | |
7e573c4a SM |
126 | ;; 1) Load the window system startup file from the lisp library and read the |
127 | ;; high-priority arguments (-q and the like). The window system startup | |
128 | ;; file should create any frames specified in the window system defaults. | |
129 | ;; | |
130 | ;; 2) If no frames have been opened, we open an initial text frame. | |
131 | ;; | |
132 | ;; 3) Once the init file is done, we apply any newly set parameters | |
133 | ;; in initial-frame-alist to the frame. | |
64c669bc | 134 | |
85557d7e | 135 | ;; These are now called explicitly at the proper times, |
fc4d4afb RS |
136 | ;; since that is easier to understand. |
137 | ;; Actually using hooks within Emacs is bad for future maintenance. --rms. | |
138 | ;; (add-hook 'before-init-hook 'frame-initialize) | |
139 | ;; (add-hook 'window-setup-hook 'frame-notice-user-settings) | |
64c669bc | 140 | |
7e573c4a | 141 | ;; If we create the initial frame, this is it. |
dc6d9681 | 142 | (defvar frame-initial-frame nil) |
64c669bc | 143 | |
3f2f8c83 RS |
144 | ;; Record the parameters used in frame-initialize to make the initial frame. |
145 | (defvar frame-initial-frame-alist) | |
146 | ||
791e09d8 RS |
147 | (defvar frame-initial-geometry-arguments nil) |
148 | ||
7e573c4a SM |
149 | ;; startup.el calls this function before loading the user's init |
150 | ;; file - if there is no frame with a minibuffer open now, create | |
151 | ;; one to display messages while loading the init file. | |
dc6d9681 | 152 | (defun frame-initialize () |
ff2a1c79 | 153 | "Create an initial frame if necessary." |
64c669bc | 154 | ;; Are we actually running under a window system at all? |
2246281f KL |
155 | (if (and initial-window-system |
156 | (not noninteractive) | |
157 | (not (eq initial-window-system 'pc))) | |
7eadab74 JB |
158 | (progn |
159 | ;; If there is no frame with a minibuffer besides the terminal | |
160 | ;; frame, then we need to create the opening frame. Make sure | |
161 | ;; it has a minibuffer, but let initial-frame-alist omit the | |
162 | ;; minibuffer spec. | |
163 | (or (delq terminal-frame (minibuffer-frame-list)) | |
36fc9c9f | 164 | (progn |
3f2f8c83 | 165 | (setq frame-initial-frame-alist |
9688894d | 166 | (append initial-frame-alist default-frame-alist nil)) |
a8bb5882 RS |
167 | (or (assq 'horizontal-scroll-bars frame-initial-frame-alist) |
168 | (setq frame-initial-frame-alist | |
169 | (cons '(horizontal-scroll-bars . t) | |
170 | frame-initial-frame-alist))) | |
2246281f KL |
171 | (setq frame-initial-frame-alist |
172 | (cons (cons 'window-system initial-window-system) | |
173 | frame-initial-frame-alist)) | |
36fc9c9f RS |
174 | (setq default-minibuffer-frame |
175 | (setq frame-initial-frame | |
96a84970 | 176 | (make-frame frame-initial-frame-alist))) |
11281034 RS |
177 | ;; Delete any specifications for window geometry parameters |
178 | ;; so that we won't reapply them in frame-notice-user-settings. | |
179 | ;; It would be wrong to reapply them then, | |
180 | ;; because that would override explicit user resizing. | |
58bf6042 | 181 | (setq initial-frame-alist |
c2079f0a | 182 | (frame-remove-geometry-params initial-frame-alist)))) |
a13f8f50 KL |
183 | ;; Copy the environment of the Emacs process into the new frame. |
184 | (set-frame-parameter frame-initial-frame 'environment | |
185 | (frame-parameter terminal-frame 'environment)) | |
85557d7e | 186 | ;; At this point, we know that we have a frame open, so we |
dc6d9681 JB |
187 | ;; can delete the terminal frame. |
188 | (delete-frame terminal-frame) | |
2246281f | 189 | (setq terminal-frame nil)))) |
85557d7e | 190 | |
8f2a992b GM |
191 | (defvar frame-notice-user-settings t |
192 | "Non-nil means function `frame-notice-user-settings' wasn't run yet.") | |
193 | ||
aa360da1 GM |
194 | (declare-function tool-bar-mode "tool-bar" (&optional arg)) |
195 | ||
7e573c4a SM |
196 | ;; startup.el calls this function after loading the user's init |
197 | ;; file. Now default-frame-alist and initial-frame-alist contain | |
198 | ;; information to which we must react; do what needs to be done. | |
dc6d9681 | 199 | (defun frame-notice-user-settings () |
40d34803 | 200 | "Act on user's init file settings of frame parameters. |
0e1bfc78 KL |
201 | React to settings of `initial-frame-alist', |
202 | `window-system-default-frame-alist' and `default-frame-alist' | |
203 | there (in decreasing order of priority)." | |
7eadab74 JB |
204 | ;; Creating and deleting frames may shift the selected frame around, |
205 | ;; and thus the current buffer. Protect against that. We don't | |
206 | ;; want to use save-excursion here, because that may also try to set | |
207 | ;; the buffer of the selected window, which fails when the selected | |
208 | ;; window is the minibuffer. | |
0e1bfc78 | 209 | (let ((old-buffer (current-buffer)) |
cb01ce3f SM |
210 | (window-system-frame-alist |
211 | (cdr (assq initial-window-system | |
212 | window-system-default-frame-alist)))) | |
7eadab74 | 213 | |
8f2a992b GM |
214 | (when (and frame-notice-user-settings |
215 | (null frame-initial-frame)) | |
42002db5 EZ |
216 | ;; This case happens when we don't have a window system, and |
217 | ;; also for MS-DOS frames. | |
0216b738 | 218 | (let ((parms (frame-parameters))) |
8f2a992b GM |
219 | ;; Don't change the frame names. |
220 | (setq parms (delq (assq 'name parms) parms)) | |
221 | ;; Can't modify the minibuffer parameter, so don't try. | |
222 | (setq parms (delq (assq 'minibuffer parms) parms)) | |
0216b738 CY |
223 | (modify-frame-parameters |
224 | nil | |
225 | (if initial-window-system | |
226 | parms | |
227 | ;; initial-frame-alist and default-frame-alist were already | |
228 | ;; applied in pc-win.el. | |
229 | (append initial-frame-alist window-system-frame-alist | |
230 | default-frame-alist parms nil))) | |
2246281f | 231 | (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el |
42002db5 EZ |
232 | (let ((newparms (frame-parameters)) |
233 | (frame (selected-frame))) | |
234 | (tty-handle-reverse-video frame newparms) | |
235 | ;; If we changed the background color, we need to update | |
236 | ;; the background-mode parameter, and maybe some faces, | |
237 | ;; too. | |
238 | (when (assq 'background-color newparms) | |
239 | (unless (or (assq 'background-mode initial-frame-alist) | |
240 | (assq 'background-mode default-frame-alist)) | |
241 | (frame-set-background-mode frame)) | |
242 | (face-set-after-frame-default frame)))))) | |
8f2a992b | 243 | |
7eadab74 JB |
244 | ;; If the initial frame is still around, apply initial-frame-alist |
245 | ;; and default-frame-alist to it. | |
9688894d GM |
246 | (when (frame-live-p frame-initial-frame) |
247 | ||
248 | ;; When tool-bar has been switched off, correct the frame size | |
249 | ;; by the lines added in x-create-frame for the tool-bar and | |
250 | ;; switch `tool-bar-mode' off. | |
085ef9b3 GM |
251 | (when (display-graphic-p) |
252 | (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist) | |
0e1bfc78 | 253 | (assq 'tool-bar-lines window-system-frame-alist) |
085ef9b3 | 254 | (assq 'tool-bar-lines default-frame-alist)))) |
5c39a60f JR |
255 | (when (and tool-bar-originally-present |
256 | (or (null tool-bar-lines) | |
257 | (null (cdr tool-bar-lines)) | |
258 | (eq 0 (cdr tool-bar-lines)))) | |
085ef9b3 | 259 | (let* ((char-height (frame-char-height frame-initial-frame)) |
5c39a60f | 260 | (image-height tool-bar-images-pixel-height) |
085ef9b3 GM |
261 | (margin (cond ((and (consp tool-bar-button-margin) |
262 | (integerp (cdr tool-bar-button-margin)) | |
263 | (> tool-bar-button-margin 0)) | |
264 | (cdr tool-bar-button-margin)) | |
265 | ((and (integerp tool-bar-button-margin) | |
266 | (> tool-bar-button-margin 0)) | |
267 | tool-bar-button-margin) | |
268 | (t 0))) | |
269 | (relief (if (and (integerp tool-bar-button-relief) | |
270 | (> tool-bar-button-relief 0)) | |
271 | tool-bar-button-relief 3)) | |
f39784dd | 272 | (lines (/ (+ image-height |
085ef9b3 GM |
273 | (* 2 margin) |
274 | (* 2 relief) | |
275 | (1- char-height)) | |
276 | char-height)) | |
277 | (height (frame-parameter frame-initial-frame 'height)) | |
278 | (newparms (list (cons 'height (- height lines)))) | |
f39784dd | 279 | (initial-top (cdr (assq 'top |
085ef9b3 GM |
280 | frame-initial-geometry-arguments))) |
281 | (top (frame-parameter frame-initial-frame 'top))) | |
282 | (when (and (consp initial-top) (eq '- (car initial-top))) | |
7f18ce22 RS |
283 | (let ((adjusted-top |
284 | (cond ((and (consp top) | |
285 | (eq '+ (car top))) | |
286 | (list '+ | |
287 | (+ (cadr top) | |
288 | (* lines char-height)))) | |
289 | ((and (consp top) | |
290 | (eq '- (car top))) | |
291 | (list '- | |
292 | (- (cadr top) | |
293 | (* lines char-height)))) | |
294 | (t (+ top (* lines char-height)))))) | |
295 | (setq newparms | |
296 | (append newparms | |
297 | `((top . ,adjusted-top)) | |
298 | nil)))) | |
085ef9b3 GM |
299 | (modify-frame-parameters frame-initial-frame newparms) |
300 | (tool-bar-mode -1))))) | |
9688894d GM |
301 | |
302 | ;; The initial frame we create above always has a minibuffer. | |
303 | ;; If the user wants to remove it, or make it a minibuffer-only | |
304 | ;; frame, then we'll have to delete the current frame and make a | |
305 | ;; new one; you can't remove or add a root window to/from an | |
306 | ;; existing frame. | |
307 | ;; | |
308 | ;; NOTE: default-frame-alist was nil when we created the | |
309 | ;; existing frame. We need to explicitly include | |
310 | ;; default-frame-alist in the parameters of the screen we | |
311 | ;; create here, so that its new value, gleaned from the user's | |
865fe16f | 312 | ;; init file, will be applied to the existing screen. |
de2f5dbe | 313 | (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist) |
0e1bfc78 | 314 | (assq 'minibuffer window-system-frame-alist) |
de2f5dbe GM |
315 | (assq 'minibuffer default-frame-alist) |
316 | '(minibuffer . t))) | |
317 | t)) | |
318 | ;; Create the new frame. | |
319 | (let (parms new) | |
320 | ;; If the frame isn't visible yet, wait till it is. | |
321 | ;; If the user has to position the window, | |
322 | ;; Emacs doesn't know its real position until | |
323 | ;; the frame is seen to be visible. | |
324 | (while (not (cdr (assq 'visibility | |
325 | (frame-parameters frame-initial-frame)))) | |
326 | (sleep-for 1)) | |
327 | (setq parms (frame-parameters frame-initial-frame)) | |
9688894d | 328 | |
f39784dd | 329 | ;; Get rid of `name' unless it was specified explicitly before. |
de2f5dbe GM |
330 | (or (assq 'name frame-initial-frame-alist) |
331 | (setq parms (delq (assq 'name parms) parms))) | |
2f5bb432 SM |
332 | ;; An explicit parent-id is a request to XEmbed the frame. |
333 | (or (assq 'parent-id frame-initial-frame-alist) | |
334 | (setq parms (delq (assq 'parent-id parms) parms))) | |
de2f5dbe GM |
335 | |
336 | (setq parms (append initial-frame-alist | |
0e1bfc78 | 337 | window-system-frame-alist |
de2f5dbe GM |
338 | default-frame-alist |
339 | parms | |
340 | nil)) | |
341 | ||
342 | ;; Get rid of `reverse', because that was handled | |
343 | ;; when we first made the frame. | |
344 | (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms))) | |
345 | ||
346 | (if (assq 'height frame-initial-geometry-arguments) | |
347 | (setq parms (assq-delete-all 'height parms))) | |
348 | (if (assq 'width frame-initial-geometry-arguments) | |
349 | (setq parms (assq-delete-all 'width parms))) | |
350 | (if (assq 'left frame-initial-geometry-arguments) | |
351 | (setq parms (assq-delete-all 'left parms))) | |
352 | (if (assq 'top frame-initial-geometry-arguments) | |
353 | (setq parms (assq-delete-all 'top parms))) | |
354 | (setq new | |
355 | (make-frame | |
356 | ;; Use the geometry args that created the existing | |
357 | ;; frame, rather than the parms we get for it. | |
358 | (append frame-initial-geometry-arguments | |
359 | '((user-size . t) (user-position . t)) | |
360 | parms))) | |
361 | ;; The initial frame, which we are about to delete, may be | |
362 | ;; the only frame with a minibuffer. If it is, create a | |
363 | ;; new one. | |
364 | (or (delq frame-initial-frame (minibuffer-frame-list)) | |
365 | (make-initial-minibuffer-frame nil)) | |
366 | ||
367 | ;; If the initial frame is serving as a surrogate | |
368 | ;; minibuffer frame for any frames, we need to wean them | |
369 | ;; onto a new frame. The default-minibuffer-frame | |
370 | ;; variable must be handled similarly. | |
371 | (let ((users-of-initial | |
372 | (filtered-frame-list | |
b7de6024 SM |
373 | (lambda (frame) |
374 | (and (not (eq frame frame-initial-frame)) | |
375 | (eq (window-frame | |
376 | (minibuffer-window frame)) | |
377 | frame-initial-frame)))))) | |
378 | (if (or users-of-initial | |
de2f5dbe GM |
379 | (eq default-minibuffer-frame frame-initial-frame)) |
380 | ||
381 | ;; Choose an appropriate frame. Prefer frames which | |
382 | ;; are only minibuffers. | |
383 | (let* ((new-surrogate | |
384 | (car | |
385 | (or (filtered-frame-list | |
b7de6024 SM |
386 | (lambda (frame) |
387 | (eq (cdr (assq 'minibuffer | |
388 | (frame-parameters frame))) | |
389 | 'only))) | |
de2f5dbe GM |
390 | (minibuffer-frame-list)))) |
391 | (new-minibuffer (minibuffer-window new-surrogate))) | |
392 | ||
393 | (if (eq default-minibuffer-frame frame-initial-frame) | |
394 | (setq default-minibuffer-frame new-surrogate)) | |
395 | ||
396 | ;; Wean the frames using frame-initial-frame as | |
397 | ;; their minibuffer frame. | |
b7de6024 SM |
398 | (dolist (frame users-of-initial) |
399 | (modify-frame-parameters | |
400 | frame (list (cons 'minibuffer new-minibuffer))))))) | |
401 | ||
402 | ;; Redirect events enqueued at this frame to the new frame. | |
de2f5dbe GM |
403 | ;; Is this a good idea? |
404 | (redirect-frame-focus frame-initial-frame new) | |
405 | ||
406 | ;; Finally, get rid of the old frame. | |
407 | (delete-frame frame-initial-frame t)) | |
9688894d | 408 | |
9858f6c3 | 409 | ;; Otherwise, we don't need all that rigmarole; just apply |
9688894d GM |
410 | ;; the new parameters. |
411 | (let (newparms allparms tail) | |
412 | (setq allparms (append initial-frame-alist | |
0e1bfc78 | 413 | window-system-frame-alist |
9688894d GM |
414 | default-frame-alist nil)) |
415 | (if (assq 'height frame-initial-geometry-arguments) | |
416 | (setq allparms (assq-delete-all 'height allparms))) | |
417 | (if (assq 'width frame-initial-geometry-arguments) | |
418 | (setq allparms (assq-delete-all 'width allparms))) | |
419 | (if (assq 'left frame-initial-geometry-arguments) | |
420 | (setq allparms (assq-delete-all 'left allparms))) | |
421 | (if (assq 'top frame-initial-geometry-arguments) | |
422 | (setq allparms (assq-delete-all 'top allparms))) | |
423 | (setq tail allparms) | |
424 | ;; Find just the parms that have changed since we first | |
425 | ;; made this frame. Those are the ones actually set by | |
f39784dd | 426 | ;; the init file. For those parms whose values we already knew |
9688894d GM |
427 | ;; (such as those spec'd by command line options) |
428 | ;; it is undesirable to specify the parm again | |
f39784dd | 429 | ;; once the user has seen the frame and been able to alter it |
9688894d | 430 | ;; manually. |
0216b738 CY |
431 | (let (newval oldval) |
432 | (dolist (entry tail) | |
433 | (setq oldval (assq (car entry) frame-initial-frame-alist)) | |
434 | (setq newval (cdr (assq (car entry) allparms))) | |
9688894d GM |
435 | (or (and oldval (eq (cdr oldval) newval)) |
436 | (setq newparms | |
0216b738 | 437 | (cons (cons (car entry) newval) newparms))))) |
9688894d | 438 | (setq newparms (nreverse newparms)) |
0216b738 CY |
439 | |
440 | (let ((new-bg (assq 'background-color newparms))) | |
441 | ;; If the `background-color' parameter is changed, apply | |
442 | ;; it first, then make sure that the `background-mode' | |
443 | ;; parameter and other faces are updated, before applying | |
444 | ;; the other parameters. | |
445 | (when new-bg | |
446 | (modify-frame-parameters frame-initial-frame | |
447 | (list new-bg)) | |
448 | (unless (assq 'background-mode newparms) | |
449 | (frame-set-background-mode frame-initial-frame)) | |
450 | (face-set-after-frame-default frame-initial-frame) | |
451 | (setq newparms (delq new-bg newparms))) | |
452 | (modify-frame-parameters frame-initial-frame newparms))))) | |
64c669bc | 453 | |
7eadab74 JB |
454 | ;; Restore the original buffer. |
455 | (set-buffer old-buffer) | |
456 | ||
457 | ;; Make sure the initial frame can be GC'd if it is ever deleted. | |
d202f1f2 | 458 | ;; Make sure frame-notice-user-settings does nothing if called twice. |
8f2a992b | 459 | (setq frame-notice-user-settings nil) |
d202f1f2 | 460 | (setq frame-initial-frame nil))) |
64c669bc | 461 | |
746bd265 KH |
462 | (defun make-initial-minibuffer-frame (display) |
463 | (let ((parms (append minibuffer-frame-alist '((minibuffer . only))))) | |
464 | (if display | |
465 | (make-frame-on-display display parms) | |
466 | (make-frame parms)))) | |
467 | ||
7eadab74 | 468 | ;;;; Creation of additional frames, and other frame miscellanea |
dc6d9681 | 469 | |
63019bad | 470 | (defun modify-all-frames-parameters (alist) |
d398de43 | 471 | "Modify all current and future frames' parameters according to ALIST. |
63019bad | 472 | This changes `default-frame-alist' and possibly `initial-frame-alist'. |
095fe281 KL |
473 | Furthermore, this function removes all parameters in ALIST from |
474 | `window-system-default-frame-alist'. | |
63019bad | 475 | See help of `modify-frame-parameters' for more information." |
095fe281 KL |
476 | (dolist (frame (frame-list)) |
477 | (modify-frame-parameters frame alist)) | |
478 | ||
479 | (dolist (pair alist) ;; conses to add/replace | |
480 | ;; initial-frame-alist needs setting only when | |
481 | ;; frame-notice-user-settings is true. | |
482 | (and frame-notice-user-settings | |
483 | (setq initial-frame-alist | |
484 | (assq-delete-all (car pair) initial-frame-alist))) | |
485 | (setq default-frame-alist | |
486 | (assq-delete-all (car pair) default-frame-alist)) | |
487 | ;; Remove any similar settings from the window-system specific | |
488 | ;; parameters---they would override default-frame-alist. | |
489 | (dolist (w window-system-default-frame-alist) | |
490 | (setcdr w (assq-delete-all (car pair) (cdr w))))) | |
491 | ||
63019bad JB |
492 | (and frame-notice-user-settings |
493 | (setq initial-frame-alist (append initial-frame-alist alist))) | |
494 | (setq default-frame-alist (append default-frame-alist alist))) | |
495 | ||
7253d8e0 | 496 | (defun get-other-frame () |
40d34803 DL |
497 | "Return some frame other than the current frame. |
498 | Create one if necessary. Note that the minibuffer frame, if separate, | |
499 | is not considered (see `next-frame')." | |
dc6d9681 | 500 | (let ((s (if (equal (next-frame (selected-frame)) (selected-frame)) |
6eb018ba | 501 | (make-frame) |
dc6d9681 | 502 | (next-frame (selected-frame))))) |
64c669bc JB |
503 | s)) |
504 | ||
dc6d9681 JB |
505 | (defun next-multiframe-window () |
506 | "Select the next window, regardless of which frame it is on." | |
64c669bc JB |
507 | (interactive) |
508 | (select-window (next-window (selected-window) | |
509 | (> (minibuffer-depth) 0) | |
bb2c34b1 | 510 | 0)) |
030f4537 | 511 | (select-frame-set-input-focus (selected-frame))) |
64c669bc | 512 | |
dc6d9681 JB |
513 | (defun previous-multiframe-window () |
514 | "Select the previous window, regardless of which frame it is on." | |
64c669bc JB |
515 | (interactive) |
516 | (select-window (previous-window (selected-window) | |
517 | (> (minibuffer-depth) 0) | |
bb2c34b1 | 518 | 0)) |
030f4537 | 519 | (select-frame-set-input-focus (selected-frame))) |
64c669bc | 520 | |
efc3dd3c DC |
521 | (defun window-system-for-display (display) |
522 | "Return the window system for DISPLAY. | |
523 | Return nil if we don't know how to interpret DISPLAY." | |
524 | (cl-loop for descriptor in display-format-alist | |
525 | for pattern = (car descriptor) | |
526 | for system = (cdr descriptor) | |
527 | when (string-match-p pattern display) return system)) | |
bbf6ef44 | 528 | |
6d73e337 | 529 | (defun make-frame-on-display (display &optional parameters) |
c5a8bc01 CY |
530 | "Make a frame on display DISPLAY. |
531 | The optional argument PARAMETERS specifies additional frame parameters." | |
6d73e337 | 532 | (interactive "sMake frame on display: ") |
efc3dd3c | 533 | (make-frame (cons (cons 'display display) parameters))) |
6d73e337 | 534 | |
aa360da1 GM |
535 | (declare-function x-close-connection "xfns.c" (terminal)) |
536 | ||
b7de6024 SM |
537 | (defun close-display-connection (display) |
538 | "Close the connection to a display, deleting all its associated frames. | |
539 | For DISPLAY, specify either a frame or a display name (a string). | |
540 | If DISPLAY is nil, that stands for the selected frame's display." | |
541 | (interactive | |
542 | (list | |
543 | (let* ((default (frame-parameter nil 'display)) | |
544 | (display (completing-read | |
545 | (format "Close display (default %s): " default) | |
546 | (delete-dups | |
547 | (mapcar (lambda (frame) | |
548 | (frame-parameter frame 'display)) | |
549 | (frame-list))) | |
550 | nil t nil nil | |
551 | default))) | |
552 | (if (zerop (length display)) default display)))) | |
553 | (let ((frames (delq nil | |
554 | (mapcar (lambda (frame) | |
555 | (if (equal display | |
556 | (frame-parameter frame 'display)) | |
557 | frame)) | |
558 | (frame-list))))) | |
559 | (if (and (consp frames) | |
560 | (not (y-or-n-p (if (cdr frames) | |
561 | (format "Delete %s frames? " (length frames)) | |
562 | (format "Delete %s ? " (car frames)))))) | |
563 | (error "Abort!") | |
564 | (mapc 'delete-frame frames) | |
565 | (x-close-connection display)))) | |
566 | ||
6238bfaf | 567 | (defun make-frame-command () |
e9e6aee8 CY |
568 | "Make a new frame, on the same terminal as the selected frame. |
569 | If the terminal is a text-only terminal, this also selects the | |
570 | new frame." | |
6238bfaf | 571 | (interactive) |
e9e6aee8 | 572 | (if (display-graphic-p) |
6238bfaf RS |
573 | (make-frame) |
574 | (select-frame (make-frame)))) | |
575 | ||
45c4fdeb SM |
576 | (defvar before-make-frame-hook nil |
577 | "Functions to run before a frame is created.") | |
578 | ||
579 | (defvar after-make-frame-functions nil | |
580 | "Functions to run after a frame is created. | |
581 | The functions are run with one arg, the newly created frame.") | |
582 | ||
72bf1a8b | 583 | (defvar after-setting-font-hook nil |
81b99826 GM |
584 | "Functions to run after a frame's font has been changed.") |
585 | ||
92e443b1 | 586 | ;; Alias, kept temporarily. |
84ed1560 | 587 | (define-obsolete-function-alias 'new-frame 'make-frame "22.1") |
bc93c097 | 588 | |
9e483377 | 589 | (defvar frame-inherited-parameters '() |
ab6198b2 SM |
590 | ;; FIXME: Shouldn't we add `font' here as well? |
591 | "Parameters `make-frame' copies from the `selected-frame' to the new frame.") | |
592 | ||
45c4fdeb SM |
593 | (defun make-frame (&optional parameters) |
594 | "Return a newly created frame displaying the current buffer. | |
c1ef4455 CY |
595 | Optional argument PARAMETERS is an alist of frame parameters for |
596 | the new frame. Each element of PARAMETERS should have the | |
597 | form (NAME . VALUE), for example: | |
a105105a | 598 | |
45c4fdeb | 599 | (name . STRING) The frame should be named STRING. |
43a2e52c | 600 | |
45c4fdeb SM |
601 | (width . NUMBER) The frame should be NUMBER characters in width. |
602 | (height . NUMBER) The frame should be NUMBER text lines high. | |
43a2e52c | 603 | |
c1ef4455 CY |
604 | You cannot specify either `width' or `height', you must specify |
605 | neither or both. | |
43a2e52c | 606 | |
45c4fdeb SM |
607 | (minibuffer . t) The frame should have a minibuffer. |
608 | (minibuffer . nil) The frame should have no minibuffer. | |
609 | (minibuffer . only) The frame should contain only a minibuffer. | |
610 | (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window. | |
43a2e52c | 611 | |
2246281f KL |
612 | (window-system . nil) The frame should be displayed on a terminal device. |
613 | (window-system . x) The frame should be displayed in an X window. | |
614 | ||
efc3dd3c DC |
615 | (display . \":0\") The frame should appear on display :0. |
616 | ||
d51f6378 | 617 | (terminal . TERMINAL) The frame should use the terminal object TERMINAL. |
b6660415 | 618 | |
c1ef4455 CY |
619 | In addition, any parameter specified in `default-frame-alist', |
620 | but not present in PARAMETERS, is applied. | |
8de9d3f6 | 621 | |
c1ef4455 CY |
622 | Before creating the frame (via `frame-creation-function-alist'), |
623 | this function runs the hook `before-make-frame-hook'. After | |
624 | creating the frame, it runs the hook `after-make-frame-functions' | |
625 | with one arg, the newly created frame. | |
626 | ||
efc3dd3c DC |
627 | If a display parameter is supplied and a window-system is not, |
628 | guess the window-system from the display. | |
629 | ||
c1ef4455 CY |
630 | On graphical displays, this function does not itself make the new |
631 | frame the selected frame. However, the window system may select | |
632 | the new frame according to its own rules." | |
64c669bc | 633 | (interactive) |
efc3dd3c DC |
634 | (let* ((display (cdr (assq 'display parameters))) |
635 | (w (cond | |
6ed8eeff KL |
636 | ((assq 'terminal parameters) |
637 | (let ((type (terminal-live-p (cdr (assq 'terminal parameters))))) | |
b6660415 KL |
638 | (cond |
639 | ((eq type t) nil) | |
cb01ce3f SM |
640 | ((eq type nil) (error "Terminal %s does not exist" |
641 | (cdr (assq 'terminal parameters)))) | |
b6660415 KL |
642 | (t type)))) |
643 | ((assq 'window-system parameters) | |
644 | (cdr (assq 'window-system parameters))) | |
efc3dd3c DC |
645 | (display |
646 | (or (window-system-for-display display) | |
647 | (error "Don't know how to interpret display \"%S\"" | |
648 | display))) | |
b6660415 | 649 | (t window-system))) |
2246281f | 650 | (frame-creation-function (cdr (assq w frame-creation-function-alist))) |
da8e8fc1 | 651 | (oldframe (selected-frame)) |
c1ef4455 | 652 | (params parameters) |
2246281f KL |
653 | frame) |
654 | (unless frame-creation-function | |
655 | (error "Don't know how to create a frame on window system %s" w)) | |
efc3dd3c DC |
656 | |
657 | (unless (get w 'window-system-initialized) | |
1a6e7e38 DC |
658 | (unless x-display-name |
659 | (setq x-display-name display)) | |
efc3dd3c DC |
660 | (funcall (cdr (assq w window-system-initialization-alist))) |
661 | (put w 'window-system-initialized t)) | |
662 | ||
c1ef4455 CY |
663 | ;; Add parameters from `window-system-default-frame-alist'. |
664 | (dolist (p (cdr (assq w window-system-default-frame-alist))) | |
21bd02a6 | 665 | (unless (assq (car p) params) |
c1ef4455 CY |
666 | (push p params))) |
667 | ;; Add parameters from `default-frame-alist'. | |
668 | (dolist (p default-frame-alist) | |
21bd02a6 | 669 | (unless (assq (car p) params) |
c1ef4455 CY |
670 | (push p params))) |
671 | ;; Now make the frame. | |
2246281f | 672 | (run-hooks 'before-make-frame-hook) |
c1ef4455 | 673 | (setq frame (funcall frame-creation-function params)) |
30a2fded | 674 | (normal-erase-is-backspace-setup-frame frame) |
ab6198b2 SM |
675 | ;; Inherit the original frame's parameters. |
676 | (dolist (param frame-inherited-parameters) | |
677 | (unless (assq param parameters) ;Overridden by explicit parameters. | |
678 | (let ((val (frame-parameter oldframe param))) | |
679 | (when val (set-frame-parameter frame param val))))) | |
45c4fdeb SM |
680 | (run-hook-with-args 'after-make-frame-functions frame) |
681 | frame)) | |
64c669bc | 682 | |
7eadab74 JB |
683 | (defun filtered-frame-list (predicate) |
684 | "Return a list of all live frames which satisfy PREDICATE." | |
047bc928 GM |
685 | (let* ((frames (frame-list)) |
686 | (list frames)) | |
7eadab74 | 687 | (while (consp frames) |
047bc928 GM |
688 | (unless (funcall predicate (car frames)) |
689 | (setcar frames nil)) | |
7eadab74 | 690 | (setq frames (cdr frames))) |
047bc928 | 691 | (delq nil list))) |
7eadab74 JB |
692 | |
693 | (defun minibuffer-frame-list () | |
694 | "Return a list of all frames with their own minibuffers." | |
695 | (filtered-frame-list | |
b7de6024 SM |
696 | (lambda (frame) |
697 | (eq frame (window-frame (minibuffer-window frame)))))) | |
7eadab74 | 698 | |
371fed4e SM |
699 | ;; Used to be called `terminal-id' in termdev.el. |
700 | (defun get-device-terminal (device) | |
701 | "Return the terminal corresponding to DEVICE. | |
702 | DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal), | |
703 | the name of an X display device (HOST.SERVER.SCREEN) or a tty device file." | |
704 | (cond | |
705 | ((or (null device) (framep device)) | |
706 | (frame-terminal device)) | |
707 | ((stringp device) | |
708 | (let ((f (car (filtered-frame-list | |
709 | (lambda (frame) | |
710 | (or (equal (frame-parameter frame 'display) device) | |
711 | (equal (frame-parameter frame 'tty) device))))))) | |
712 | (or f (error "Display %s does not exist" device)) | |
713 | (frame-terminal f))) | |
714 | ((terminal-live-p device) device) | |
715 | (t | |
716 | (error "Invalid argument %s in `get-device-terminal'" device)))) | |
717 | ||
718 | (defun frames-on-display-list (&optional device) | |
719 | "Return a list of all frames on DEVICE. | |
720 | ||
721 | DEVICE should be a terminal, a frame, | |
722 | or a name of an X display or tty (a string of the form | |
9684e4c9 | 723 | HOST:SERVER.SCREEN). |
b6660415 | 724 | |
371fed4e | 725 | If DEVICE is omitted or nil, it defaults to the selected |
9684e4c9 | 726 | frame's terminal device." |
371fed4e | 727 | (let* ((terminal (get-device-terminal device)) |
047bc928 | 728 | (func #'(lambda (frame) |
6ed8eeff | 729 | (eq (frame-terminal frame) terminal)))) |
9911648b EZ |
730 | (filtered-frame-list func))) |
731 | ||
f35ca2fe KL |
732 | (defun framep-on-display (&optional terminal) |
733 | "Return the type of frames on TERMINAL. | |
734 | TERMINAL may be a terminal id, a display name or a frame. If it | |
735 | is a frame, its type is returned. If TERMINAL is omitted or nil, | |
736 | it defaults to the selected frame's terminal device. All frames | |
737 | on a given display are of the same type." | |
6ed8eeff | 738 | (or (terminal-live-p terminal) |
f35ca2fe KL |
739 | (framep terminal) |
740 | (framep (car (frames-on-display-list terminal))))) | |
9911648b | 741 | |
58bf6042 JB |
742 | (defun frame-remove-geometry-params (param-list) |
743 | "Return the parameter list PARAM-LIST, but with geometry specs removed. | |
744 | This deletes all bindings in PARAM-LIST for `top', `left', `width', | |
791e09d8 | 745 | `height', `user-size' and `user-position' parameters. |
58bf6042 JB |
746 | Emacs uses this to avoid overriding explicit moves and resizings from |
747 | the user during startup." | |
748 | (setq param-list (cons nil param-list)) | |
749 | (let ((tail param-list)) | |
750 | (while (consp (cdr tail)) | |
751 | (if (and (consp (car (cdr tail))) | |
791e09d8 RS |
752 | (memq (car (car (cdr tail))) |
753 | '(height width top left user-position user-size))) | |
754 | (progn | |
755 | (setq frame-initial-geometry-arguments | |
756 | (cons (car (cdr tail)) frame-initial-geometry-arguments)) | |
757 | (setcdr tail (cdr (cdr tail)))) | |
58bf6042 | 758 | (setq tail (cdr tail))))) |
e11c3dc2 KH |
759 | (setq frame-initial-geometry-arguments |
760 | (nreverse frame-initial-geometry-arguments)) | |
58bf6042 JB |
761 | (cdr param-list)) |
762 | ||
aa360da1 GM |
763 | (declare-function x-focus-frame "xfns.c" (frame)) |
764 | ||
be39b8cc | 765 | (defun select-frame-set-input-focus (frame &optional norecord) |
bbca16d8 | 766 | "Select FRAME, raise it, and set input focus, if possible. |
e343066f | 767 | If `mouse-autoselect-window' is non-nil, also move mouse pointer |
bbca16d8 | 768 | to FRAME's selected window. Otherwise, if `focus-follows-mouse' |
be39b8cc MR |
769 | is non-nil, move mouse cursor to FRAME. |
770 | ||
771 | Optional argument NORECORD means to neither change the order of | |
772 | recently selected windows nor the buffer list." | |
773 | (select-frame frame norecord) | |
b0c7121c | 774 | (raise-frame frame) |
bbca16d8 | 775 | ;; Ensure, if possible, that FRAME gets input focus. |
b0c7121c MR |
776 | (when (memq (window-system frame) '(x w32 ns)) |
777 | (x-focus-frame frame)) | |
bbca16d8 MR |
778 | ;; Move mouse cursor if necessary. |
779 | (cond | |
780 | (mouse-autoselect-window | |
781 | (let ((edges (window-inside-edges (frame-selected-window frame)))) | |
782 | ;; Move mouse cursor into FRAME's selected window to avoid that | |
783 | ;; Emacs mouse-autoselects another window. | |
784 | (set-mouse-position frame (nth 2 edges) (nth 1 edges)))) | |
785 | (focus-follows-mouse | |
786 | ;; Move mouse cursor into FRAME to avoid that another frame gets | |
787 | ;; selected by the window manager. | |
788 | (set-mouse-position frame (1- (frame-width frame)) 0)))) | |
030f4537 | 789 | |
ceab6935 | 790 | (defun other-frame (arg) |
c2c93894 | 791 | "Select the ARGth different visible frame on current display, and raise it. |
ceab6935 RM |
792 | All frames are arranged in a cyclic order. |
793 | This command selects the frame ARG steps away in that order. | |
bb578a72 RS |
794 | A negative ARG moves in the opposite order. |
795 | ||
796 | To make this command work properly, you must tell Emacs | |
797 | how the system (or the window manager) generally handles | |
798 | focus-switching between windows. If moving the mouse onto a window | |
799 | selects it (gives it focus), set `focus-follows-mouse' to t. | |
800 | Otherwise, that variable should be nil." | |
ceab6935 RM |
801 | (interactive "p") |
802 | (let ((frame (selected-frame))) | |
803 | (while (> arg 0) | |
a569dbc3 RM |
804 | (setq frame (next-frame frame)) |
805 | (while (not (eq (frame-visible-p frame) t)) | |
806 | (setq frame (next-frame frame))) | |
807 | (setq arg (1- arg))) | |
ceab6935 | 808 | (while (< arg 0) |
a569dbc3 RM |
809 | (setq frame (previous-frame frame)) |
810 | (while (not (eq (frame-visible-p frame) t)) | |
811 | (setq frame (previous-frame frame))) | |
915cfd1f | 812 | (setq arg (1+ arg))) |
030f4537 | 813 | (select-frame-set-input-focus frame))) |
845cde06 | 814 | |
3db7df06 SM |
815 | (defun iconify-or-deiconify-frame () |
816 | "Iconify the selected frame, or deiconify if it's currently an icon." | |
817 | (interactive) | |
818 | (if (eq (cdr (assq 'visibility (frame-parameters))) t) | |
819 | (iconify-frame) | |
820 | (make-frame-visible))) | |
821 | ||
0b0d3e0b KL |
822 | (defun suspend-frame () |
823 | "Do whatever is right to suspend the current frame. | |
f35ca2fe KL |
824 | Calls `suspend-emacs' if invoked from the controlling tty device, |
825 | `suspend-tty' from a secondary tty device, and | |
0b0d3e0b KL |
826 | `iconify-or-deiconify-frame' from an X frame." |
827 | (interactive) | |
828 | (let ((type (framep (selected-frame)))) | |
829 | (cond | |
edfda783 | 830 | ((memq type '(x ns w32)) (iconify-or-deiconify-frame)) |
0b0d3e0b | 831 | ((eq type t) |
6ed8eeff | 832 | (if (controlling-tty-p) |
4a933ef8 KL |
833 | (suspend-emacs) |
834 | (suspend-tty))) | |
0b0d3e0b KL |
835 | (t (suspend-emacs))))) |
836 | ||
845cde06 | 837 | (defun make-frame-names-alist () |
e2c3f530 | 838 | ;; Only consider the frames on the same display. |
845cde06 EZ |
839 | (let* ((current-frame (selected-frame)) |
840 | (falist | |
841 | (cons | |
842 | (cons (frame-parameter current-frame 'name) current-frame) nil)) | |
e2c3f530 | 843 | (frame (next-frame nil 0))) |
845cde06 EZ |
844 | (while (not (eq frame current-frame)) |
845 | (progn | |
e2c3f530 SM |
846 | (push (cons (frame-parameter frame 'name) frame) falist) |
847 | (setq frame (next-frame frame 0)))) | |
845cde06 EZ |
848 | falist)) |
849 | ||
850 | (defvar frame-name-history nil) | |
845cde06 | 851 | (defun select-frame-by-name (name) |
563283b1 | 852 | "Select the frame on the current terminal whose name is NAME and raise it. |
845cde06 EZ |
853 | If there is no frame by that name, signal an error." |
854 | (interactive | |
716ff1c9 RS |
855 | (let* ((frame-names-alist (make-frame-names-alist)) |
856 | (default (car (car frame-names-alist))) | |
857 | (input (completing-read | |
858 | (format "Select Frame (default %s): " default) | |
859 | frame-names-alist nil t nil 'frame-name-history))) | |
845cde06 EZ |
860 | (if (= (length input) 0) |
861 | (list default) | |
862 | (list input)))) | |
716ff1c9 RS |
863 | (let* ((frame-names-alist (make-frame-names-alist)) |
864 | (frame (cdr (assoc name frame-names-alist)))) | |
bbca16d8 MR |
865 | (if frame |
866 | (select-frame-set-input-focus frame) | |
867 | (error "There is no frame named `%s'" name)))) | |
1485f4c0 CY |
868 | |
869 | \f | |
870 | ;;;; Background mode. | |
871 | ||
872 | (defcustom frame-background-mode nil | |
873 | "The brightness of the background. | |
874 | Set this to the symbol `dark' if your background color is dark, | |
875 | `light' if your background is light, or nil (automatic by default) | |
876 | if you want Emacs to examine the brightness for you. Don't set this | |
877 | variable with `setq'; this won't have the expected effect." | |
878 | :group 'faces | |
879 | :set #'(lambda (var value) | |
880 | (set-default var value) | |
881 | (mapc 'frame-set-background-mode (frame-list))) | |
882 | :initialize 'custom-initialize-changed | |
883 | :type '(choice (const dark) | |
884 | (const light) | |
885 | (const :tag "automatic" nil))) | |
886 | ||
887 | (declare-function x-get-resource "frame.c" | |
888 | (attribute class &optional component subclass)) | |
889 | ||
890 | (defvar inhibit-frame-set-background-mode nil) | |
891 | ||
892 | (defun frame-set-background-mode (frame &optional keep-face-specs) | |
893 | "Set up display-dependent faces on FRAME. | |
894 | Display-dependent faces are those which have different definitions | |
895 | according to the `background-mode' and `display-type' frame parameters. | |
896 | ||
897 | If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate | |
898 | face specs for the new background mode." | |
899 | (unless inhibit-frame-set-background-mode | |
900 | (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame)) | |
901 | (bg-color (frame-parameter frame 'background-color)) | |
902 | (tty-type (tty-type frame)) | |
903 | (default-bg-mode | |
904 | (if (or (window-system frame) | |
905 | (and tty-type | |
906 | (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)" | |
907 | tty-type))) | |
908 | 'light | |
909 | 'dark)) | |
910 | (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light)) | |
911 | (bg-mode | |
912 | (cond (frame-default-bg-mode) | |
913 | ((equal bg-color "unspecified-fg") ; inverted colors | |
914 | non-default-bg-mode) | |
915 | ((not (color-values bg-color frame)) | |
916 | default-bg-mode) | |
917 | ((>= (apply '+ (color-values bg-color frame)) | |
918 | ;; Just looking at the screen, colors whose | |
919 | ;; values add up to .6 of the white total | |
920 | ;; still look dark to me. | |
921 | (* (apply '+ (color-values "white" frame)) .6)) | |
922 | 'light) | |
923 | (t 'dark))) | |
924 | (display-type | |
925 | (cond ((null (window-system frame)) | |
926 | (if (tty-display-color-p frame) 'color 'mono)) | |
927 | ((display-color-p frame) | |
928 | 'color) | |
929 | ((x-display-grayscale-p frame) | |
930 | 'grayscale) | |
931 | (t 'mono))) | |
932 | (old-bg-mode | |
933 | (frame-parameter frame 'background-mode)) | |
934 | (old-display-type | |
935 | (frame-parameter frame 'display-type))) | |
936 | ||
937 | (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type)) | |
938 | (let ((locally-modified-faces nil) | |
939 | ;; Prevent face-spec-recalc from calling this function | |
940 | ;; again, resulting in a loop (bug#911). | |
941 | (inhibit-frame-set-background-mode t) | |
942 | (params (list (cons 'background-mode bg-mode) | |
943 | (cons 'display-type display-type)))) | |
944 | (if keep-face-specs | |
945 | (modify-frame-parameters frame params) | |
946 | ;; If we are recomputing face specs, first collect a list | |
947 | ;; of faces that don't match their face-specs. These are | |
948 | ;; the faces modified on FRAME, and we avoid changing them | |
949 | ;; below. Use a negative list to avoid consing (we assume | |
950 | ;; most faces are unmodified). | |
951 | (dolist (face (face-list)) | |
952 | (and (not (get face 'face-override-spec)) | |
953 | (not (face-spec-match-p face | |
954 | (face-user-default-spec face) | |
955 | (selected-frame))) | |
956 | (push face locally-modified-faces))) | |
957 | ;; Now change to the new frame parameters | |
958 | (modify-frame-parameters frame params) | |
959 | ;; For all unmodified named faces, choose face specs | |
960 | ;; matching the new frame parameters. | |
961 | (dolist (face (face-list)) | |
962 | (unless (memq face locally-modified-faces) | |
963 | (face-spec-recalc face frame))))))))) | |
964 | ||
965 | (defun frame-terminal-default-bg-mode (frame) | |
966 | "Return the default background mode of FRAME. | |
967 | This checks the `frame-background-mode' variable, the X resource | |
968 | named \"backgroundMode\" (if FRAME is an X frame), and finally | |
969 | the `background-mode' terminal parameter." | |
970 | (or frame-background-mode | |
971 | (let ((bg-resource | |
972 | (and (window-system frame) | |
973 | (x-get-resource "backgroundMode" "BackgroundMode")))) | |
974 | (if bg-resource | |
975 | (intern (downcase bg-resource)))) | |
976 | (terminal-parameter frame 'background-mode))) | |
977 | ||
64c669bc | 978 | \f |
dc6d9681 JB |
979 | ;;;; Frame configurations |
980 | ||
981 | (defun current-frame-configuration () | |
982 | "Return a list describing the positions and states of all frames. | |
376a7584 JB |
983 | Its car is `frame-configuration'. |
984 | Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG), | |
985 | where | |
986 | FRAME is a frame object, | |
987 | ALIST is an association list specifying some of FRAME's parameters, and | |
988 | WINDOW-CONFIG is a window configuration object for FRAME." | |
989 | (cons 'frame-configuration | |
b7de6024 SM |
990 | (mapcar (lambda (frame) |
991 | (list frame | |
992 | (frame-parameters frame) | |
993 | (current-window-configuration frame))) | |
376a7584 | 994 | (frame-list)))) |
dc6d9681 | 995 | |
68cd265f | 996 | (defun set-frame-configuration (configuration &optional nodelete) |
dc6d9681 JB |
997 | "Restore the frames to the state described by CONFIGURATION. |
998 | Each frame listed in CONFIGURATION has its position, size, window | |
68cd265f | 999 | configuration, and other parameters set as specified in CONFIGURATION. |
d398de43 LT |
1000 | However, this function does not restore deleted frames. |
1001 | ||
a78db71c RS |
1002 | Ordinarily, this function deletes all existing frames not |
1003 | listed in CONFIGURATION. But if optional second argument NODELETE | |
5da841d2 | 1004 | is given and non-nil, the unwanted frames are iconified instead." |
376a7584 JB |
1005 | (or (frame-configuration-p configuration) |
1006 | (signal 'wrong-type-argument | |
1007 | (list 'frame-configuration-p configuration))) | |
1008 | (let ((config-alist (cdr configuration)) | |
1009 | frames-to-delete) | |
b7de6024 SM |
1010 | (dolist (frame (frame-list)) |
1011 | (let ((parameters (assq frame config-alist))) | |
1012 | (if parameters | |
1013 | (progn | |
1014 | (modify-frame-parameters | |
1015 | frame | |
1016 | ;; Since we can't set a frame's minibuffer status, | |
1017 | ;; we might as well omit the parameter altogether. | |
1018 | (let* ((parms (nth 1 parameters)) | |
b2529d56 MB |
1019 | (mini (assq 'minibuffer parms)) |
1020 | (name (assq 'name parms)) | |
1021 | (explicit-name (cdr (assq 'explicit-name parms)))) | |
1022 | (when mini (setq parms (delq mini parms))) | |
1023 | ;; Leave name in iff it was set explicitly. | |
1024 | ;; This should fix the behavior reported in | |
1025 | ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html | |
1026 | (when (and name (not explicit-name)) | |
1027 | (setq parms (delq name parms))) | |
b7de6024 SM |
1028 | parms)) |
1029 | (set-window-configuration (nth 2 parameters))) | |
1030 | (setq frames-to-delete (cons frame frames-to-delete))))) | |
1031 | (mapc (if nodelete | |
1032 | ;; Note: making frames invisible here was tried | |
1033 | ;; but led to some strange behavior--each time the frame | |
1034 | ;; was made visible again, the window manager asked afresh | |
1035 | ;; for where to put it. | |
1036 | 'iconify-frame | |
1037 | 'delete-frame) | |
1038 | frames-to-delete))) | |
64c669bc | 1039 | \f |
dc6d9681 JB |
1040 | ;;;; Convenience functions for accessing and interactively changing |
1041 | ;;;; frame parameters. | |
64c669bc | 1042 | |
151bdc83 | 1043 | (defun frame-height (&optional frame) |
dc6d9681 | 1044 | "Return number of lines available for display on FRAME. |
4619ff5e GM |
1045 | If FRAME is omitted, describe the currently selected frame. |
1046 | Exactly what is included in the return value depends on the | |
1047 | window-system and toolkit in use - see `frame-pixel-height' for | |
1048 | more details. The lines are in units of the default font height. | |
1049 | ||
1050 | The result is roughly related to the frame pixel height via | |
1051 | height in pixels = height in lines * `frame-char-height'. | |
1052 | However, this is only approximate, and is complicated e.g. by the | |
1053 | fact that individual window lines and menu bar lines can have | |
1054 | differing font heights." | |
151bdc83 | 1055 | (cdr (assq 'height (frame-parameters frame)))) |
dc6d9681 JB |
1056 | |
1057 | (defun frame-width (&optional frame) | |
1058 | "Return number of columns available for display on FRAME. | |
1059 | If FRAME is omitted, describe the currently selected frame." | |
151bdc83 | 1060 | (cdr (assq 'width (frame-parameters frame)))) |
dc6d9681 | 1061 | |
aa360da1 GM |
1062 | (declare-function x-list-fonts "xfaces.c" |
1063 | (pattern &optional face frame maximum width)) | |
1064 | ||
52ef9375 | 1065 | (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1") |
fce3fdeb | 1066 | |
f2045622 CY |
1067 | (defun set-frame-font (font &optional keep-size frames) |
1068 | "Set the default font to FONT. | |
fce3fdeb | 1069 | When called interactively, prompt for the name of a font, and use |
f2045622 CY |
1070 | that font on the selected frame. When called from Lisp, FONT |
1071 | should be a font name (a string), a font object, font entity, or | |
1072 | font spec. | |
fce3fdeb CY |
1073 | |
1074 | If KEEP-SIZE is nil, keep the number of frame lines and columns | |
1075 | fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try | |
1076 | to keep the current frame size fixed (in pixels) by adjusting the | |
1077 | number of lines and columns. | |
1078 | ||
9f562668 CY |
1079 | If FRAMES is nil, apply the font to the selected frame only. |
1080 | If FRAMES is non-nil, it should be a list of frames to act upon, | |
1081 | or t meaning all graphical frames. Also, if FRAME is non-nil, | |
1082 | alter the user's Customization settings as though the | |
fce3fdeb CY |
1083 | font-related attributes of the `default' face had been \"set in |
1084 | this session\", so that the font is applied to future frames." | |
f39784dd | 1085 | (interactive |
1cef6541 JB |
1086 | (let* ((completion-ignore-case t) |
1087 | (font (completing-read "Font name: " | |
1cef6541 JB |
1088 | ;; x-list-fonts will fail with an error |
1089 | ;; if this frame doesn't support fonts. | |
b7de6024 SM |
1090 | (x-list-fonts "*" nil (selected-frame)) |
1091 | nil nil nil nil | |
1092 | (frame-parameter nil 'font)))) | |
fce3fdeb | 1093 | (list font current-prefix-arg nil))) |
f2045622 | 1094 | (when (or (stringp font) (fontp font)) |
fce3fdeb | 1095 | (let* ((this-frame (selected-frame)) |
9f562668 CY |
1096 | ;; FRAMES nil means affect the selected frame. |
1097 | (frame-list (cond ((null frames) | |
1098 | (list this-frame)) | |
1099 | ((eq frames t) | |
1100 | (frame-list)) | |
1101 | (t frames))) | |
fce3fdeb | 1102 | height width) |
9f562668 | 1103 | (dolist (f frame-list) |
fce3fdeb CY |
1104 | (when (display-multi-font-p f) |
1105 | (if keep-size | |
1106 | (setq height (* (frame-parameter f 'height) | |
1107 | (frame-char-height f)) | |
1108 | width (* (frame-parameter f 'width) | |
1109 | (frame-char-width f)))) | |
1110 | ;; When set-face-attribute is called for :font, Emacs | |
1111 | ;; guesses the best font according to other face attributes | |
1112 | ;; (:width, :weight, etc.) so reset them too (Bug#2476). | |
1113 | (set-face-attribute 'default f | |
1114 | :width 'normal :weight 'normal | |
f2045622 | 1115 | :slant 'normal :font font) |
fce3fdeb CY |
1116 | (if keep-size |
1117 | (modify-frame-parameters | |
1118 | f | |
1119 | (list (cons 'height (round height (frame-char-height f))) | |
1120 | (cons 'width (round width (frame-char-width f)))))))) | |
9f562668 | 1121 | (when frames |
fce3fdeb CY |
1122 | ;; Alter the user's Custom setting of the `default' face, but |
1123 | ;; only for font-related attributes. | |
1124 | (let ((specs (cadr (assq 'user (get 'default 'theme-face)))) | |
1125 | (attrs '(:family :foundry :slant :weight :height :width)) | |
1126 | (new-specs nil)) | |
1127 | (if (null specs) (setq specs '((t nil)))) | |
1128 | (dolist (spec specs) | |
1129 | ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST) | |
1130 | (let ((display (nth 0 spec)) | |
1131 | (plist (copy-tree (nth 1 spec)))) | |
1132 | ;; Alter only DISPLAY conditions matching this frame. | |
1133 | (when (or (memq display '(t default)) | |
1134 | (face-spec-set-match-display display this-frame)) | |
1135 | (dolist (attr attrs) | |
1136 | (setq plist (plist-put plist attr | |
1137 | (face-attribute 'default attr))))) | |
1138 | (push (list display plist) new-specs))) | |
1139 | (setq new-specs (nreverse new-specs)) | |
1140 | (put 'default 'customized-face new-specs) | |
1141 | (custom-push-theme 'theme-face 'default 'user 'set new-specs) | |
1142 | (put 'default 'face-modified nil)))) | |
1143 | (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))) | |
64c669bc | 1144 | |
7e573c4a | 1145 | (defun set-frame-parameter (frame parameter value) |
0dac35b8 KL |
1146 | "Set frame parameter PARAMETER to VALUE on FRAME. |
1147 | If FRAME is nil, it defaults to the selected frame. | |
c2c93894 | 1148 | See `modify-frame-parameters'." |
7e573c4a SM |
1149 | (modify-frame-parameters frame (list (cons parameter value)))) |
1150 | ||
8290babd | 1151 | (defun set-background-color (color-name) |
40d34803 | 1152 | "Set the background color of the selected frame to COLOR-NAME. |
61298010 RS |
1153 | When called interactively, prompt for the name of the color to use. |
1154 | To get the frame's current background color, use `frame-parameters'." | |
9317e499 | 1155 | (interactive (list (read-color "Background color: "))) |
dc6d9681 | 1156 | (modify-frame-parameters (selected-frame) |
528e1416 EZ |
1157 | (list (cons 'background-color color-name))) |
1158 | (or window-system | |
1159 | (face-set-after-frame-default (selected-frame)))) | |
64c669bc | 1160 | |
8290babd | 1161 | (defun set-foreground-color (color-name) |
40d34803 | 1162 | "Set the foreground color of the selected frame to COLOR-NAME. |
61298010 RS |
1163 | When called interactively, prompt for the name of the color to use. |
1164 | To get the frame's current foreground color, use `frame-parameters'." | |
9317e499 | 1165 | (interactive (list (read-color "Foreground color: "))) |
dc6d9681 | 1166 | (modify-frame-parameters (selected-frame) |
528e1416 EZ |
1167 | (list (cons 'foreground-color color-name))) |
1168 | (or window-system | |
1169 | (face-set-after-frame-default (selected-frame)))) | |
64c669bc JB |
1170 | |
1171 | (defun set-cursor-color (color-name) | |
40d34803 | 1172 | "Set the text cursor color of the selected frame to COLOR-NAME. |
61298010 | 1173 | When called interactively, prompt for the name of the color to use. |
2680c309 CY |
1174 | This works by setting the `cursor-color' frame parameter on the |
1175 | selected frame. | |
1176 | ||
1177 | You can also set the text cursor color, for all frames, by | |
1178 | customizing the `cursor' face." | |
9317e499 | 1179 | (interactive (list (read-color "Cursor color: "))) |
dc6d9681 | 1180 | (modify-frame-parameters (selected-frame) |
7eadab74 | 1181 | (list (cons 'cursor-color color-name)))) |
64c669bc | 1182 | |
eaa974e1 | 1183 | (defun set-mouse-color (color-name) |
40d34803 | 1184 | "Set the color of the mouse pointer of the selected frame to COLOR-NAME. |
61298010 RS |
1185 | When called interactively, prompt for the name of the color to use. |
1186 | To get the frame's current mouse color, use `frame-parameters'." | |
9317e499 | 1187 | (interactive (list (read-color "Mouse color: "))) |
dc6d9681 | 1188 | (modify-frame-parameters (selected-frame) |
ec6d4463 KH |
1189 | (list (cons 'mouse-color |
1190 | (or color-name | |
1191 | (cdr (assq 'mouse-color | |
1192 | (frame-parameters)))))))) | |
7eadab74 | 1193 | |
eaa974e1 | 1194 | (defun set-border-color (color-name) |
40d34803 | 1195 | "Set the color of the border of the selected frame to COLOR-NAME. |
61298010 RS |
1196 | When called interactively, prompt for the name of the color to use. |
1197 | To get the frame's current border color, use `frame-parameters'." | |
9317e499 | 1198 | (interactive (list (read-color "Border color: "))) |
eaa974e1 JB |
1199 | (modify-frame-parameters (selected-frame) |
1200 | (list (cons 'border-color color-name)))) | |
1201 | ||
f44379e7 | 1202 | (define-minor-mode auto-raise-mode |
ed472be9 | 1203 | "Toggle whether or not selected frames should auto-raise. |
06e21633 CY |
1204 | With a prefix argument ARG, enable Auto Raise mode if ARG is |
1205 | positive, and disable it otherwise. If called from Lisp, enable | |
1206 | the mode if ARG is omitted or nil. | |
1207 | ||
ed472be9 CY |
1208 | Auto Raise mode does nothing under most window managers, which |
1209 | switch focus on mouse clicks. It only has an effect if your | |
1210 | window manager switches focus on mouse movement (in which case | |
1211 | you should also change `focus-follows-mouse' to t). Then, | |
1212 | enabling Auto Raise mode causes any graphical Emacs frame which | |
1213 | acquires focus to be automatically raised. | |
1214 | ||
1215 | Note that this minor mode controls Emacs's own auto-raise | |
1216 | feature. Window managers that switch focus on mouse movement | |
1217 | often have their own auto-raise feature." | |
f44379e7 SM |
1218 | :variable (frame-parameter nil 'auto-raise) |
1219 | (if (frame-parameter nil 'auto-raise) | |
1220 | (raise-frame))) | |
7eadab74 | 1221 | |
f44379e7 | 1222 | (define-minor-mode auto-lower-mode |
7eadab74 | 1223 | "Toggle whether or not the selected frame should auto-lower. |
06e21633 CY |
1224 | With a prefix argument ARG, enable Auto Lower mode if ARG is |
1225 | positive, and disable it otherwise. If called from Lisp, enable | |
1226 | the mode if ARG is omitted or nil. | |
1227 | ||
ed472be9 CY |
1228 | Auto Lower mode does nothing under most window managers, which |
1229 | switch focus on mouse clicks. It only has an effect if your | |
1230 | window manager switches focus on mouse movement (in which case | |
1231 | you should also change `focus-follows-mouse' to t). Then, | |
1232 | enabling Auto Lower Mode causes any graphical Emacs frame which | |
1233 | loses focus to be automatically lowered. | |
1234 | ||
1235 | Note that this minor mode controls Emacs's own auto-lower | |
1236 | feature. Window managers that switch focus on mouse movement | |
1237 | often have their own features for raising or lowering frames." | |
f44379e7 SM |
1238 | :variable (frame-parameter nil 'auto-lower)) |
1239 | ||
7777d03b EZ |
1240 | (defun set-frame-name (name) |
1241 | "Set the name of the selected frame to NAME. | |
1242 | When called interactively, prompt for the name of the frame. | |
37269466 CY |
1243 | On text terminals, the frame name is displayed on the mode line. |
1244 | On graphical displays, it is displayed on the frame's title bar." | |
7777d03b EZ |
1245 | (interactive "sFrame name: ") |
1246 | (modify-frame-parameters (selected-frame) | |
1247 | (list (cons 'name name)))) | |
56cfea72 KS |
1248 | |
1249 | (defun frame-current-scroll-bars (&optional frame) | |
1250 | "Return the current scroll-bar settings in frame FRAME. | |
1cecf04d | 1251 | Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the |
56cfea72 | 1252 | current location of the vertical scroll-bars (left, right, or nil), |
1cecf04d | 1253 | and HORIZONTAL specifies the current location of the horizontal scroll |
56cfea72 KS |
1254 | bars (top, bottom, or nil)." |
1255 | (let ((vert (frame-parameter frame 'vertical-scroll-bars)) | |
1256 | (hor nil)) | |
1257 | (unless (memq vert '(left right nil)) | |
1258 | (setq vert default-frame-scroll-bars)) | |
1259 | (cons vert hor))) | |
64c669bc | 1260 | \f |
9911648b | 1261 | ;;;; Frame/display capabilities. |
6ed8eeff KL |
1262 | (defun selected-terminal () |
1263 | "Return the terminal that is now selected." | |
1264 | (frame-terminal (selected-frame))) | |
b6660415 | 1265 | |
73e6adaa DN |
1266 | (declare-function msdos-mouse-p "dosfns.c") |
1267 | ||
9911648b EZ |
1268 | (defun display-mouse-p (&optional display) |
1269 | "Return non-nil if DISPLAY has a mouse available. | |
1270 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
1271 | frame's display)." | |
1272 | (let ((frame-type (framep-on-display display))) | |
1273 | (cond | |
1274 | ((eq frame-type 'pc) | |
1275 | (msdos-mouse-p)) | |
0fda9b75 | 1276 | ((eq frame-type 'w32) |
9fa5bb32 RS |
1277 | (with-no-warnings |
1278 | (> w32-num-mouse-buttons 0))) | |
9e2a2647 DN |
1279 | ((memq frame-type '(x ns)) |
1280 | t) ;; We assume X and NeXTstep *always* have a pointing device | |
9911648b | 1281 | (t |
7565ee93 DL |
1282 | (or (and (featurep 'xt-mouse) |
1283 | xterm-mouse-mode) | |
1284 | ;; t-mouse is distributed with the GPM package. It doesn't have | |
1285 | ;; a toggle. | |
1286 | (featurep 't-mouse)))))) | |
9911648b EZ |
1287 | |
1288 | (defun display-popup-menus-p (&optional display) | |
1289 | "Return non-nil if popup menus are supported on DISPLAY. | |
1290 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
1291 | frame's display). | |
1292 | Support for popup menus requires that the mouse be available." | |
1293 | (and | |
1294 | (let ((frame-type (framep-on-display display))) | |
9e2a2647 | 1295 | (memq frame-type '(x w32 pc ns))) |
9911648b EZ |
1296 | (display-mouse-p display))) |
1297 | ||
1298 | (defun display-graphic-p (&optional display) | |
1299 | "Return non-nil if DISPLAY is a graphic display. | |
1300 | Graphical displays are those which are capable of displaying several | |
1301 | frames and several different fonts at once. This is true for displays | |
1302 | that use a window system such as X, and false for text-only terminals. | |
1303 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
1304 | frame's display)." | |
9e2a2647 | 1305 | (not (null (memq (framep-on-display display) '(x w32 ns))))) |
9911648b | 1306 | |
ddc456e4 EZ |
1307 | (defun display-images-p (&optional display) |
1308 | "Return non-nil if DISPLAY can display images. | |
1309 | ||
1310 | DISPLAY can be a display name, a frame, or nil (meaning the selected | |
1311 | frame's display)." | |
1312 | (and (display-graphic-p display) | |
1313 | (fboundp 'image-mask-p) | |
fcc6f5cc | 1314 | (fboundp 'image-size))) |
ddc456e4 | 1315 | |
6693b279 EZ |
1316 | (defalias 'display-multi-frame-p 'display-graphic-p) |
1317 | (defalias 'display-multi-font-p 'display-graphic-p) | |
1318 | ||
9911648b EZ |
1319 | (defun display-selections-p (&optional display) |
1320 | "Return non-nil if DISPLAY supports selections. | |
1321 | A selection is a way to transfer text or other data between programs | |
45240125 | 1322 | via special system buffers called `selection' or `clipboard'. |
9911648b EZ |
1323 | DISPLAY can be a display name, a frame, or nil (meaning the selected |
1324 | frame's display)." | |
1325 | (let ((frame-type (framep-on-display display))) | |
1326 | (cond | |
1327 | ((eq frame-type 'pc) | |
1328 | ;; MS-DOG frames support selections when Emacs runs inside | |
1329 | ;; the Windows' DOS Box. | |
9fa5bb32 RS |
1330 | (with-no-warnings |
1331 | (not (null dos-windows-version)))) | |
9e2a2647 | 1332 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1333 | t) ;; FIXME? |
1334 | (t | |
1335 | nil)))) | |
1336 | ||
aa360da1 GM |
1337 | (declare-function x-display-screens "xfns.c" (&optional terminal)) |
1338 | ||
9911648b EZ |
1339 | (defun display-screens (&optional display) |
1340 | "Return the number of screens associated with DISPLAY." | |
1341 | (let ((frame-type (framep-on-display display))) | |
1342 | (cond | |
9e2a2647 | 1343 | ((memq frame-type '(x w32 ns)) |
9911648b | 1344 | (x-display-screens display)) |
bb9404d6 | 1345 | (t |
9911648b EZ |
1346 | 1)))) |
1347 | ||
aa360da1 GM |
1348 | (declare-function x-display-pixel-height "xfns.c" (&optional terminal)) |
1349 | ||
9911648b EZ |
1350 | (defun display-pixel-height (&optional display) |
1351 | "Return the height of DISPLAY's screen in pixels. | |
1352 | For character terminals, each character counts as a single pixel." | |
1353 | (let ((frame-type (framep-on-display display))) | |
1354 | (cond | |
9e2a2647 | 1355 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1356 | (x-display-pixel-height display)) |
1357 | (t | |
1358 | (frame-height (if (framep display) display (selected-frame))))))) | |
1359 | ||
aa360da1 GM |
1360 | (declare-function x-display-pixel-width "xfns.c" (&optional terminal)) |
1361 | ||
9911648b EZ |
1362 | (defun display-pixel-width (&optional display) |
1363 | "Return the width of DISPLAY's screen in pixels. | |
1364 | For character terminals, each character counts as a single pixel." | |
1365 | (let ((frame-type (framep-on-display display))) | |
1366 | (cond | |
9e2a2647 | 1367 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1368 | (x-display-pixel-width display)) |
1369 | (t | |
1370 | (frame-width (if (framep display) display (selected-frame))))))) | |
1371 | ||
51e39dfc KS |
1372 | (defcustom display-mm-dimensions-alist nil |
1373 | "Alist for specifying screen dimensions in millimeters. | |
1374 | The dimensions will be used for `display-mm-height' and | |
1375 | `display-mm-width' if defined for the respective display. | |
1376 | ||
1377 | Each element of the alist has the form (display . (width . height)), | |
1378 | e.g. (\":0.0\" . (287 . 215)). | |
1379 | ||
1380 | If `display' equals t, it specifies dimensions for all graphical | |
c7015153 | 1381 | displays not explicitly specified." |
51e39dfc KS |
1382 | :version "22.1" |
1383 | :type '(alist :key-type (choice (string :tag "Display name") | |
1384 | (const :tag "Default" t)) | |
1385 | :value-type (cons :tag "Dimensions" | |
1386 | (integer :tag "Width") | |
1387 | (integer :tag "Height"))) | |
1388 | :group 'frames) | |
1389 | ||
aa360da1 GM |
1390 | (declare-function x-display-mm-height "xfns.c" (&optional terminal)) |
1391 | ||
9911648b EZ |
1392 | (defun display-mm-height (&optional display) |
1393 | "Return the height of DISPLAY's screen in millimeters. | |
d7cd2d8b | 1394 | System values can be overridden by `display-mm-dimensions-alist'. |
9911648b | 1395 | If the information is unavailable, value is nil." |
9e2a2647 | 1396 | (and (memq (framep-on-display display) '(x w32 ns)) |
51e39dfc KS |
1397 | (or (cddr (assoc (or display (frame-parameter nil 'display)) |
1398 | display-mm-dimensions-alist)) | |
1399 | (cddr (assoc t display-mm-dimensions-alist)) | |
1400 | (x-display-mm-height display)))) | |
9911648b | 1401 | |
aa360da1 GM |
1402 | (declare-function x-display-mm-width "xfns.c" (&optional terminal)) |
1403 | ||
9911648b EZ |
1404 | (defun display-mm-width (&optional display) |
1405 | "Return the width of DISPLAY's screen in millimeters. | |
d7cd2d8b | 1406 | System values can be overridden by `display-mm-dimensions-alist'. |
9911648b | 1407 | If the information is unavailable, value is nil." |
9e2a2647 | 1408 | (and (memq (framep-on-display display) '(x w32 ns)) |
51e39dfc KS |
1409 | (or (cadr (assoc (or display (frame-parameter nil 'display)) |
1410 | display-mm-dimensions-alist)) | |
1411 | (cadr (assoc t display-mm-dimensions-alist)) | |
1412 | (x-display-mm-width display)))) | |
9911648b | 1413 | |
aa360da1 GM |
1414 | (declare-function x-display-backing-store "xfns.c" (&optional terminal)) |
1415 | ||
9911648b EZ |
1416 | (defun display-backing-store (&optional display) |
1417 | "Return the backing store capability of DISPLAY's screen. | |
1418 | The value may be `always', `when-mapped', `not-useful', or nil if | |
1419 | the question is inapplicable to a certain kind of display." | |
1420 | (let ((frame-type (framep-on-display display))) | |
1421 | (cond | |
9e2a2647 | 1422 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1423 | (x-display-backing-store display)) |
1424 | (t | |
1425 | 'not-useful)))) | |
1426 | ||
aa360da1 GM |
1427 | (declare-function x-display-save-under "xfns.c" (&optional terminal)) |
1428 | ||
9911648b EZ |
1429 | (defun display-save-under (&optional display) |
1430 | "Return non-nil if DISPLAY's screen supports the SaveUnder feature." | |
1431 | (let ((frame-type (framep-on-display display))) | |
1432 | (cond | |
9e2a2647 | 1433 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1434 | (x-display-save-under display)) |
1435 | (t | |
1436 | 'not-useful)))) | |
1437 | ||
aa360da1 GM |
1438 | (declare-function x-display-planes "xfns.c" (&optional terminal)) |
1439 | ||
9911648b EZ |
1440 | (defun display-planes (&optional display) |
1441 | "Return the number of planes supported by DISPLAY." | |
1442 | (let ((frame-type (framep-on-display display))) | |
1443 | (cond | |
9e2a2647 | 1444 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1445 | (x-display-planes display)) |
1446 | ((eq frame-type 'pc) | |
1447 | 4) | |
1448 | (t | |
1449 | (truncate (log (length (tty-color-alist)) 2)))))) | |
1450 | ||
aa360da1 GM |
1451 | (declare-function x-display-color-cells "xfns.c" (&optional terminal)) |
1452 | ||
9911648b EZ |
1453 | (defun display-color-cells (&optional display) |
1454 | "Return the number of color cells supported by DISPLAY." | |
1455 | (let ((frame-type (framep-on-display display))) | |
1456 | (cond | |
9e2a2647 | 1457 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1458 | (x-display-color-cells display)) |
1459 | ((eq frame-type 'pc) | |
1460 | 16) | |
1461 | (t | |
3224dac1 | 1462 | (tty-display-color-cells display))))) |
9911648b | 1463 | |
aa360da1 GM |
1464 | (declare-function x-display-visual-class "xfns.c" (&optional terminal)) |
1465 | ||
9911648b | 1466 | (defun display-visual-class (&optional display) |
6cda144f | 1467 | "Return the visual class of DISPLAY. |
9911648b EZ |
1468 | The value is one of the symbols `static-gray', `gray-scale', |
1469 | `static-color', `pseudo-color', `true-color', or `direct-color'." | |
1470 | (let ((frame-type (framep-on-display display))) | |
1471 | (cond | |
9e2a2647 | 1472 | ((memq frame-type '(x w32 ns)) |
9911648b EZ |
1473 | (x-display-visual-class display)) |
1474 | ((and (memq frame-type '(pc t)) | |
1475 | (tty-display-color-p display)) | |
1476 | 'static-color) | |
1477 | (t | |
1478 | 'static-gray)))) | |
1479 | ||
1480 | \f | |
a32c1804 RS |
1481 | ;;;; Frame geometry values |
1482 | ||
1483 | (defun frame-geom-value-cons (type value &optional frame) | |
1484 | "Return equivalent geometry value for FRAME as a cons with car `+'. | |
1485 | A geometry value equivalent to VALUE for FRAME is returned, | |
1486 | where the value is a cons with car `+', not numeric. | |
1487 | TYPE is the car of the original geometry spec (TYPE . VALUE). | |
1488 | It is `top' or `left', depending on which edge VALUE is related to. | |
1489 | VALUE is the cdr of a frame geometry spec: (left/top . VALUE). | |
1490 | If VALUE is a number, then it is converted to a cons value, perhaps | |
1491 | relative to the opposite frame edge from that in the original spec. | |
1492 | FRAME defaults to the selected frame. | |
1493 | ||
1494 | Examples (measures in pixels) - | |
1495 | Assuming display height/width=1024, frame height/width=600: | |
1496 | 300 inside display edge: 300 => (+ 300) | |
1497 | (+ 300) => (+ 300) | |
1498 | 300 inside opposite display edge: (- 300) => (+ 124) | |
1499 | -300 => (+ 124) | |
1500 | 300 beyond display edge | |
1501 | (= 724 inside opposite display edge): (+ -300) => (+ -300) | |
1502 | 300 beyond display edge | |
1503 | (= 724 inside opposite display edge): (- -300) => (+ 724) | |
1504 | ||
1505 | In the 3rd, 4th, and 6th examples, the returned value is relative to | |
1506 | the opposite frame edge from the edge indicated in the input spec." | |
1507 | (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300) | |
1508 | value) | |
1509 | ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300) | |
1510 | (t ; e.g. -300, (- 300), (- -300) | |
1511 | (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724) | |
1512 | (x-display-pixel-width) | |
1513 | (x-display-pixel-height)) | |
1514 | (if (integerp value) (- value) (cadr value)) | |
1515 | (if (eq 'left type) | |
1516 | (frame-pixel-width frame) | |
1517 | (frame-pixel-height frame))))))) | |
1518 | ||
1519 | (defun frame-geom-spec-cons (spec &optional frame) | |
1520 | "Return equivalent geometry spec for FRAME as a cons with car `+'. | |
1521 | A geometry specification equivalent to SPEC for FRAME is returned, | |
1522 | where the value is a cons with car `+', not numeric. | |
1523 | SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE). | |
1524 | If VALUE is a number, then it is converted to a cons value, perhaps | |
1525 | relative to the opposite frame edge from that in the original spec. | |
1526 | FRAME defaults to the selected frame. | |
1527 | ||
1528 | Examples (measures in pixels) - | |
1529 | Assuming display height=1024, frame height=600: | |
1530 | top 300 below display top: (top . 300) => (top + 300) | |
1531 | (top + 300) => (top + 300) | |
1532 | bottom 300 above display bottom: (top - 300) => (top + 124) | |
1533 | (top . -300) => (top + 124) | |
1534 | top 300 above display top | |
1535 | (= bottom 724 above display bottom): (top + -300) => (top + -300) | |
1536 | bottom 300 below display bottom | |
1537 | (= top 724 below display top): (top - -300) => (top + 724) | |
1538 | ||
1539 | In the 3rd, 4th, and 6th examples, the returned value is relative to | |
1540 | the opposite frame edge from the edge indicated in the input spec." | |
06b60517 | 1541 | (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame))) |
a32c1804 | 1542 | \f |
9e2b097b | 1543 | |
154a757e | 1544 | (defun delete-other-frames (&optional frame) |
4a592f66 | 1545 | "Delete all frames on the current terminal, except FRAME. |
a2125918 GM |
1546 | If FRAME uses another frame's minibuffer, the minibuffer frame is |
1547 | left untouched. FRAME nil or omitted means use the selected frame." | |
154a757e GM |
1548 | (interactive) |
1549 | (unless frame | |
1550 | (setq frame (selected-frame))) | |
a2125918 GM |
1551 | (let* ((mini-frame (window-frame (minibuffer-window frame))) |
1552 | (frames (delq mini-frame (delq frame (frame-list))))) | |
5e5ae184 SM |
1553 | ;; Only consider frames on the same terminal. |
1554 | (dolist (frame (prog1 frames (setq frames nil))) | |
1555 | (if (eq (frame-terminal) (frame-terminal frame)) | |
1556 | (push frame frames))) | |
a2125918 GM |
1557 | ;; Delete mon-minibuffer-only frames first, because `delete-frame' |
1558 | ;; signals an error when trying to delete a mini-frame that's | |
1559 | ;; still in use by another frame. | |
1560 | (dolist (frame frames) | |
1561 | (unless (eq (frame-parameter frame 'minibuffer) 'only) | |
1562 | (delete-frame frame))) | |
1563 | ;; Delete minibuffer-only frames. | |
1564 | (dolist (frame frames) | |
1565 | (when (eq (frame-parameter frame 'minibuffer) 'only) | |
1566 | (delete-frame frame))))) | |
154a757e | 1567 | |
da7829a3 | 1568 | ;; miscellaneous obsolescence declarations |
84ed1560 JB |
1569 | (define-obsolete-variable-alias 'delete-frame-hook |
1570 | 'delete-frame-functions "22.1") | |
da7829a3 | 1571 | |
dc6d9681 | 1572 | \f |
7e573c4a | 1573 | ;; Blinking cursor |
81b99826 GM |
1574 | |
1575 | (defgroup cursor nil | |
ca693be8 | 1576 | "Displaying text cursors." |
40d34803 | 1577 | :version "21.1" |
81b99826 GM |
1578 | :group 'frames) |
1579 | ||
1580 | (defcustom blink-cursor-delay 0.5 | |
6cda144f | 1581 | "Seconds of idle time after which cursor starts to blink." |
81b99826 GM |
1582 | :type 'number |
1583 | :group 'cursor) | |
1584 | ||
1585 | (defcustom blink-cursor-interval 0.5 | |
6cda144f | 1586 | "Length of cursor blink interval in seconds." |
81b99826 GM |
1587 | :type 'number |
1588 | :group 'cursor) | |
1589 | ||
1590 | (defvar blink-cursor-idle-timer nil | |
ca693be8 GM |
1591 | "Timer started after `blink-cursor-delay' seconds of Emacs idle time. |
1592 | The function `blink-cursor-start' is called when the timer fires.") | |
81b99826 GM |
1593 | |
1594 | (defvar blink-cursor-timer nil | |
ca693be8 | 1595 | "Timer started from `blink-cursor-start'. |
a795e09a LT |
1596 | This timer calls `blink-cursor-timer-function' every |
1597 | `blink-cursor-interval' seconds.") | |
1598 | ||
81b99826 | 1599 | (defun blink-cursor-start () |
ca693be8 GM |
1600 | "Timer function called from the timer `blink-cursor-idle-timer'. |
1601 | This starts the timer `blink-cursor-timer', which makes the cursor blink | |
1602 | if appropriate. It also arranges to cancel that timer when the next | |
1603 | command starts, by installing a pre-command hook." | |
81b99826 | 1604 | (when (null blink-cursor-timer) |
f9ac92c5 CY |
1605 | ;; Set up the timer first, so that if this signals an error, |
1606 | ;; blink-cursor-end is not added to pre-command-hook. | |
81b99826 GM |
1607 | (setq blink-cursor-timer |
1608 | (run-with-timer blink-cursor-interval blink-cursor-interval | |
f9ac92c5 CY |
1609 | 'blink-cursor-timer-function)) |
1610 | (add-hook 'pre-command-hook 'blink-cursor-end) | |
1611 | (internal-show-cursor nil nil))) | |
0a5ebe4b GM |
1612 | |
1613 | (defun blink-cursor-timer-function () | |
1614 | "Timer function of timer `blink-cursor-timer'." | |
1615 | (internal-show-cursor nil (not (internal-show-cursor-p)))) | |
81b99826 GM |
1616 | |
1617 | (defun blink-cursor-end () | |
1618 | "Stop cursor blinking. | |
ca693be8 | 1619 | This is installed as a pre-command hook by `blink-cursor-start'. |
f39784dd | 1620 | When run, it cancels the timer `blink-cursor-timer' and removes |
ca693be8 | 1621 | itself as a pre-command hook." |
81b99826 | 1622 | (remove-hook 'pre-command-hook 'blink-cursor-end) |
0a5ebe4b | 1623 | (internal-show-cursor nil t) |
8ec94c16 SM |
1624 | (when blink-cursor-timer |
1625 | (cancel-timer blink-cursor-timer) | |
1626 | (setq blink-cursor-timer nil))) | |
81b99826 | 1627 | |
e5bd0a28 SM |
1628 | (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1") |
1629 | ||
8ec94c16 | 1630 | (define-minor-mode blink-cursor-mode |
06e21633 CY |
1631 | "Toggle cursor blinking (Blink Cursor mode). |
1632 | With a prefix argument ARG, enable Blink Cursor mode if ARG is | |
1633 | positive, and disable it otherwise. If called from Lisp, enable | |
1634 | the mode if ARG is omitted or nil. | |
1635 | ||
1636 | This command is effective only on graphical frames. On text-only | |
1637 | terminals, cursor blinking is controlled by the terminal." | |
8ec94c16 SM |
1638 | :init-value (not (or noninteractive |
1639 | no-blinking-cursor | |
1640 | (eq system-type 'ms-dos) | |
0afb6242 | 1641 | (not (memq window-system '(x w32 ns))))) |
adba8116 | 1642 | :initialize 'custom-initialize-delay |
8ec94c16 SM |
1643 | :group 'cursor |
1644 | :global t | |
1645 | (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer)) | |
1646 | (setq blink-cursor-idle-timer nil) | |
1647 | (blink-cursor-end) | |
1648 | (when blink-cursor-mode | |
1649 | ;; Hide the cursor. | |
1650 | ;;(internal-show-cursor nil nil) | |
1651 | (setq blink-cursor-idle-timer | |
1652 | (run-with-idle-timer blink-cursor-delay | |
1653 | blink-cursor-delay | |
1654 | 'blink-cursor-start)))) | |
81b99826 | 1655 | |
81b99826 | 1656 | \f |
a45b7647 | 1657 | ;; Frame maximization/fullscreen |
37f38bca SS |
1658 | |
1659 | (defun toggle-frame-maximized () | |
a45b7647 JL |
1660 | "Toggle maximization state of the selected frame. |
1661 | Maximize the selected frame or un-maximize if it is already maximized. | |
1662 | Respect window manager screen decorations. | |
1663 | If the frame is in fullscreen mode, don't change its mode, | |
1664 | just toggle the temporary frame parameter `maximized', | |
1665 | so the frame will go to the right maximization state | |
1666 | after disabling fullscreen mode. | |
1667 | See also `toggle-frame-fullscreen'." | |
37f38bca | 1668 | (interactive) |
a45b7647 JL |
1669 | (if (eq (frame-parameter nil 'fullscreen) 'fullscreen) |
1670 | (modify-frame-parameters | |
1671 | nil | |
1672 | `((maximized | |
1673 | . ,(unless (eq (frame-parameter nil 'maximized) 'maximized) | |
1674 | 'maximized)))) | |
1675 | (modify-frame-parameters | |
1676 | nil | |
1677 | `((fullscreen | |
1678 | . ,(unless (eq (frame-parameter nil 'fullscreen) 'maximized) | |
1679 | 'maximized)))))) | |
1680 | ||
1681 | (defun toggle-frame-fullscreen () | |
1682 | "Toggle fullscreen mode of the selected frame. | |
1683 | Enable fullscreen mode of the selected frame or disable if it is | |
1684 | already fullscreen. Ignore window manager screen decorations. | |
1685 | When turning on fullscreen mode, remember the previous value of the | |
1686 | maximization state in the temporary frame parameter `maximized'. | |
1687 | Restore the maximization state when turning off fullscreen mode. | |
37f38bca SS |
1688 | See also `toggle-frame-maximized'." |
1689 | (interactive) | |
1690 | (modify-frame-parameters | |
a45b7647 JL |
1691 | nil |
1692 | `((maximized | |
1693 | . ,(unless (eq (frame-parameter nil 'fullscreen) 'fullscreen) | |
1694 | (frame-parameter nil 'fullscreen))) | |
1695 | (fullscreen | |
1696 | . ,(if (eq (frame-parameter nil 'fullscreen) 'fullscreen) | |
1697 | (if (eq (frame-parameter nil 'maximized) 'maximized) | |
1698 | 'maximized) | |
1699 | 'fullscreen))))) | |
37f38bca SS |
1700 | |
1701 | \f | |
64c669bc | 1702 | ;;;; Key bindings |
64c669bc | 1703 | |
6238bfaf | 1704 | (define-key ctl-x-5-map "2" 'make-frame-command) |
154a757e | 1705 | (define-key ctl-x-5-map "1" 'delete-other-frames) |
dc6d9681 | 1706 | (define-key ctl-x-5-map "0" 'delete-frame) |
ceab6935 | 1707 | (define-key ctl-x-5-map "o" 'other-frame) |
a45b7647 JL |
1708 | (define-key global-map [f11] 'toggle-frame-fullscreen) |
1709 | (define-key global-map [(meta f10)] 'toggle-frame-maximized) | |
49116ac0 | 1710 | |
7a76850c CY |
1711 | \f |
1712 | ;; Misc. | |
1713 | ||
2a1e2476 | 1714 | ;; Only marked as obsolete in 24.3. |
e5bd0a28 SM |
1715 | (define-obsolete-variable-alias 'automatic-hscrolling |
1716 | 'auto-hscroll-mode "22.1") | |
7a76850c CY |
1717 | |
1718 | (make-variable-buffer-local 'show-trailing-whitespace) | |
1719 | ||
3424a4f6 CY |
1720 | ;; Defined in dispnew.c. |
1721 | (make-obsolete-variable | |
1722 | 'window-system-version "it does not give useful information." "24.3") | |
1723 | ||
dc6d9681 | 1724 | (provide 'frame) |
c88ab9ce | 1725 | |
dc6d9681 | 1726 | ;;; frame.el ends here |