1 ;;; frame.el --- multi-frame management independent of window systems
3 ;; Copyright (C) 1993-1994, 1996-1997, 2000-2012
4 ;; Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (eval-when-compile (require 'cl
))
30 (defvar frame-creation-function-alist
32 (if (fboundp 'tty-create-frame-with-faces
)
33 'tty-create-frame-with-faces
35 (error "Can't create multiple frames without a window system")))))
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
41 (defvar window-system-default-frame-alist nil
42 "Alist of window-system dependent default frame parameters.
43 Parameters specified here supersede the values given in
44 `default-frame-alist'.")
46 ;; The initial value given here used to ask for a minibuffer.
47 ;; But that's not necessary, because the default is to have one.
48 ;; By not specifying it here, we let an X resource specify it.
49 (defcustom initial-frame-alist nil
50 "Alist of parameters for the initial X window frame.
51 You can set this in your init file; for example,
53 (setq initial-frame-alist
54 '((top . 1) (left . 1) (width . 80) (height . 55)))
56 Parameters specified here supersede the values given in
57 `default-frame-alist'.
59 If the value calls for a frame without a minibuffer, and you have
60 not created a minibuffer frame on your own, a minibuffer frame is
61 created according to `minibuffer-frame-alist'.
63 You can specify geometry-related options for just the initial
64 frame by setting this variable in your init file; however, they
65 won't take effect until Emacs reads your init file, which happens
66 after creating the initial frame. If you want the initial frame
67 to have the proper geometry as soon as it appears, you need to
68 use this three-step process:
69 * Specify X resources to give the geometry you want.
70 * Set `default-frame-alist' to override these options so that they
71 don't affect subsequent frames.
72 * Set `initial-frame-alist' in a way that matches the X resources,
73 to override what you put in `default-frame-alist'."
74 :type
'(repeat (cons :format
"%v"
75 (symbol :tag
"Parameter")
79 (defcustom minibuffer-frame-alist
'((width .
80) (height .
2))
80 "Alist of parameters for the initial minibuffer frame.
81 This is the minibuffer frame created if `initial-frame-alist'
82 calls for a frame without a minibuffer. The parameters specified
83 here supersede those given in `default-frame-alist', for the
84 initial minibuffer frame.
86 You can set this in your init file; for example,
88 (setq minibuffer-frame-alist
89 '((top . 1) (left . 1) (width . 80) (height . 2)))
91 It is not necessary to include (minibuffer . only); that is
92 appended when the minibuffer frame is created."
93 :type
'(repeat (cons :format
"%v"
94 (symbol :tag
"Parameter")
98 (defun handle-delete-frame (event)
99 "Handle delete-frame events from the X server."
101 (let ((frame (posn-window (event-start event
)))
105 (and (frame-visible-p (car tail
))
106 (not (eq (car tail
) frame
))
108 (setq tail
(cdr tail
)))
110 (delete-frame frame t
)
111 ;; Gildea@x.org says it is ok to ask questions before terminating.
112 (save-buffers-kill-emacs))))
114 ;;;; Arrangement of frames at startup
116 ;; 1) Load the window system startup file from the lisp library and read the
117 ;; high-priority arguments (-q and the like). The window system startup
118 ;; file should create any frames specified in the window system defaults.
120 ;; 2) If no frames have been opened, we open an initial text frame.
122 ;; 3) Once the init file is done, we apply any newly set parameters
123 ;; in initial-frame-alist to the frame.
125 ;; These are now called explicitly at the proper times,
126 ;; since that is easier to understand.
127 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
128 ;; (add-hook 'before-init-hook 'frame-initialize)
129 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
131 ;; If we create the initial frame, this is it.
132 (defvar frame-initial-frame nil
)
134 ;; Record the parameters used in frame-initialize to make the initial frame.
135 (defvar frame-initial-frame-alist
)
137 (defvar frame-initial-geometry-arguments nil
)
139 ;; startup.el calls this function before loading the user's init
140 ;; file - if there is no frame with a minibuffer open now, create
141 ;; one to display messages while loading the init file.
142 (defun frame-initialize ()
143 "Create an initial frame if necessary."
144 ;; Are we actually running under a window system at all?
145 (if (and initial-window-system
147 (not (eq initial-window-system
'pc
)))
149 ;; If there is no frame with a minibuffer besides the terminal
150 ;; frame, then we need to create the opening frame. Make sure
151 ;; it has a minibuffer, but let initial-frame-alist omit the
153 (or (delq terminal-frame
(minibuffer-frame-list))
155 (setq frame-initial-frame-alist
156 (append initial-frame-alist default-frame-alist nil
))
157 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist
)
158 (setq frame-initial-frame-alist
159 (cons '(horizontal-scroll-bars . t
)
160 frame-initial-frame-alist
)))
161 (setq frame-initial-frame-alist
162 (cons (cons 'window-system initial-window-system
)
163 frame-initial-frame-alist
))
164 (setq default-minibuffer-frame
165 (setq frame-initial-frame
166 (make-frame frame-initial-frame-alist
)))
167 ;; Delete any specifications for window geometry parameters
168 ;; so that we won't reapply them in frame-notice-user-settings.
169 ;; It would be wrong to reapply them then,
170 ;; because that would override explicit user resizing.
171 (setq initial-frame-alist
172 (frame-remove-geometry-params initial-frame-alist
))))
173 ;; Copy the environment of the Emacs process into the new frame.
174 (set-frame-parameter frame-initial-frame
'environment
175 (frame-parameter terminal-frame
'environment
))
176 ;; At this point, we know that we have a frame open, so we
177 ;; can delete the terminal frame.
178 (delete-frame terminal-frame
)
179 (setq terminal-frame nil
))))
181 (defvar frame-notice-user-settings t
182 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
184 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
186 ;; startup.el calls this function after loading the user's init
187 ;; file. Now default-frame-alist and initial-frame-alist contain
188 ;; information to which we must react; do what needs to be done.
189 (defun frame-notice-user-settings ()
190 "Act on user's init file settings of frame parameters.
191 React to settings of `initial-frame-alist',
192 `window-system-default-frame-alist' and `default-frame-alist'
193 there (in decreasing order of priority)."
194 ;; Creating and deleting frames may shift the selected frame around,
195 ;; and thus the current buffer. Protect against that. We don't
196 ;; want to use save-excursion here, because that may also try to set
197 ;; the buffer of the selected window, which fails when the selected
198 ;; window is the minibuffer.
199 (let ((old-buffer (current-buffer))
200 (window-system-frame-alist
201 (cdr (assq initial-window-system
202 window-system-default-frame-alist
))))
204 (when (and frame-notice-user-settings
205 (null frame-initial-frame
))
206 ;; This case happens when we don't have a window system, and
207 ;; also for MS-DOS frames.
208 (let ((parms (frame-parameters)))
209 ;; Don't change the frame names.
210 (setq parms
(delq (assq 'name parms
) parms
))
211 ;; Can't modify the minibuffer parameter, so don't try.
212 (setq parms
(delq (assq 'minibuffer parms
) parms
))
213 (modify-frame-parameters
215 (if initial-window-system
217 ;; initial-frame-alist and default-frame-alist were already
218 ;; applied in pc-win.el.
219 (append initial-frame-alist window-system-frame-alist
220 default-frame-alist parms nil
)))
221 (if (null initial-window-system
) ;; MS-DOS does this differently in pc-win.el
222 (let ((newparms (frame-parameters))
223 (frame (selected-frame)))
224 (tty-handle-reverse-video frame newparms
)
225 ;; If we changed the background color, we need to update
226 ;; the background-mode parameter, and maybe some faces,
228 (when (assq 'background-color newparms
)
229 (unless (or (assq 'background-mode initial-frame-alist
)
230 (assq 'background-mode default-frame-alist
))
231 (frame-set-background-mode frame
))
232 (face-set-after-frame-default frame
))))))
234 ;; If the initial frame is still around, apply initial-frame-alist
235 ;; and default-frame-alist to it.
236 (when (frame-live-p frame-initial-frame
)
238 ;; When tool-bar has been switched off, correct the frame size
239 ;; by the lines added in x-create-frame for the tool-bar and
240 ;; switch `tool-bar-mode' off.
241 (when (display-graphic-p)
242 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
243 (assq 'tool-bar-lines window-system-frame-alist
)
244 (assq 'tool-bar-lines default-frame-alist
))))
245 (when (and tool-bar-originally-present
246 (or (null tool-bar-lines
)
247 (null (cdr tool-bar-lines
))
248 (eq 0 (cdr tool-bar-lines
))))
249 (let* ((char-height (frame-char-height frame-initial-frame
))
250 (image-height tool-bar-images-pixel-height
)
251 (margin (cond ((and (consp tool-bar-button-margin
)
252 (integerp (cdr tool-bar-button-margin
))
253 (> tool-bar-button-margin
0))
254 (cdr tool-bar-button-margin
))
255 ((and (integerp tool-bar-button-margin
)
256 (> tool-bar-button-margin
0))
257 tool-bar-button-margin
)
259 (relief (if (and (integerp tool-bar-button-relief
)
260 (> tool-bar-button-relief
0))
261 tool-bar-button-relief
3))
262 (lines (/ (+ image-height
267 (height (frame-parameter frame-initial-frame
'height
))
268 (newparms (list (cons 'height
(- height lines
))))
269 (initial-top (cdr (assq 'top
270 frame-initial-geometry-arguments
)))
271 (top (frame-parameter frame-initial-frame
'top
)))
272 (when (and (consp initial-top
) (eq '-
(car initial-top
)))
274 (cond ((and (consp top
)
278 (* lines char-height
))))
283 (* lines char-height
))))
284 (t (+ top
(* lines char-height
))))))
287 `((top .
,adjusted-top
))
289 (modify-frame-parameters frame-initial-frame newparms
)
290 (tool-bar-mode -
1)))))
292 ;; The initial frame we create above always has a minibuffer.
293 ;; If the user wants to remove it, or make it a minibuffer-only
294 ;; frame, then we'll have to delete the current frame and make a
295 ;; new one; you can't remove or add a root window to/from an
298 ;; NOTE: default-frame-alist was nil when we created the
299 ;; existing frame. We need to explicitly include
300 ;; default-frame-alist in the parameters of the screen we
301 ;; create here, so that its new value, gleaned from the user's
302 ;; .emacs file, will be applied to the existing screen.
303 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist
)
304 (assq 'minibuffer window-system-frame-alist
)
305 (assq 'minibuffer default-frame-alist
)
308 ;; Create the new frame.
310 ;; If the frame isn't visible yet, wait till it is.
311 ;; If the user has to position the window,
312 ;; Emacs doesn't know its real position until
313 ;; the frame is seen to be visible.
314 (while (not (cdr (assq 'visibility
315 (frame-parameters frame-initial-frame
))))
317 (setq parms
(frame-parameters frame-initial-frame
))
319 ;; Get rid of `name' unless it was specified explicitly before.
320 (or (assq 'name frame-initial-frame-alist
)
321 (setq parms
(delq (assq 'name parms
) parms
)))
322 ;; An explicit parent-id is a request to XEmbed the frame.
323 (or (assq 'parent-id frame-initial-frame-alist
)
324 (setq parms
(delq (assq 'parent-id parms
) parms
)))
326 (setq parms
(append initial-frame-alist
327 window-system-frame-alist
332 ;; Get rid of `reverse', because that was handled
333 ;; when we first made the frame.
334 (setq parms
(cons '(reverse) (delq (assq 'reverse parms
) parms
)))
336 (if (assq 'height frame-initial-geometry-arguments
)
337 (setq parms
(assq-delete-all 'height parms
)))
338 (if (assq 'width frame-initial-geometry-arguments
)
339 (setq parms
(assq-delete-all 'width parms
)))
340 (if (assq 'left frame-initial-geometry-arguments
)
341 (setq parms
(assq-delete-all 'left parms
)))
342 (if (assq 'top frame-initial-geometry-arguments
)
343 (setq parms
(assq-delete-all 'top parms
)))
346 ;; Use the geometry args that created the existing
347 ;; frame, rather than the parms we get for it.
348 (append frame-initial-geometry-arguments
349 '((user-size . t
) (user-position . t
))
351 ;; The initial frame, which we are about to delete, may be
352 ;; the only frame with a minibuffer. If it is, create a
354 (or (delq frame-initial-frame
(minibuffer-frame-list))
355 (make-initial-minibuffer-frame nil
))
357 ;; If the initial frame is serving as a surrogate
358 ;; minibuffer frame for any frames, we need to wean them
359 ;; onto a new frame. The default-minibuffer-frame
360 ;; variable must be handled similarly.
361 (let ((users-of-initial
364 (and (not (eq frame frame-initial-frame
))
366 (minibuffer-window frame
))
367 frame-initial-frame
))))))
368 (if (or users-of-initial
369 (eq default-minibuffer-frame frame-initial-frame
))
371 ;; Choose an appropriate frame. Prefer frames which
372 ;; are only minibuffers.
373 (let* ((new-surrogate
375 (or (filtered-frame-list
377 (eq (cdr (assq 'minibuffer
378 (frame-parameters frame
)))
380 (minibuffer-frame-list))))
381 (new-minibuffer (minibuffer-window new-surrogate
)))
383 (if (eq default-minibuffer-frame frame-initial-frame
)
384 (setq default-minibuffer-frame new-surrogate
))
386 ;; Wean the frames using frame-initial-frame as
387 ;; their minibuffer frame.
388 (dolist (frame users-of-initial
)
389 (modify-frame-parameters
390 frame
(list (cons 'minibuffer new-minibuffer
)))))))
392 ;; Redirect events enqueued at this frame to the new frame.
393 ;; Is this a good idea?
394 (redirect-frame-focus frame-initial-frame new
)
396 ;; Finally, get rid of the old frame.
397 (delete-frame frame-initial-frame t
))
399 ;; Otherwise, we don't need all that rigmarole; just apply
400 ;; the new parameters.
401 (let (newparms allparms tail
)
402 (setq allparms
(append initial-frame-alist
403 window-system-frame-alist
404 default-frame-alist nil
))
405 (if (assq 'height frame-initial-geometry-arguments
)
406 (setq allparms
(assq-delete-all 'height allparms
)))
407 (if (assq 'width frame-initial-geometry-arguments
)
408 (setq allparms
(assq-delete-all 'width allparms
)))
409 (if (assq 'left frame-initial-geometry-arguments
)
410 (setq allparms
(assq-delete-all 'left allparms
)))
411 (if (assq 'top frame-initial-geometry-arguments
)
412 (setq allparms
(assq-delete-all 'top allparms
)))
414 ;; Find just the parms that have changed since we first
415 ;; made this frame. Those are the ones actually set by
416 ;; the init file. For those parms whose values we already knew
417 ;; (such as those spec'd by command line options)
418 ;; it is undesirable to specify the parm again
419 ;; once the user has seen the frame and been able to alter it
423 (setq oldval
(assq (car entry
) frame-initial-frame-alist
))
424 (setq newval
(cdr (assq (car entry
) allparms
)))
425 (or (and oldval
(eq (cdr oldval
) newval
))
427 (cons (cons (car entry
) newval
) newparms
)))))
428 (setq newparms
(nreverse newparms
))
430 (let ((new-bg (assq 'background-color newparms
)))
431 ;; If the `background-color' parameter is changed, apply
432 ;; it first, then make sure that the `background-mode'
433 ;; parameter and other faces are updated, before applying
434 ;; the other parameters.
436 (modify-frame-parameters frame-initial-frame
438 (unless (assq 'background-mode newparms
)
439 (frame-set-background-mode frame-initial-frame
))
440 (face-set-after-frame-default frame-initial-frame
)
441 (setq newparms
(delq new-bg newparms
)))
442 (modify-frame-parameters frame-initial-frame newparms
)))))
444 ;; Restore the original buffer.
445 (set-buffer old-buffer
)
447 ;; Make sure the initial frame can be GC'd if it is ever deleted.
448 ;; Make sure frame-notice-user-settings does nothing if called twice.
449 (setq frame-notice-user-settings nil
)
450 (setq frame-initial-frame nil
)))
452 (defun make-initial-minibuffer-frame (display)
453 (let ((parms (append minibuffer-frame-alist
'((minibuffer . only
)))))
455 (make-frame-on-display display parms
)
456 (make-frame parms
))))
458 ;;;; Creation of additional frames, and other frame miscellanea
460 (defun modify-all-frames-parameters (alist)
461 "Modify all current and future frames' parameters according to ALIST.
462 This changes `default-frame-alist' and possibly `initial-frame-alist'.
463 Furthermore, this function removes all parameters in ALIST from
464 `window-system-default-frame-alist'.
465 See help of `modify-frame-parameters' for more information."
466 (dolist (frame (frame-list))
467 (modify-frame-parameters frame alist
))
469 (dolist (pair alist
) ;; conses to add/replace
470 ;; initial-frame-alist needs setting only when
471 ;; frame-notice-user-settings is true.
472 (and frame-notice-user-settings
473 (setq initial-frame-alist
474 (assq-delete-all (car pair
) initial-frame-alist
)))
475 (setq default-frame-alist
476 (assq-delete-all (car pair
) default-frame-alist
))
477 ;; Remove any similar settings from the window-system specific
478 ;; parameters---they would override default-frame-alist.
479 (dolist (w window-system-default-frame-alist
)
480 (setcdr w
(assq-delete-all (car pair
) (cdr w
)))))
482 (and frame-notice-user-settings
483 (setq initial-frame-alist
(append initial-frame-alist alist
)))
484 (setq default-frame-alist
(append default-frame-alist alist
)))
486 (defun get-other-frame ()
487 "Return some frame other than the current frame.
488 Create one if necessary. Note that the minibuffer frame, if separate,
489 is not considered (see `next-frame')."
490 (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
492 (next-frame (selected-frame)))))
495 (defun next-multiframe-window ()
496 "Select the next window, regardless of which frame it is on."
498 (select-window (next-window (selected-window)
499 (> (minibuffer-depth) 0)
501 (select-frame-set-input-focus (selected-frame)))
503 (defun previous-multiframe-window ()
504 "Select the previous window, regardless of which frame it is on."
506 (select-window (previous-window (selected-window)
507 (> (minibuffer-depth) 0)
509 (select-frame-set-input-focus (selected-frame)))
511 (declare-function x-initialize-window-system
"term/x-win" ())
512 (declare-function ns-initialize-window-system
"term/ns-win" ())
513 (defvar x-display-name
) ; term/x-win
515 (defun make-frame-on-display (display &optional parameters
)
516 "Make a frame on display DISPLAY.
517 The optional argument PARAMETERS specifies additional frame parameters."
518 (interactive "sMake frame on display: ")
519 (cond ((featurep 'ns
)
520 (when (and (boundp 'ns-initialized
) (not ns-initialized
))
521 (setq x-display-name display
)
522 (ns-initialize-window-system))
523 (make-frame `((window-system . ns
)
524 (display .
,display
) .
,parameters
)))
525 ((eq system-type
'windows-nt
)
526 ;; On Windows, ignore DISPLAY.
527 (make-frame parameters
))
529 (unless (string-match-p "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display
)
530 (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
531 (when (and (boundp 'x-initialized
) (not x-initialized
))
532 (setq x-display-name display
)
533 (x-initialize-window-system))
534 (make-frame `((window-system . x
)
535 (display .
,display
) .
,parameters
)))))
537 (declare-function x-close-connection
"xfns.c" (terminal))
539 (defun close-display-connection (display)
540 "Close the connection to a display, deleting all its associated frames.
541 For DISPLAY, specify either a frame or a display name (a string).
542 If DISPLAY is nil, that stands for the selected frame's display."
545 (let* ((default (frame-parameter nil
'display
))
546 (display (completing-read
547 (format "Close display (default %s): " default
)
549 (mapcar (lambda (frame)
550 (frame-parameter frame
'display
))
554 (if (zerop (length display
)) default display
))))
555 (let ((frames (delq nil
556 (mapcar (lambda (frame)
558 (frame-parameter frame
'display
))
561 (if (and (consp frames
)
562 (not (y-or-n-p (if (cdr frames
)
563 (format "Delete %s frames? " (length frames
))
564 (format "Delete %s ? " (car frames
))))))
566 (mapc 'delete-frame frames
)
567 (x-close-connection display
))))
569 (defun make-frame-command ()
570 "Make a new frame, on the same terminal as the selected frame.
571 If the terminal is a text-only terminal, this also selects the
574 (if (display-graphic-p)
576 (select-frame (make-frame))))
578 (defvar before-make-frame-hook nil
579 "Functions to run before a frame is created.")
581 (defvar after-make-frame-functions nil
582 "Functions to run after a frame is created.
583 The functions are run with one arg, the newly created frame.")
585 (defvar after-setting-font-hook nil
586 "Functions to run after a frame's font has been changed.")
588 ;; Alias, kept temporarily.
589 (define-obsolete-function-alias 'new-frame
'make-frame
"22.1")
591 (defvar frame-inherited-parameters
'()
592 ;; FIXME: Shouldn't we add `font' here as well?
593 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
595 (defun make-frame (&optional parameters
)
596 "Return a newly created frame displaying the current buffer.
597 Optional argument PARAMETERS is an alist of frame parameters for
598 the new frame. Each element of PARAMETERS should have the
599 form (NAME . VALUE), for example:
601 (name . STRING) The frame should be named STRING.
603 (width . NUMBER) The frame should be NUMBER characters in width.
604 (height . NUMBER) The frame should be NUMBER text lines high.
606 You cannot specify either `width' or `height', you must specify
609 (minibuffer . t) The frame should have a minibuffer.
610 (minibuffer . nil) The frame should have no minibuffer.
611 (minibuffer . only) The frame should contain only a minibuffer.
612 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
614 (window-system . nil) The frame should be displayed on a terminal device.
615 (window-system . x) The frame should be displayed in an X window.
617 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
619 In addition, any parameter specified in `default-frame-alist',
620 but not present in PARAMETERS, is applied.
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.
627 On graphical displays, this function does not itself make the new
628 frame the selected frame. However, the window system may select
629 the new frame according to its own rules."
632 ((assq 'terminal parameters
)
633 (let ((type (terminal-live-p (cdr (assq 'terminal parameters
)))))
636 ((eq type nil
) (error "Terminal %s does not exist"
637 (cdr (assq 'terminal parameters
))))
639 ((assq 'window-system parameters
)
640 (cdr (assq 'window-system parameters
)))
642 (frame-creation-function (cdr (assq w frame-creation-function-alist
)))
643 (oldframe (selected-frame))
646 (unless frame-creation-function
647 (error "Don't know how to create a frame on window system %s" w
))
648 ;; Add parameters from `window-system-default-frame-alist'.
649 (dolist (p (cdr (assq w window-system-default-frame-alist
)))
650 (unless (assq (car p
) params
)
652 ;; Add parameters from `default-frame-alist'.
653 (dolist (p default-frame-alist
)
654 (unless (assq (car p
) params
)
656 ;; Now make the frame.
657 (run-hooks 'before-make-frame-hook
)
658 (setq frame
(funcall frame-creation-function params
))
659 (normal-erase-is-backspace-setup-frame frame
)
660 ;; Inherit the original frame's parameters.
661 (dolist (param frame-inherited-parameters
)
662 (unless (assq param parameters
) ;Overridden by explicit parameters.
663 (let ((val (frame-parameter oldframe param
)))
664 (when val
(set-frame-parameter frame param val
)))))
665 (run-hook-with-args 'after-make-frame-functions frame
)
668 (defun filtered-frame-list (predicate)
669 "Return a list of all live frames which satisfy PREDICATE."
670 (let* ((frames (frame-list))
672 (while (consp frames
)
673 (unless (funcall predicate
(car frames
))
675 (setq frames
(cdr frames
)))
678 (defun minibuffer-frame-list ()
679 "Return a list of all frames with their own minibuffers."
682 (eq frame
(window-frame (minibuffer-window frame
))))))
684 ;; Used to be called `terminal-id' in termdev.el.
685 (defun get-device-terminal (device)
686 "Return the terminal corresponding to DEVICE.
687 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
688 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
690 ((or (null device
) (framep device
))
691 (frame-terminal device
))
693 (let ((f (car (filtered-frame-list
695 (or (equal (frame-parameter frame
'display
) device
)
696 (equal (frame-parameter frame
'tty
) device
)))))))
697 (or f
(error "Display %s does not exist" device
))
699 ((terminal-live-p device
) device
)
701 (error "Invalid argument %s in `get-device-terminal'" device
))))
703 (defun frames-on-display-list (&optional device
)
704 "Return a list of all frames on DEVICE.
706 DEVICE should be a terminal, a frame,
707 or a name of an X display or tty (a string of the form
710 If DEVICE is omitted or nil, it defaults to the selected
711 frame's terminal device."
712 (let* ((terminal (get-device-terminal device
))
713 (func #'(lambda (frame)
714 (eq (frame-terminal frame
) terminal
))))
715 (filtered-frame-list func
)))
717 (defun framep-on-display (&optional terminal
)
718 "Return the type of frames on TERMINAL.
719 TERMINAL may be a terminal id, a display name or a frame. If it
720 is a frame, its type is returned. If TERMINAL is omitted or nil,
721 it defaults to the selected frame's terminal device. All frames
722 on a given display are of the same type."
723 (or (terminal-live-p terminal
)
725 (framep (car (frames-on-display-list terminal
)))))
727 (defun frame-remove-geometry-params (param-list)
728 "Return the parameter list PARAM-LIST, but with geometry specs removed.
729 This deletes all bindings in PARAM-LIST for `top', `left', `width',
730 `height', `user-size' and `user-position' parameters.
731 Emacs uses this to avoid overriding explicit moves and resizings from
732 the user during startup."
733 (setq param-list
(cons nil param-list
))
734 (let ((tail param-list
))
735 (while (consp (cdr tail
))
736 (if (and (consp (car (cdr tail
)))
737 (memq (car (car (cdr tail
)))
738 '(height width top left user-position user-size
)))
740 (setq frame-initial-geometry-arguments
741 (cons (car (cdr tail
)) frame-initial-geometry-arguments
))
742 (setcdr tail
(cdr (cdr tail
))))
743 (setq tail
(cdr tail
)))))
744 (setq frame-initial-geometry-arguments
745 (nreverse frame-initial-geometry-arguments
))
748 (declare-function x-focus-frame
"xfns.c" (frame))
750 (defun select-frame-set-input-focus (frame &optional norecord
)
751 "Select FRAME, raise it, and set input focus, if possible.
752 If `mouse-autoselect-window' is non-nil, also move mouse pointer
753 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
754 is non-nil, move mouse cursor to FRAME.
756 Optional argument NORECORD means to neither change the order of
757 recently selected windows nor the buffer list."
758 (select-frame frame norecord
)
760 ;; Ensure, if possible, that FRAME gets input focus.
761 (when (memq (window-system frame
) '(x w32 ns
))
762 (x-focus-frame frame
))
763 ;; Move mouse cursor if necessary.
765 (mouse-autoselect-window
766 (let ((edges (window-inside-edges (frame-selected-window frame
))))
767 ;; Move mouse cursor into FRAME's selected window to avoid that
768 ;; Emacs mouse-autoselects another window.
769 (set-mouse-position frame
(nth 2 edges
) (nth 1 edges
))))
771 ;; Move mouse cursor into FRAME to avoid that another frame gets
772 ;; selected by the window manager.
773 (set-mouse-position frame
(1- (frame-width frame
)) 0))))
775 (defun other-frame (arg)
776 "Select the ARGth different visible frame on current display, and raise it.
777 All frames are arranged in a cyclic order.
778 This command selects the frame ARG steps away in that order.
779 A negative ARG moves in the opposite order.
781 To make this command work properly, you must tell Emacs
782 how the system (or the window manager) generally handles
783 focus-switching between windows. If moving the mouse onto a window
784 selects it (gives it focus), set `focus-follows-mouse' to t.
785 Otherwise, that variable should be nil."
787 (let ((frame (selected-frame)))
789 (setq frame
(next-frame frame
))
790 (while (not (eq (frame-visible-p frame
) t
))
791 (setq frame
(next-frame frame
)))
794 (setq frame
(previous-frame frame
))
795 (while (not (eq (frame-visible-p frame
) t
))
796 (setq frame
(previous-frame frame
)))
798 (select-frame-set-input-focus frame
)))
800 (defun iconify-or-deiconify-frame ()
801 "Iconify the selected frame, or deiconify if it's currently an icon."
803 (if (eq (cdr (assq 'visibility
(frame-parameters))) t
)
805 (make-frame-visible)))
807 (defun suspend-frame ()
808 "Do whatever is right to suspend the current frame.
809 Calls `suspend-emacs' if invoked from the controlling tty device,
810 `suspend-tty' from a secondary tty device, and
811 `iconify-or-deiconify-frame' from an X frame."
813 (let ((type (framep (selected-frame))))
815 ((memq type
'(x ns w32
)) (iconify-or-deiconify-frame))
817 (if (controlling-tty-p)
820 (t (suspend-emacs)))))
822 (defun make-frame-names-alist ()
823 ;; Only consider the frames on the same display.
824 (let* ((current-frame (selected-frame))
827 (cons (frame-parameter current-frame
'name
) current-frame
) nil
))
828 (frame (next-frame nil
0)))
829 (while (not (eq frame current-frame
))
831 (push (cons (frame-parameter frame
'name
) frame
) falist
)
832 (setq frame
(next-frame frame
0))))
835 (defvar frame-name-history nil
)
836 (defun select-frame-by-name (name)
837 "Select the frame on the current terminal whose name is NAME and raise it.
838 If there is no frame by that name, signal an error."
840 (let* ((frame-names-alist (make-frame-names-alist))
841 (default (car (car frame-names-alist
)))
842 (input (completing-read
843 (format "Select Frame (default %s): " default
)
844 frame-names-alist nil t nil
'frame-name-history
)))
845 (if (= (length input
) 0)
848 (let* ((frame-names-alist (make-frame-names-alist))
849 (frame (cdr (assoc name frame-names-alist
))))
851 (select-frame-set-input-focus frame
)
852 (error "There is no frame named `%s'" name
))))
855 ;;;; Background mode.
857 (defcustom frame-background-mode nil
858 "The brightness of the background.
859 Set this to the symbol `dark' if your background color is dark,
860 `light' if your background is light, or nil (automatic by default)
861 if you want Emacs to examine the brightness for you. Don't set this
862 variable with `setq'; this won't have the expected effect."
864 :set
#'(lambda (var value
)
865 (set-default var value
)
866 (mapc 'frame-set-background-mode
(frame-list)))
867 :initialize
'custom-initialize-changed
868 :type
'(choice (const dark
)
870 (const :tag
"automatic" nil
)))
872 (declare-function x-get-resource
"frame.c"
873 (attribute class
&optional component subclass
))
875 (defvar inhibit-frame-set-background-mode nil
)
877 (defun frame-set-background-mode (frame &optional keep-face-specs
)
878 "Set up display-dependent faces on FRAME.
879 Display-dependent faces are those which have different definitions
880 according to the `background-mode' and `display-type' frame parameters.
882 If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
883 face specs for the new background mode."
884 (unless inhibit-frame-set-background-mode
885 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame
))
886 (bg-color (frame-parameter frame
'background-color
))
887 (tty-type (tty-type frame
))
889 (if (or (window-system frame
)
891 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
895 (non-default-bg-mode (if (eq default-bg-mode
'light
) 'dark
'light
))
897 (cond (frame-default-bg-mode)
898 ((equal bg-color
"unspecified-fg") ; inverted colors
900 ((not (color-values bg-color frame
))
902 ((>= (apply '+ (color-values bg-color frame
))
903 ;; Just looking at the screen, colors whose
904 ;; values add up to .6 of the white total
905 ;; still look dark to me.
906 (* (apply '+ (color-values "white" frame
)) .6))
910 (cond ((null (window-system frame
))
911 (if (tty-display-color-p frame
) 'color
'mono
))
912 ((display-color-p frame
)
914 ((x-display-grayscale-p frame
)
918 (frame-parameter frame
'background-mode
))
920 (frame-parameter frame
'display-type
)))
922 (unless (and (eq bg-mode old-bg-mode
) (eq display-type old-display-type
))
923 (let ((locally-modified-faces nil
)
924 ;; Prevent face-spec-recalc from calling this function
925 ;; again, resulting in a loop (bug#911).
926 (inhibit-frame-set-background-mode t
)
927 (params (list (cons 'background-mode bg-mode
)
928 (cons 'display-type display-type
))))
930 (modify-frame-parameters frame params
)
931 ;; If we are recomputing face specs, first collect a list
932 ;; of faces that don't match their face-specs. These are
933 ;; the faces modified on FRAME, and we avoid changing them
934 ;; below. Use a negative list to avoid consing (we assume
935 ;; most faces are unmodified).
936 (dolist (face (face-list))
937 (and (not (get face
'face-override-spec
))
938 (not (face-spec-match-p face
939 (face-user-default-spec face
)
941 (push face locally-modified-faces
)))
942 ;; Now change to the new frame parameters
943 (modify-frame-parameters frame params
)
944 ;; For all unmodified named faces, choose face specs
945 ;; matching the new frame parameters.
946 (dolist (face (face-list))
947 (unless (memq face locally-modified-faces
)
948 (face-spec-recalc face frame
)))))))))
950 (defun frame-terminal-default-bg-mode (frame)
951 "Return the default background mode of FRAME.
952 This checks the `frame-background-mode' variable, the X resource
953 named \"backgroundMode\" (if FRAME is an X frame), and finally
954 the `background-mode' terminal parameter."
955 (or frame-background-mode
957 (and (window-system frame
)
958 (x-get-resource "backgroundMode" "BackgroundMode"))))
960 (intern (downcase bg-resource
))))
961 (terminal-parameter frame
'background-mode
)))
964 ;;;; Frame configurations
966 (defun current-frame-configuration ()
967 "Return a list describing the positions and states of all frames.
968 Its car is `frame-configuration'.
969 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
971 FRAME is a frame object,
972 ALIST is an association list specifying some of FRAME's parameters, and
973 WINDOW-CONFIG is a window configuration object for FRAME."
974 (cons 'frame-configuration
975 (mapcar (lambda (frame)
977 (frame-parameters frame
)
978 (current-window-configuration frame
)))
981 (defun set-frame-configuration (configuration &optional nodelete
)
982 "Restore the frames to the state described by CONFIGURATION.
983 Each frame listed in CONFIGURATION has its position, size, window
984 configuration, and other parameters set as specified in CONFIGURATION.
985 However, this function does not restore deleted frames.
987 Ordinarily, this function deletes all existing frames not
988 listed in CONFIGURATION. But if optional second argument NODELETE
989 is given and non-nil, the unwanted frames are iconified instead."
990 (or (frame-configuration-p configuration
)
991 (signal 'wrong-type-argument
992 (list 'frame-configuration-p configuration
)))
993 (let ((config-alist (cdr configuration
))
995 (dolist (frame (frame-list))
996 (let ((parameters (assq frame config-alist
)))
999 (modify-frame-parameters
1001 ;; Since we can't set a frame's minibuffer status,
1002 ;; we might as well omit the parameter altogether.
1003 (let* ((parms (nth 1 parameters
))
1004 (mini (assq 'minibuffer parms
))
1005 (name (assq 'name parms
))
1006 (explicit-name (cdr (assq 'explicit-name parms
))))
1007 (when mini
(setq parms
(delq mini parms
)))
1008 ;; Leave name in iff it was set explicitly.
1009 ;; This should fix the behavior reported in
1010 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
1011 (when (and name
(not explicit-name
))
1012 (setq parms
(delq name parms
)))
1014 (set-window-configuration (nth 2 parameters
)))
1015 (setq frames-to-delete
(cons frame frames-to-delete
)))))
1017 ;; Note: making frames invisible here was tried
1018 ;; but led to some strange behavior--each time the frame
1019 ;; was made visible again, the window manager asked afresh
1020 ;; for where to put it.
1025 ;;;; Convenience functions for accessing and interactively changing
1026 ;;;; frame parameters.
1028 (defun frame-height (&optional frame
)
1029 "Return number of lines available for display on FRAME.
1030 If FRAME is omitted, describe the currently selected frame.
1031 Exactly what is included in the return value depends on the
1032 window-system and toolkit in use - see `frame-pixel-height' for
1033 more details. The lines are in units of the default font height.
1035 The result is roughly related to the frame pixel height via
1036 height in pixels = height in lines * `frame-char-height'.
1037 However, this is only approximate, and is complicated e.g. by the
1038 fact that individual window lines and menu bar lines can have
1039 differing font heights."
1040 (cdr (assq 'height
(frame-parameters frame
))))
1042 (defun frame-width (&optional frame
)
1043 "Return number of columns available for display on FRAME.
1044 If FRAME is omitted, describe the currently selected frame."
1045 (cdr (assq 'width
(frame-parameters frame
))))
1047 (declare-function x-list-fonts
"xfaces.c"
1048 (pattern &optional face frame maximum width
))
1050 (define-obsolete-function-alias 'set-default-font
'set-frame-font
"23.1")
1051 (defun set-frame-font (font-name &optional keep-size
)
1052 "Set the font of the selected frame to FONT-NAME.
1053 When called interactively, prompt for the name of the font to use.
1054 To get the frame's current default font, use `frame-parameters'.
1056 The default behavior is to keep the numbers of lines and columns in
1057 the frame, thus may change its pixel size. If optional KEEP-SIZE is
1058 non-nil (interactively, prefix argument) the current frame size (in
1059 pixels) is kept by adjusting the numbers of the lines and columns."
1061 (let* ((completion-ignore-case t
)
1062 (font (completing-read "Font name: "
1063 ;; x-list-fonts will fail with an error
1064 ;; if this frame doesn't support fonts.
1065 (x-list-fonts "*" nil
(selected-frame))
1067 (frame-parameter nil
'font
))))
1068 (list font current-prefix-arg
)))
1071 (setq fht
(* (frame-parameter nil
'height
) (frame-char-height))
1072 fwd
(* (frame-parameter nil
'width
) (frame-char-width))))
1073 (modify-frame-parameters (selected-frame)
1074 (list (cons 'font font-name
)))
1076 (modify-frame-parameters
1078 (list (cons 'height
(round fht
(frame-char-height)))
1079 (cons 'width
(round fwd
(frame-char-width)))))))
1080 (run-hooks 'after-setting-font-hook
'after-setting-font-hooks
))
1082 (defun set-frame-parameter (frame parameter value
)
1083 "Set frame parameter PARAMETER to VALUE on FRAME.
1084 If FRAME is nil, it defaults to the selected frame.
1085 See `modify-frame-parameters'."
1086 (modify-frame-parameters frame
(list (cons parameter value
))))
1088 (defun set-background-color (color-name)
1089 "Set the background 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 background color, use `frame-parameters'."
1092 (interactive (list (read-color "Background color: ")))
1093 (modify-frame-parameters (selected-frame)
1094 (list (cons 'background-color color-name
)))
1096 (face-set-after-frame-default (selected-frame))))
1098 (defun set-foreground-color (color-name)
1099 "Set the foreground color of the selected frame to COLOR-NAME.
1100 When called interactively, prompt for the name of the color to use.
1101 To get the frame's current foreground color, use `frame-parameters'."
1102 (interactive (list (read-color "Foreground color: ")))
1103 (modify-frame-parameters (selected-frame)
1104 (list (cons 'foreground-color color-name
)))
1106 (face-set-after-frame-default (selected-frame))))
1108 (defun set-cursor-color (color-name)
1109 "Set the text cursor color of the selected frame to COLOR-NAME.
1110 When called interactively, prompt for the name of the color to use.
1111 To get the frame's current cursor color, use `frame-parameters'."
1112 (interactive (list (read-color "Cursor color: ")))
1113 (modify-frame-parameters (selected-frame)
1114 (list (cons 'cursor-color color-name
))))
1116 (defun set-mouse-color (color-name)
1117 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1118 When called interactively, prompt for the name of the color to use.
1119 To get the frame's current mouse color, use `frame-parameters'."
1120 (interactive (list (read-color "Mouse color: ")))
1121 (modify-frame-parameters (selected-frame)
1122 (list (cons 'mouse-color
1124 (cdr (assq 'mouse-color
1125 (frame-parameters))))))))
1127 (defun set-border-color (color-name)
1128 "Set the color of the border of the selected frame to COLOR-NAME.
1129 When called interactively, prompt for the name of the color to use.
1130 To get the frame's current border color, use `frame-parameters'."
1131 (interactive (list (read-color "Border color: ")))
1132 (modify-frame-parameters (selected-frame)
1133 (list (cons 'border-color color-name
))))
1135 (define-minor-mode auto-raise-mode
1136 "Toggle whether or not selected frames should auto-raise.
1137 With a prefix argument ARG, enable Auto Raise mode if ARG is
1138 positive, and disable it otherwise. If called from Lisp, enable
1139 the mode if ARG is omitted or nil.
1141 Auto Raise mode does nothing under most window managers, which
1142 switch focus on mouse clicks. It only has an effect if your
1143 window manager switches focus on mouse movement (in which case
1144 you should also change `focus-follows-mouse' to t). Then,
1145 enabling Auto Raise mode causes any graphical Emacs frame which
1146 acquires focus to be automatically raised.
1148 Note that this minor mode controls Emacs's own auto-raise
1149 feature. Window managers that switch focus on mouse movement
1150 often have their own auto-raise feature."
1151 :variable
(frame-parameter nil
'auto-raise
)
1152 (if (frame-parameter nil
'auto-raise
)
1155 (define-minor-mode auto-lower-mode
1156 "Toggle whether or not the selected frame should auto-lower.
1157 With a prefix argument ARG, enable Auto Lower mode if ARG is
1158 positive, and disable it otherwise. If called from Lisp, enable
1159 the mode if ARG is omitted or nil.
1161 Auto Lower mode does nothing under most window managers, which
1162 switch focus on mouse clicks. It only has an effect if your
1163 window manager switches focus on mouse movement (in which case
1164 you should also change `focus-follows-mouse' to t). Then,
1165 enabling Auto Lower Mode causes any graphical Emacs frame which
1166 loses focus to be automatically lowered.
1168 Note that this minor mode controls Emacs's own auto-lower
1169 feature. Window managers that switch focus on mouse movement
1170 often have their own features for raising or lowering frames."
1171 :variable
(frame-parameter nil
'auto-lower
))
1173 (defun set-frame-name (name)
1174 "Set the name of the selected frame to NAME.
1175 When called interactively, prompt for the name of the frame.
1176 The frame name is displayed on the modeline if the terminal displays only
1177 one frame, otherwise the name is displayed on the frame's caption bar."
1178 (interactive "sFrame name: ")
1179 (modify-frame-parameters (selected-frame)
1180 (list (cons 'name name
))))
1182 (defun frame-current-scroll-bars (&optional frame
)
1183 "Return the current scroll-bar settings in frame FRAME.
1184 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1185 current location of the vertical scroll-bars (left, right, or nil),
1186 and HORIZONTAL specifies the current location of the horizontal scroll
1187 bars (top, bottom, or nil)."
1188 (let ((vert (frame-parameter frame
'vertical-scroll-bars
))
1190 (unless (memq vert
'(left right nil
))
1191 (setq vert default-frame-scroll-bars
))
1194 ;;;; Frame/display capabilities.
1195 (defun selected-terminal ()
1196 "Return the terminal that is now selected."
1197 (frame-terminal (selected-frame)))
1199 (declare-function msdos-mouse-p
"dosfns.c")
1201 (defun display-mouse-p (&optional display
)
1202 "Return non-nil if DISPLAY has a mouse available.
1203 DISPLAY can be a display name, a frame, or nil (meaning the selected
1205 (let ((frame-type (framep-on-display display
)))
1207 ((eq frame-type
'pc
)
1209 ((eq system-type
'windows-nt
)
1211 (> w32-num-mouse-buttons
0)))
1212 ((memq frame-type
'(x ns
))
1213 t
) ;; We assume X and NeXTstep *always* have a pointing device
1215 (or (and (featurep 'xt-mouse
)
1217 ;; t-mouse is distributed with the GPM package. It doesn't have
1219 (featurep 't-mouse
))))))
1221 (defun display-popup-menus-p (&optional display
)
1222 "Return non-nil if popup menus are supported on DISPLAY.
1223 DISPLAY can be a display name, a frame, or nil (meaning the selected
1225 Support for popup menus requires that the mouse be available."
1227 (let ((frame-type (framep-on-display display
)))
1228 (memq frame-type
'(x w32 pc ns
)))
1229 (display-mouse-p display
)))
1231 (defun display-graphic-p (&optional display
)
1232 "Return non-nil if DISPLAY is a graphic display.
1233 Graphical displays are those which are capable of displaying several
1234 frames and several different fonts at once. This is true for displays
1235 that use a window system such as X, and false for text-only terminals.
1236 DISPLAY can be a display name, a frame, or nil (meaning the selected
1238 (not (null (memq (framep-on-display display
) '(x w32 ns
)))))
1240 (defun display-images-p (&optional display
)
1241 "Return non-nil if DISPLAY can display images.
1243 DISPLAY can be a display name, a frame, or nil (meaning the selected
1245 (and (display-graphic-p display
)
1246 (fboundp 'image-mask-p
)
1247 (fboundp 'image-size
)))
1249 (defalias 'display-multi-frame-p
'display-graphic-p
)
1250 (defalias 'display-multi-font-p
'display-graphic-p
)
1252 (defun display-selections-p (&optional display
)
1253 "Return non-nil if DISPLAY supports selections.
1254 A selection is a way to transfer text or other data between programs
1255 via special system buffers called `selection' or `clipboard'.
1256 DISPLAY can be a display name, a frame, or nil (meaning the selected
1258 (let ((frame-type (framep-on-display display
)))
1260 ((eq frame-type
'pc
)
1261 ;; MS-DOG frames support selections when Emacs runs inside
1262 ;; the Windows' DOS Box.
1264 (not (null dos-windows-version
))))
1265 ((memq frame-type
'(x w32 ns
))
1270 (declare-function x-display-screens
"xfns.c" (&optional terminal
))
1272 (defun display-screens (&optional display
)
1273 "Return the number of screens associated with DISPLAY."
1274 (let ((frame-type (framep-on-display display
)))
1276 ((memq frame-type
'(x w32 ns
))
1277 (x-display-screens display
))
1281 (declare-function x-display-pixel-height
"xfns.c" (&optional terminal
))
1283 (defun display-pixel-height (&optional display
)
1284 "Return the height of DISPLAY's screen in pixels.
1285 For character terminals, each character counts as a single pixel."
1286 (let ((frame-type (framep-on-display display
)))
1288 ((memq frame-type
'(x w32 ns
))
1289 (x-display-pixel-height display
))
1291 (frame-height (if (framep display
) display
(selected-frame)))))))
1293 (declare-function x-display-pixel-width
"xfns.c" (&optional terminal
))
1295 (defun display-pixel-width (&optional display
)
1296 "Return the width of DISPLAY's screen in pixels.
1297 For character terminals, each character counts as a single pixel."
1298 (let ((frame-type (framep-on-display display
)))
1300 ((memq frame-type
'(x w32 ns
))
1301 (x-display-pixel-width display
))
1303 (frame-width (if (framep display
) display
(selected-frame)))))))
1305 (defcustom display-mm-dimensions-alist nil
1306 "Alist for specifying screen dimensions in millimeters.
1307 The dimensions will be used for `display-mm-height' and
1308 `display-mm-width' if defined for the respective display.
1310 Each element of the alist has the form (display . (width . height)),
1311 e.g. (\":0.0\" . (287 . 215)).
1313 If `display' equals t, it specifies dimensions for all graphical
1314 displays not explicitly specified."
1316 :type
'(alist :key-type
(choice (string :tag
"Display name")
1317 (const :tag
"Default" t
))
1318 :value-type
(cons :tag
"Dimensions"
1319 (integer :tag
"Width")
1320 (integer :tag
"Height")))
1323 (declare-function x-display-mm-height
"xfns.c" (&optional terminal
))
1325 (defun display-mm-height (&optional display
)
1326 "Return the height of DISPLAY's screen in millimeters.
1327 System values can be overridden by `display-mm-dimensions-alist'.
1328 If the information is unavailable, value is nil."
1329 (and (memq (framep-on-display display
) '(x w32 ns
))
1330 (or (cddr (assoc (or display
(frame-parameter nil
'display
))
1331 display-mm-dimensions-alist
))
1332 (cddr (assoc t display-mm-dimensions-alist
))
1333 (x-display-mm-height display
))))
1335 (declare-function x-display-mm-width
"xfns.c" (&optional terminal
))
1337 (defun display-mm-width (&optional display
)
1338 "Return the width of DISPLAY's screen in millimeters.
1339 System values can be overridden by `display-mm-dimensions-alist'.
1340 If the information is unavailable, value is nil."
1341 (and (memq (framep-on-display display
) '(x w32 ns
))
1342 (or (cadr (assoc (or display
(frame-parameter nil
'display
))
1343 display-mm-dimensions-alist
))
1344 (cadr (assoc t display-mm-dimensions-alist
))
1345 (x-display-mm-width display
))))
1347 (declare-function x-display-backing-store
"xfns.c" (&optional terminal
))
1349 (defun display-backing-store (&optional display
)
1350 "Return the backing store capability of DISPLAY's screen.
1351 The value may be `always', `when-mapped', `not-useful', or nil if
1352 the question is inapplicable to a certain kind of display."
1353 (let ((frame-type (framep-on-display display
)))
1355 ((memq frame-type
'(x w32 ns
))
1356 (x-display-backing-store display
))
1360 (declare-function x-display-save-under
"xfns.c" (&optional terminal
))
1362 (defun display-save-under (&optional display
)
1363 "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
1364 (let ((frame-type (framep-on-display display
)))
1366 ((memq frame-type
'(x w32 ns
))
1367 (x-display-save-under display
))
1371 (declare-function x-display-planes
"xfns.c" (&optional terminal
))
1373 (defun display-planes (&optional display
)
1374 "Return the number of planes supported by DISPLAY."
1375 (let ((frame-type (framep-on-display display
)))
1377 ((memq frame-type
'(x w32 ns
))
1378 (x-display-planes display
))
1379 ((eq frame-type
'pc
)
1382 (truncate (log (length (tty-color-alist)) 2))))))
1384 (declare-function x-display-color-cells
"xfns.c" (&optional terminal
))
1386 (defun display-color-cells (&optional display
)
1387 "Return the number of color cells supported by DISPLAY."
1388 (let ((frame-type (framep-on-display display
)))
1390 ((memq frame-type
'(x w32 ns
))
1391 (x-display-color-cells display
))
1392 ((eq frame-type
'pc
)
1395 (tty-display-color-cells display
)))))
1397 (declare-function x-display-visual-class
"xfns.c" (&optional terminal
))
1399 (defun display-visual-class (&optional display
)
1400 "Return the visual class of DISPLAY.
1401 The value is one of the symbols `static-gray', `gray-scale',
1402 `static-color', `pseudo-color', `true-color', or `direct-color'."
1403 (let ((frame-type (framep-on-display display
)))
1405 ((memq frame-type
'(x w32 ns
))
1406 (x-display-visual-class display
))
1407 ((and (memq frame-type
'(pc t
))
1408 (tty-display-color-p display
))
1414 ;;;; Frame geometry values
1416 (defun frame-geom-value-cons (type value
&optional frame
)
1417 "Return equivalent geometry value for FRAME as a cons with car `+'.
1418 A geometry value equivalent to VALUE for FRAME is returned,
1419 where the value is a cons with car `+', not numeric.
1420 TYPE is the car of the original geometry spec (TYPE . VALUE).
1421 It is `top' or `left', depending on which edge VALUE is related to.
1422 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1423 If VALUE is a number, then it is converted to a cons value, perhaps
1424 relative to the opposite frame edge from that in the original spec.
1425 FRAME defaults to the selected frame.
1427 Examples (measures in pixels) -
1428 Assuming display height/width=1024, frame height/width=600:
1429 300 inside display edge: 300 => (+ 300)
1431 300 inside opposite display edge: (- 300) => (+ 124)
1433 300 beyond display edge
1434 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1435 300 beyond display edge
1436 (= 724 inside opposite display edge): (- -300) => (+ 724)
1438 In the 3rd, 4th, and 6th examples, the returned value is relative to
1439 the opposite frame edge from the edge indicated in the input spec."
1440 (cond ((and (consp value
) (eq '+ (car value
))) ; e.g. (+ 300), (+ -300)
1442 ((natnump value
) (list '+ value
)) ; e.g. 300 => (+ 300)
1443 (t ; e.g. -300, (- 300), (- -300)
1444 (list '+ (- (if (eq 'left type
) ; => (+ 124), (+ 124), (+ 724)
1445 (x-display-pixel-width)
1446 (x-display-pixel-height))
1447 (if (integerp value
) (- value
) (cadr value
))
1449 (frame-pixel-width frame
)
1450 (frame-pixel-height frame
)))))))
1452 (defun frame-geom-spec-cons (spec &optional frame
)
1453 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1454 A geometry specification equivalent to SPEC for FRAME is returned,
1455 where the value is a cons with car `+', not numeric.
1456 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1457 If VALUE is a number, then it is converted to a cons value, perhaps
1458 relative to the opposite frame edge from that in the original spec.
1459 FRAME defaults to the selected frame.
1461 Examples (measures in pixels) -
1462 Assuming display height=1024, frame height=600:
1463 top 300 below display top: (top . 300) => (top + 300)
1464 (top + 300) => (top + 300)
1465 bottom 300 above display bottom: (top - 300) => (top + 124)
1466 (top . -300) => (top + 124)
1467 top 300 above display top
1468 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1469 bottom 300 below display bottom
1470 (= top 724 below display top): (top - -300) => (top + 724)
1472 In the 3rd, 4th, and 6th examples, the returned value is relative to
1473 the opposite frame edge from the edge indicated in the input spec."
1474 (cons (car spec
) (frame-geom-value-cons (car spec
) (cdr spec
) frame
)))
1477 (defun delete-other-frames (&optional frame
)
1478 "Delete all frames on the current terminal, except FRAME.
1479 If FRAME uses another frame's minibuffer, the minibuffer frame is
1480 left untouched. FRAME nil or omitted means use the selected frame."
1483 (setq frame
(selected-frame)))
1484 (let* ((mini-frame (window-frame (minibuffer-window frame
)))
1485 (frames (delq mini-frame
(delq frame
(frame-list)))))
1486 ;; Only consider frames on the same terminal.
1487 (dolist (frame (prog1 frames
(setq frames nil
)))
1488 (if (eq (frame-terminal) (frame-terminal frame
))
1489 (push frame frames
)))
1490 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1491 ;; signals an error when trying to delete a mini-frame that's
1492 ;; still in use by another frame.
1493 (dolist (frame frames
)
1494 (unless (eq (frame-parameter frame
'minibuffer
) 'only
)
1495 (delete-frame frame
)))
1496 ;; Delete minibuffer-only frames.
1497 (dolist (frame frames
)
1498 (when (eq (frame-parameter frame
'minibuffer
) 'only
)
1499 (delete-frame frame
)))))
1501 ;; miscellaneous obsolescence declarations
1502 (define-obsolete-variable-alias 'delete-frame-hook
1503 'delete-frame-functions
"22.1")
1506 ;; Highlighting trailing whitespace.
1508 (make-variable-buffer-local 'show-trailing-whitespace
)
1513 (defgroup scrolling nil
1514 "Scrolling windows."
1518 (defvaralias 'automatic-hscrolling
'auto-hscroll-mode
)
1523 (defgroup cursor nil
1524 "Displaying text cursors."
1528 (defcustom blink-cursor-delay
0.5
1529 "Seconds of idle time after which cursor starts to blink."
1533 (defcustom blink-cursor-interval
0.5
1534 "Length of cursor blink interval in seconds."
1538 (defvar blink-cursor-idle-timer nil
1539 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1540 The function `blink-cursor-start' is called when the timer fires.")
1542 (defvar blink-cursor-timer nil
1543 "Timer started from `blink-cursor-start'.
1544 This timer calls `blink-cursor-timer-function' every
1545 `blink-cursor-interval' seconds.")
1547 (defun blink-cursor-start ()
1548 "Timer function called from the timer `blink-cursor-idle-timer'.
1549 This starts the timer `blink-cursor-timer', which makes the cursor blink
1550 if appropriate. It also arranges to cancel that timer when the next
1551 command starts, by installing a pre-command hook."
1552 (when (null blink-cursor-timer
)
1553 ;; Set up the timer first, so that if this signals an error,
1554 ;; blink-cursor-end is not added to pre-command-hook.
1555 (setq blink-cursor-timer
1556 (run-with-timer blink-cursor-interval blink-cursor-interval
1557 'blink-cursor-timer-function
))
1558 (add-hook 'pre-command-hook
'blink-cursor-end
)
1559 (internal-show-cursor nil nil
)))
1561 (defun blink-cursor-timer-function ()
1562 "Timer function of timer `blink-cursor-timer'."
1563 (internal-show-cursor nil
(not (internal-show-cursor-p))))
1565 (defun blink-cursor-end ()
1566 "Stop cursor blinking.
1567 This is installed as a pre-command hook by `blink-cursor-start'.
1568 When run, it cancels the timer `blink-cursor-timer' and removes
1569 itself as a pre-command hook."
1570 (remove-hook 'pre-command-hook
'blink-cursor-end
)
1571 (internal-show-cursor nil t
)
1572 (when blink-cursor-timer
1573 (cancel-timer blink-cursor-timer
)
1574 (setq blink-cursor-timer nil
)))
1576 (define-minor-mode blink-cursor-mode
1577 "Toggle cursor blinking (Blink Cursor mode).
1578 With a prefix argument ARG, enable Blink Cursor mode if ARG is
1579 positive, and disable it otherwise. If called from Lisp, enable
1580 the mode if ARG is omitted or nil.
1582 This command is effective only on graphical frames. On text-only
1583 terminals, cursor blinking is controlled by the terminal."
1584 :init-value
(not (or noninteractive
1586 (eq system-type
'ms-dos
)
1587 (not (memq window-system
'(x w32 ns
)))))
1588 :initialize
'custom-initialize-delay
1591 (if blink-cursor-idle-timer
(cancel-timer blink-cursor-idle-timer
))
1592 (setq blink-cursor-idle-timer nil
)
1594 (when blink-cursor-mode
1596 ;;(internal-show-cursor nil nil)
1597 (setq blink-cursor-idle-timer
1598 (run-with-idle-timer blink-cursor-delay
1600 'blink-cursor-start
))))
1602 (define-obsolete-variable-alias 'blink-cursor
'blink-cursor-mode
"22.1")
1607 (define-key ctl-x-5-map
"2" 'make-frame-command
)
1608 (define-key ctl-x-5-map
"1" 'delete-other-frames
)
1609 (define-key ctl-x-5-map
"0" 'delete-frame
)
1610 (define-key ctl-x-5-map
"o" 'other-frame
)
1614 ;;; frame.el ends here