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