Reorder conditions that are written backwards
[emacs.git] / lisp / frame.el
blob9a170134e3d8bbb72974aeff9b4b65400704e79f
1 ;;; frame.el --- multi-frame management independent of window systems
3 ;; Copyright (C) 1993-1994, 1996-1997, 2000-2014 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: internal
7 ;; Package: emacs
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
26 ;;; Code:
27 (eval-when-compile (require 'cl-lib))
29 (defvar frame-creation-function-alist
30 (list (cons nil
31 (if (fboundp 'tty-create-frame-with-faces)
32 'tty-create-frame-with-faces
33 (lambda (_parameters)
34 (error "Can't create multiple frames without a window system")))))
35 "Alist of window-system dependent functions to call to create a new frame.
36 The window system startup file should add its frame creation
37 function to this list, which should take an alist of parameters
38 as its argument.")
40 (defvar window-system-default-frame-alist nil
41 "Window-system dependent default frame parameters.
42 The value should be an alist of elements (WINDOW-SYSTEM . ALIST),
43 where WINDOW-SYSTEM is a window system symbol (see `window-system')
44 and ALIST is a frame parameter alist like `default-frame-alist'.
45 Then, for frames on WINDOW-SYSTEM, any parameters specified in
46 ALIST supersede the corresponding parameters specified in
47 `default-frame-alist'.")
49 (defvar display-format-alist nil
50 "Alist of patterns to decode display names.
51 The car of each entry is a regular expression matching a display
52 name string. The cdr is a symbol giving the window-system that
53 handles the corresponding kind of display.")
55 ;; The initial value given here used to ask for a minibuffer.
56 ;; But that's not necessary, because the default is to have one.
57 ;; By not specifying it here, we let an X resource specify it.
58 (defcustom initial-frame-alist nil
59 "Alist of parameters for the initial X window frame.
60 You can set this in your init file; for example,
62 (setq initial-frame-alist
63 '((top . 1) (left . 1) (width . 80) (height . 55)))
65 Parameters specified here supersede the values given in
66 `default-frame-alist'.
68 If the value calls for a frame without a minibuffer, and you have
69 not created a minibuffer frame on your own, a minibuffer frame is
70 created according to `minibuffer-frame-alist'.
72 You can specify geometry-related options for just the initial
73 frame by setting this variable in your init file; however, they
74 won't take effect until Emacs reads your init file, which happens
75 after creating the initial frame. If you want the initial frame
76 to have the proper geometry as soon as it appears, you need to
77 use this three-step process:
78 * Specify X resources to give the geometry you want.
79 * Set `default-frame-alist' to override these options so that they
80 don't affect subsequent frames.
81 * Set `initial-frame-alist' in a way that matches the X resources,
82 to override what you put in `default-frame-alist'."
83 :type '(repeat (cons :format "%v"
84 (symbol :tag "Parameter")
85 (sexp :tag "Value")))
86 :group 'frames)
88 (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
89 "Alist of parameters for the initial minibuffer frame.
90 This is the minibuffer frame created if `initial-frame-alist'
91 calls for a frame without a minibuffer. The parameters specified
92 here supersede those given in `default-frame-alist', for the
93 initial minibuffer frame.
95 You can set this in your init file; for example,
97 (setq minibuffer-frame-alist
98 '((top . 1) (left . 1) (width . 80) (height . 2)))
100 It is not necessary to include (minibuffer . only); that is
101 appended when the minibuffer frame is created."
102 :type '(repeat (cons :format "%v"
103 (symbol :tag "Parameter")
104 (sexp :tag "Value")))
105 :group 'frames)
107 (defun handle-delete-frame (event)
108 "Handle delete-frame events from the X server."
109 (interactive "e")
110 (let ((frame (posn-window (event-start event)))
111 (i 0)
112 (tail (frame-list)))
113 (while tail
114 (and (frame-visible-p (car tail))
115 (not (eq (car tail) frame))
116 (setq i (1+ i)))
117 (setq tail (cdr tail)))
118 (if (> i 0)
119 (delete-frame frame t)
120 ;; Gildea@x.org says it is ok to ask questions before terminating.
121 (save-buffers-kill-emacs))))
123 (defun handle-focus-in (_event)
124 "Handle a focus-in event.
125 Focus-in events are usually bound to this function.
126 Focus-in events occur when a frame has focus, but a switch-frame event
127 is not generated.
128 This function runs the hook `focus-in-hook'."
129 (interactive "e")
130 (run-hooks 'focus-in-hook))
132 (defun handle-focus-out (_event)
133 "Handle a focus-out event.
134 Focus-out events are usually bound to this function.
135 Focus-out events occur when no frame has focus.
136 This function runs the hook `focus-out-hook'."
137 (interactive "e")
138 (run-hooks 'focus-out-hook))
140 ;;;; Arrangement of frames at startup
142 ;; 1) Load the window system startup file from the lisp library and read the
143 ;; high-priority arguments (-q and the like). The window system startup
144 ;; file should create any frames specified in the window system defaults.
146 ;; 2) If no frames have been opened, we open an initial text frame.
148 ;; 3) Once the init file is done, we apply any newly set parameters
149 ;; in initial-frame-alist to the frame.
151 ;; If we create the initial frame, this is it.
152 (defvar frame-initial-frame nil)
154 ;; Record the parameters used in frame-initialize to make the initial frame.
155 (defvar frame-initial-frame-alist)
157 (defvar frame-initial-geometry-arguments nil)
159 ;; startup.el calls this function before loading the user's init
160 ;; file - if there is no frame with a minibuffer open now, create
161 ;; one to display messages while loading the init file.
162 (defun frame-initialize ()
163 "Create an initial frame if necessary."
164 ;; Are we actually running under a window system at all?
165 (if (and initial-window-system
166 (not noninteractive)
167 (not (eq initial-window-system 'pc)))
168 (progn
169 ;; If there is no frame with a minibuffer besides the terminal
170 ;; frame, then we need to create the opening frame. Make sure
171 ;; it has a minibuffer, but let initial-frame-alist omit the
172 ;; minibuffer spec.
173 (or (delq terminal-frame (minibuffer-frame-list))
174 (progn
175 (setq frame-initial-frame-alist
176 (append initial-frame-alist default-frame-alist nil))
177 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
178 (setq frame-initial-frame-alist
179 (cons '(horizontal-scroll-bars . t)
180 frame-initial-frame-alist)))
181 (setq frame-initial-frame-alist
182 (cons (cons 'window-system initial-window-system)
183 frame-initial-frame-alist))
184 (setq default-minibuffer-frame
185 (setq frame-initial-frame
186 (make-frame frame-initial-frame-alist)))
187 ;; Delete any specifications for window geometry parameters
188 ;; so that we won't reapply them in frame-notice-user-settings.
189 ;; It would be wrong to reapply them then,
190 ;; because that would override explicit user resizing.
191 (setq initial-frame-alist
192 (frame-remove-geometry-params initial-frame-alist))))
193 ;; Copy the environment of the Emacs process into the new frame.
194 (set-frame-parameter frame-initial-frame 'environment
195 (frame-parameter terminal-frame 'environment))
196 ;; At this point, we know that we have a frame open, so we
197 ;; can delete the terminal frame.
198 (delete-frame terminal-frame)
199 (setq terminal-frame nil))))
201 (defvar frame-notice-user-settings t
202 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
204 (declare-function tool-bar-mode "tool-bar" (&optional arg))
206 (defalias 'tool-bar-lines-needed 'tool-bar-height)
208 ;; startup.el calls this function after loading the user's init
209 ;; file. Now default-frame-alist and initial-frame-alist contain
210 ;; information to which we must react; do what needs to be done.
211 (defun frame-notice-user-settings ()
212 "Act on user's init file settings of frame parameters.
213 React to settings of `initial-frame-alist',
214 `window-system-default-frame-alist' and `default-frame-alist'
215 there (in decreasing order of priority)."
216 ;; Creating and deleting frames may shift the selected frame around,
217 ;; and thus the current buffer. Protect against that. We don't
218 ;; want to use save-excursion here, because that may also try to set
219 ;; the buffer of the selected window, which fails when the selected
220 ;; window is the minibuffer.
221 (let ((old-buffer (current-buffer))
222 (window-system-frame-alist
223 (cdr (assq initial-window-system
224 window-system-default-frame-alist))))
226 (when (and frame-notice-user-settings
227 (null frame-initial-frame))
228 ;; This case happens when we don't have a window system, and
229 ;; also for MS-DOS frames.
230 (let ((parms (frame-parameters)))
231 ;; Don't change the frame names.
232 (setq parms (delq (assq 'name parms) parms))
233 ;; Can't modify the minibuffer parameter, so don't try.
234 (setq parms (delq (assq 'minibuffer parms) parms))
235 (modify-frame-parameters
237 (if initial-window-system
238 parms
239 ;; initial-frame-alist and default-frame-alist were already
240 ;; applied in pc-win.el.
241 (append initial-frame-alist window-system-frame-alist
242 default-frame-alist parms nil)))
243 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
244 (let ((newparms (frame-parameters))
245 (frame (selected-frame)))
246 (tty-handle-reverse-video frame newparms)
247 ;; If we changed the background color, we need to update
248 ;; the background-mode parameter, and maybe some faces,
249 ;; too.
250 (when (assq 'background-color newparms)
251 (unless (or (assq 'background-mode initial-frame-alist)
252 (assq 'background-mode default-frame-alist))
253 (frame-set-background-mode frame))
254 (face-set-after-frame-default frame))))))
256 ;; If the initial frame is still around, apply initial-frame-alist
257 ;; and default-frame-alist to it.
258 (when (frame-live-p frame-initial-frame)
260 ;; When tool-bar has been switched off, correct the frame size
261 ;; by the lines added in x-create-frame for the tool-bar and
262 ;; switch `tool-bar-mode' off.
263 (when (display-graphic-p)
264 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
265 (assq 'tool-bar-lines window-system-frame-alist)
266 (assq 'tool-bar-lines default-frame-alist))))
267 (when (and tool-bar-originally-present
268 (or (null tool-bar-lines)
269 (null (cdr tool-bar-lines))
270 (eq 0 (cdr tool-bar-lines))))
271 (let* ((char-height (frame-char-height frame-initial-frame))
272 (image-height tool-bar-images-pixel-height)
273 (margin (cond ((and (consp tool-bar-button-margin)
274 (integerp (cdr tool-bar-button-margin))
275 (> tool-bar-button-margin 0))
276 (cdr tool-bar-button-margin))
277 ((and (integerp tool-bar-button-margin)
278 (> tool-bar-button-margin 0))
279 tool-bar-button-margin)
280 (t 0)))
281 (relief (if (and (integerp tool-bar-button-relief)
282 (> tool-bar-button-relief 0))
283 tool-bar-button-relief 3))
284 (lines (/ (+ image-height
285 (* 2 margin)
286 (* 2 relief)
287 (1- char-height))
288 char-height))
289 (height (frame-parameter frame-initial-frame 'height))
290 (newparms (list (cons 'height (- height lines))))
291 (initial-top (cdr (assq 'top
292 frame-initial-geometry-arguments)))
293 (top (frame-parameter frame-initial-frame 'top)))
294 (when (and (consp initial-top) (eq '- (car initial-top)))
295 (let ((adjusted-top
296 (cond ((and (consp top)
297 (eq '+ (car top)))
298 (list '+
299 (+ (cadr top)
300 (* lines char-height))))
301 ((and (consp top)
302 (eq '- (car top)))
303 (list '-
304 (- (cadr top)
305 (* lines char-height))))
306 (t (+ top (* lines char-height))))))
307 (setq newparms
308 (append newparms
309 `((top . ,adjusted-top))
310 nil))))
311 (modify-frame-parameters frame-initial-frame newparms)
312 (tool-bar-mode -1)))))
314 ;; The initial frame we create above always has a minibuffer.
315 ;; If the user wants to remove it, or make it a minibuffer-only
316 ;; frame, then we'll have to delete the current frame and make a
317 ;; new one; you can't remove or add a root window to/from an
318 ;; existing frame.
320 ;; NOTE: default-frame-alist was nil when we created the
321 ;; existing frame. We need to explicitly include
322 ;; default-frame-alist in the parameters of the screen we
323 ;; create here, so that its new value, gleaned from the user's
324 ;; init file, will be applied to the existing screen.
325 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
326 (assq 'minibuffer window-system-frame-alist)
327 (assq 'minibuffer default-frame-alist)
328 '(minibuffer . t)))
330 ;; Create the new frame.
331 (let (parms new)
332 ;; MS-Windows needs this to avoid inflooping below.
333 (if (eq system-type 'windows-nt)
334 (sit-for 0 t))
335 ;; If the frame isn't visible yet, wait till it is.
336 ;; If the user has to position the window,
337 ;; Emacs doesn't know its real position until
338 ;; the frame is seen to be visible.
339 (while (not (cdr (assq 'visibility
340 (frame-parameters frame-initial-frame))))
341 (sleep-for 1))
342 (setq parms (frame-parameters frame-initial-frame))
344 ;; Get rid of `name' unless it was specified explicitly before.
345 (or (assq 'name frame-initial-frame-alist)
346 (setq parms (delq (assq 'name parms) parms)))
347 ;; An explicit parent-id is a request to XEmbed the frame.
348 (or (assq 'parent-id frame-initial-frame-alist)
349 (setq parms (delq (assq 'parent-id parms) parms)))
351 (setq parms (append initial-frame-alist
352 window-system-frame-alist
353 default-frame-alist
354 parms
355 nil))
357 ;; Get rid of `reverse', because that was handled
358 ;; when we first made the frame.
359 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
361 (if (assq 'height frame-initial-geometry-arguments)
362 (setq parms (assq-delete-all 'height parms)))
363 (if (assq 'width frame-initial-geometry-arguments)
364 (setq parms (assq-delete-all 'width parms)))
365 (if (assq 'left frame-initial-geometry-arguments)
366 (setq parms (assq-delete-all 'left parms)))
367 (if (assq 'top frame-initial-geometry-arguments)
368 (setq parms (assq-delete-all 'top parms)))
369 (setq new
370 (make-frame
371 ;; Use the geometry args that created the existing
372 ;; frame, rather than the parms we get for it.
373 (append frame-initial-geometry-arguments
374 '((user-size . t) (user-position . t))
375 parms)))
376 ;; The initial frame, which we are about to delete, may be
377 ;; the only frame with a minibuffer. If it is, create a
378 ;; new one.
379 (or (delq frame-initial-frame (minibuffer-frame-list))
380 (make-initial-minibuffer-frame nil))
382 ;; If the initial frame is serving as a surrogate
383 ;; minibuffer frame for any frames, we need to wean them
384 ;; onto a new frame. The default-minibuffer-frame
385 ;; variable must be handled similarly.
386 (let ((users-of-initial
387 (filtered-frame-list
388 (lambda (frame)
389 (and (not (eq frame frame-initial-frame))
390 (eq (window-frame
391 (minibuffer-window frame))
392 frame-initial-frame))))))
393 (if (or users-of-initial
394 (eq default-minibuffer-frame frame-initial-frame))
396 ;; Choose an appropriate frame. Prefer frames which
397 ;; are only minibuffers.
398 (let* ((new-surrogate
399 (car
400 (or (filtered-frame-list
401 (lambda (frame)
402 (eq (cdr (assq 'minibuffer
403 (frame-parameters frame)))
404 'only)))
405 (minibuffer-frame-list))))
406 (new-minibuffer (minibuffer-window new-surrogate)))
408 (if (eq default-minibuffer-frame frame-initial-frame)
409 (setq default-minibuffer-frame new-surrogate))
411 ;; Wean the frames using frame-initial-frame as
412 ;; their minibuffer frame.
413 (dolist (frame users-of-initial)
414 (modify-frame-parameters
415 frame (list (cons 'minibuffer new-minibuffer)))))))
417 ;; Redirect events enqueued at this frame to the new frame.
418 ;; Is this a good idea?
419 (redirect-frame-focus frame-initial-frame new)
421 ;; Finally, get rid of the old frame.
422 (delete-frame frame-initial-frame t))
424 ;; Otherwise, we don't need all that rigmarole; just apply
425 ;; the new parameters.
426 (let (newparms allparms tail)
427 (setq allparms (append initial-frame-alist
428 window-system-frame-alist
429 default-frame-alist nil))
430 (if (assq 'height frame-initial-geometry-arguments)
431 (setq allparms (assq-delete-all 'height allparms)))
432 (if (assq 'width frame-initial-geometry-arguments)
433 (setq allparms (assq-delete-all 'width allparms)))
434 (if (assq 'left frame-initial-geometry-arguments)
435 (setq allparms (assq-delete-all 'left allparms)))
436 (if (assq 'top frame-initial-geometry-arguments)
437 (setq allparms (assq-delete-all 'top allparms)))
438 (setq tail allparms)
439 ;; Find just the parms that have changed since we first
440 ;; made this frame. Those are the ones actually set by
441 ;; the init file. For those parms whose values we already knew
442 ;; (such as those spec'd by command line options)
443 ;; it is undesirable to specify the parm again
444 ;; once the user has seen the frame and been able to alter it
445 ;; manually.
446 (let (newval oldval)
447 (dolist (entry tail)
448 (setq oldval (assq (car entry) frame-initial-frame-alist))
449 (setq newval (cdr (assq (car entry) allparms)))
450 (or (and oldval (eq (cdr oldval) newval))
451 (setq newparms
452 (cons (cons (car entry) newval) newparms)))))
453 (setq newparms (nreverse newparms))
455 (let ((new-bg (assq 'background-color newparms)))
456 ;; If the `background-color' parameter is changed, apply
457 ;; it first, then make sure that the `background-mode'
458 ;; parameter and other faces are updated, before applying
459 ;; the other parameters.
460 (when new-bg
461 (modify-frame-parameters frame-initial-frame
462 (list new-bg))
463 (unless (assq 'background-mode newparms)
464 (frame-set-background-mode frame-initial-frame))
465 (face-set-after-frame-default frame-initial-frame)
466 (setq newparms (delq new-bg newparms)))
467 (modify-frame-parameters frame-initial-frame newparms)))))
469 ;; Restore the original buffer.
470 (set-buffer old-buffer)
472 ;; Make sure the initial frame can be GC'd if it is ever deleted.
473 ;; Make sure frame-notice-user-settings does nothing if called twice.
474 (setq frame-notice-user-settings nil)
475 (setq frame-initial-frame nil)))
477 (defun make-initial-minibuffer-frame (display)
478 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
479 (if display
480 (make-frame-on-display display parms)
481 (make-frame parms))))
483 ;;;; Creation of additional frames, and other frame miscellanea
485 (defun modify-all-frames-parameters (alist)
486 "Modify all current and future frames' parameters according to ALIST.
487 This changes `default-frame-alist' and possibly `initial-frame-alist'.
488 Furthermore, this function removes all parameters in ALIST from
489 `window-system-default-frame-alist'.
490 See help of `modify-frame-parameters' for more information."
491 (dolist (frame (frame-list))
492 (modify-frame-parameters frame alist))
494 (dolist (pair alist) ;; conses to add/replace
495 ;; initial-frame-alist needs setting only when
496 ;; frame-notice-user-settings is true.
497 (and frame-notice-user-settings
498 (setq initial-frame-alist
499 (assq-delete-all (car pair) initial-frame-alist)))
500 (setq default-frame-alist
501 (assq-delete-all (car pair) default-frame-alist))
502 ;; Remove any similar settings from the window-system specific
503 ;; parameters---they would override default-frame-alist.
504 (dolist (w window-system-default-frame-alist)
505 (setcdr w (assq-delete-all (car pair) (cdr w)))))
507 (and frame-notice-user-settings
508 (setq initial-frame-alist (append initial-frame-alist alist)))
509 (setq default-frame-alist (append default-frame-alist alist)))
511 (defun get-other-frame ()
512 "Return some frame other than the current frame.
513 Create one if necessary. Note that the minibuffer frame, if separate,
514 is not considered (see `next-frame')."
515 (if (equal (next-frame) (selected-frame)) (make-frame) (next-frame)))
517 (defun next-multiframe-window ()
518 "Select the next window, regardless of which frame it is on."
519 (interactive)
520 (select-window (next-window (selected-window)
521 (> (minibuffer-depth) 0)
523 (select-frame-set-input-focus (selected-frame)))
525 (defun previous-multiframe-window ()
526 "Select the previous window, regardless of which frame it is on."
527 (interactive)
528 (select-window (previous-window (selected-window)
529 (> (minibuffer-depth) 0)
531 (select-frame-set-input-focus (selected-frame)))
533 (defun window-system-for-display (display)
534 "Return the window system for DISPLAY.
535 Return nil if we don't know how to interpret DISPLAY."
536 ;; MS-Windows doesn't know how to create a GUI frame in a -nw session.
537 (if (and (eq system-type 'windows-nt)
538 (null (window-system)))
540 (cl-loop for descriptor in display-format-alist
541 for pattern = (car descriptor)
542 for system = (cdr descriptor)
543 when (string-match-p pattern display) return system)))
545 (defun make-frame-on-display (display &optional parameters)
546 "Make a frame on display DISPLAY.
547 The optional argument PARAMETERS specifies additional frame parameters."
548 (interactive "sMake frame on display: ")
549 (make-frame (cons (cons 'display display) parameters)))
551 (declare-function x-close-connection "xfns.c" (terminal))
553 (defun close-display-connection (display)
554 "Close the connection to a display, deleting all its associated frames.
555 For DISPLAY, specify either a frame or a display name (a string).
556 If DISPLAY is nil, that stands for the selected frame's display."
557 (interactive
558 (list
559 (let* ((default (frame-parameter nil 'display))
560 (display (completing-read
561 (format "Close display (default %s): " default)
562 (delete-dups
563 (mapcar (lambda (frame)
564 (frame-parameter frame 'display))
565 (frame-list)))
566 nil t nil nil
567 default)))
568 (if (zerop (length display)) default display))))
569 (let ((frames (delq nil
570 (mapcar (lambda (frame)
571 (if (equal display
572 (frame-parameter frame 'display))
573 frame))
574 (frame-list)))))
575 (if (and (consp frames)
576 (not (y-or-n-p (if (cdr frames)
577 (format "Delete %s frames? " (length frames))
578 (format "Delete %s ? " (car frames))))))
579 (error "Abort!")
580 (mapc 'delete-frame frames)
581 (x-close-connection display))))
583 (defun make-frame-command ()
584 "Make a new frame, on the same terminal as the selected frame.
585 If the terminal is a text-only terminal, this also selects the
586 new frame."
587 (interactive)
588 (if (display-graphic-p)
589 (make-frame)
590 (select-frame (make-frame))))
592 (defvar before-make-frame-hook nil
593 "Functions to run before a frame is created.")
595 (defvar after-make-frame-functions nil
596 "Functions to run after a frame is created.
597 The functions are run with one arg, the newly created frame.")
599 (defvar after-setting-font-hook nil
600 "Functions to run after a frame's font has been changed.")
602 ;; Alias, kept temporarily.
603 (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
605 (defvar frame-inherited-parameters '()
606 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
608 (defvar x-display-name)
610 (defun make-frame (&optional parameters)
611 "Return a newly created frame displaying the current buffer.
612 Optional argument PARAMETERS is an alist of frame parameters for
613 the new frame. Each element of PARAMETERS should have the
614 form (NAME . VALUE), for example:
616 (name . STRING) The frame should be named STRING.
618 (width . NUMBER) The frame should be NUMBER characters in width.
619 (height . NUMBER) The frame should be NUMBER text lines high.
621 You cannot specify either `width' or `height', you must specify
622 neither or both.
624 (minibuffer . t) The frame should have a minibuffer.
625 (minibuffer . nil) The frame should have no minibuffer.
626 (minibuffer . only) The frame should contain only a minibuffer.
627 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
629 (window-system . nil) The frame should be displayed on a terminal device.
630 (window-system . x) The frame should be displayed in an X window.
632 (display . \":0\") The frame should appear on display :0.
634 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
636 In addition, any parameter specified in `default-frame-alist',
637 but not present in PARAMETERS, is applied.
639 Before creating the frame (via `frame-creation-function-alist'),
640 this function runs the hook `before-make-frame-hook'. After
641 creating the frame, it runs the hook `after-make-frame-functions'
642 with one arg, the newly created frame.
644 If a display parameter is supplied and a window-system is not,
645 guess the window-system from the display.
647 On graphical displays, this function does not itself make the new
648 frame the selected frame. However, the window system may select
649 the new frame according to its own rules."
650 (interactive)
651 (let* ((display (cdr (assq 'display parameters)))
652 (w (cond
653 ((assq 'terminal parameters)
654 (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
655 (cond
656 ((eq type t) nil)
657 ((eq type nil) (error "Terminal %s does not exist"
658 (cdr (assq 'terminal parameters))))
659 (t type))))
660 ((assq 'window-system parameters)
661 (cdr (assq 'window-system parameters)))
662 (display
663 (or (window-system-for-display display)
664 (error "Don't know how to interpret display %S"
665 display)))
666 (t window-system)))
667 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
668 (oldframe (selected-frame))
669 (params parameters)
670 frame)
671 (unless frame-creation-function
672 (error "Don't know how to create a frame on window system %s" w))
674 (unless (get w 'window-system-initialized)
675 (funcall (cdr (assq w window-system-initialization-alist)) display)
676 (setq x-display-name display)
677 (put w 'window-system-initialized t))
679 ;; Add parameters from `window-system-default-frame-alist'.
680 (dolist (p (cdr (assq w window-system-default-frame-alist)))
681 (unless (assq (car p) params)
682 (push p params)))
683 ;; Add parameters from `default-frame-alist'.
684 (dolist (p default-frame-alist)
685 (unless (assq (car p) params)
686 (push p params)))
687 ;; Now make the frame.
688 (run-hooks 'before-make-frame-hook)
689 (setq frame (funcall frame-creation-function params))
690 (normal-erase-is-backspace-setup-frame frame)
691 ;; Inherit the original frame's parameters.
692 (dolist (param frame-inherited-parameters)
693 (unless (assq param parameters) ;Overridden by explicit parameters.
694 (let ((val (frame-parameter oldframe param)))
695 (when val (set-frame-parameter frame param val)))))
696 (run-hook-with-args 'after-make-frame-functions frame)
697 frame))
699 (defun filtered-frame-list (predicate)
700 "Return a list of all live frames which satisfy PREDICATE."
701 (let* ((frames (frame-list))
702 (list frames))
703 (while (consp frames)
704 (unless (funcall predicate (car frames))
705 (setcar frames nil))
706 (setq frames (cdr frames)))
707 (delq nil list)))
709 (defun minibuffer-frame-list ()
710 "Return a list of all frames with their own minibuffers."
711 (filtered-frame-list
712 (lambda (frame)
713 (eq frame (window-frame (minibuffer-window frame))))))
715 ;; Used to be called `terminal-id' in termdev.el.
716 (defun get-device-terminal (device)
717 "Return the terminal corresponding to DEVICE.
718 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
719 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
720 (cond
721 ((or (null device) (framep device))
722 (frame-terminal device))
723 ((stringp device)
724 (let ((f (car (filtered-frame-list
725 (lambda (frame)
726 (or (equal (frame-parameter frame 'display) device)
727 (equal (frame-parameter frame 'tty) device)))))))
728 (or f (error "Display %s does not exist" device))
729 (frame-terminal f)))
730 ((terminal-live-p device) device)
732 (error "Invalid argument %s in `get-device-terminal'" device))))
734 (defun frames-on-display-list (&optional device)
735 "Return a list of all frames on DEVICE.
737 DEVICE should be a terminal, a frame,
738 or a name of an X display or tty (a string of the form
739 HOST:SERVER.SCREEN).
741 If DEVICE is omitted or nil, it defaults to the selected
742 frame's terminal device."
743 (let* ((terminal (get-device-terminal device))
744 (func #'(lambda (frame)
745 (eq (frame-terminal frame) terminal))))
746 (filtered-frame-list func)))
748 (defun framep-on-display (&optional terminal)
749 "Return the type of frames on TERMINAL.
750 TERMINAL may be a terminal id, a display name or a frame. If it
751 is a frame, its type is returned. If TERMINAL is omitted or nil,
752 it defaults to the selected frame's terminal device. All frames
753 on a given display are of the same type."
754 (or (terminal-live-p terminal)
755 (framep terminal)
756 (framep (car (frames-on-display-list terminal)))))
758 (defun frame-remove-geometry-params (param-list)
759 "Return the parameter list PARAM-LIST, but with geometry specs removed.
760 This deletes all bindings in PARAM-LIST for `top', `left', `width',
761 `height', `user-size' and `user-position' parameters.
762 Emacs uses this to avoid overriding explicit moves and resizings from
763 the user during startup."
764 (setq param-list (cons nil param-list))
765 (let ((tail param-list))
766 (while (consp (cdr tail))
767 (if (and (consp (car (cdr tail)))
768 (memq (car (car (cdr tail)))
769 '(height width top left user-position user-size)))
770 (progn
771 (setq frame-initial-geometry-arguments
772 (cons (car (cdr tail)) frame-initial-geometry-arguments))
773 (setcdr tail (cdr (cdr tail))))
774 (setq tail (cdr tail)))))
775 (setq frame-initial-geometry-arguments
776 (nreverse frame-initial-geometry-arguments))
777 (cdr param-list))
779 (declare-function x-focus-frame "frame.c" (frame))
781 (defun select-frame-set-input-focus (frame &optional norecord)
782 "Select FRAME, raise it, and set input focus, if possible.
783 If `mouse-autoselect-window' is non-nil, also move mouse pointer
784 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
785 is non-nil, move mouse cursor to FRAME.
787 Optional argument NORECORD means to neither change the order of
788 recently selected windows nor the buffer list."
789 (select-frame frame norecord)
790 (raise-frame frame)
791 ;; Ensure, if possible, that FRAME gets input focus.
792 (when (memq (window-system frame) '(x w32 ns))
793 (x-focus-frame frame))
794 ;; Move mouse cursor if necessary.
795 (cond
796 (mouse-autoselect-window
797 (let ((edges (window-inside-edges (frame-selected-window frame))))
798 ;; Move mouse cursor into FRAME's selected window to avoid that
799 ;; Emacs mouse-autoselects another window.
800 (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
801 (focus-follows-mouse
802 ;; Move mouse cursor into FRAME to avoid that another frame gets
803 ;; selected by the window manager.
804 (set-mouse-position frame (1- (frame-width frame)) 0))))
806 (defun other-frame (arg)
807 "Select the ARGth different visible frame on current display, and raise it.
808 All frames are arranged in a cyclic order.
809 This command selects the frame ARG steps away in that order.
810 A negative ARG moves in the opposite order.
812 To make this command work properly, you must tell Emacs
813 how the system (or the window manager) generally handles
814 focus-switching between windows. If moving the mouse onto a window
815 selects it (gives it focus), set `focus-follows-mouse' to t.
816 Otherwise, that variable should be nil."
817 (interactive "p")
818 (let ((frame (selected-frame)))
819 (while (> arg 0)
820 (setq frame (next-frame frame))
821 (while (not (eq (frame-visible-p frame) t))
822 (setq frame (next-frame frame)))
823 (setq arg (1- arg)))
824 (while (< arg 0)
825 (setq frame (previous-frame frame))
826 (while (not (eq (frame-visible-p frame) t))
827 (setq frame (previous-frame frame)))
828 (setq arg (1+ arg)))
829 (select-frame-set-input-focus frame)))
831 (defun iconify-or-deiconify-frame ()
832 "Iconify the selected frame, or deiconify if it's currently an icon."
833 (interactive)
834 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
835 (iconify-frame)
836 (make-frame-visible)))
838 (defun suspend-frame ()
839 "Do whatever is right to suspend the current frame.
840 Calls `suspend-emacs' if invoked from the controlling tty device,
841 `suspend-tty' from a secondary tty device, and
842 `iconify-or-deiconify-frame' from an X frame."
843 (interactive)
844 (let ((type (framep (selected-frame))))
845 (cond
846 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
847 ((eq type t)
848 (if (controlling-tty-p)
849 (suspend-emacs)
850 (suspend-tty)))
851 (t (suspend-emacs)))))
853 (defun make-frame-names-alist ()
854 ;; Only consider the frames on the same display.
855 (let* ((current-frame (selected-frame))
856 (falist
857 (cons
858 (cons (frame-parameter current-frame 'name) current-frame) nil))
859 (frame (next-frame nil 0)))
860 (while (not (eq frame current-frame))
861 (progn
862 (push (cons (frame-parameter frame 'name) frame) falist)
863 (setq frame (next-frame frame 0))))
864 falist))
866 (defvar frame-name-history nil)
867 (defun select-frame-by-name (name)
868 "Select the frame on the current terminal whose name is NAME and raise it.
869 If there is no frame by that name, signal an error."
870 (interactive
871 (let* ((frame-names-alist (make-frame-names-alist))
872 (default (car (car frame-names-alist)))
873 (input (completing-read
874 (format "Select Frame (default %s): " default)
875 frame-names-alist nil t nil 'frame-name-history)))
876 (if (= (length input) 0)
877 (list default)
878 (list input))))
879 (let* ((frame-names-alist (make-frame-names-alist))
880 (frame (cdr (assoc name frame-names-alist))))
881 (if frame
882 (select-frame-set-input-focus frame)
883 (error "There is no frame named `%s'" name))))
886 ;;;; Background mode.
888 (defcustom frame-background-mode nil
889 "The brightness of the background.
890 Set this to the symbol `dark' if your background color is dark,
891 `light' if your background is light, or nil (automatic by default)
892 if you want Emacs to examine the brightness for you.
894 If you change this without using customize, you should use
895 `frame-set-background-mode' to update existing frames;
896 e.g. (mapc 'frame-set-background-mode (frame-list))."
897 :group 'faces
898 :set #'(lambda (var value)
899 (set-default var value)
900 (mapc 'frame-set-background-mode (frame-list)))
901 :initialize 'custom-initialize-changed
902 :type '(choice (const dark)
903 (const light)
904 (const :tag "automatic" nil)))
906 (declare-function x-get-resource "frame.c"
907 (attribute class &optional component subclass))
909 ;; Only used if window-system is not null.
910 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
912 (defvar inhibit-frame-set-background-mode nil)
914 (defun frame-set-background-mode (frame &optional keep-face-specs)
915 "Set up display-dependent faces on FRAME.
916 Display-dependent faces are those which have different definitions
917 according to the `background-mode' and `display-type' frame parameters.
919 If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
920 face specs for the new background mode."
921 (unless inhibit-frame-set-background-mode
922 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
923 (bg-color (frame-parameter frame 'background-color))
924 (tty-type (tty-type frame))
925 (default-bg-mode
926 (if (or (window-system frame)
927 (and tty-type
928 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
929 tty-type)))
930 'light
931 'dark))
932 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
933 (bg-mode
934 (cond (frame-default-bg-mode)
935 ((equal bg-color "unspecified-fg") ; inverted colors
936 non-default-bg-mode)
937 ((not (color-values bg-color frame))
938 default-bg-mode)
939 ((>= (apply '+ (color-values bg-color frame))
940 ;; Just looking at the screen, colors whose
941 ;; values add up to .6 of the white total
942 ;; still look dark to me.
943 (* (apply '+ (color-values "white" frame)) .6))
944 'light)
945 (t 'dark)))
946 (display-type
947 (cond ((null (window-system frame))
948 (if (tty-display-color-p frame) 'color 'mono))
949 ((display-color-p frame)
950 'color)
951 ((x-display-grayscale-p frame)
952 'grayscale)
953 (t 'mono)))
954 (old-bg-mode
955 (frame-parameter frame 'background-mode))
956 (old-display-type
957 (frame-parameter frame 'display-type)))
959 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
960 (let ((locally-modified-faces nil)
961 ;; Prevent face-spec-recalc from calling this function
962 ;; again, resulting in a loop (bug#911).
963 (inhibit-frame-set-background-mode t)
964 (params (list (cons 'background-mode bg-mode)
965 (cons 'display-type display-type))))
966 (if keep-face-specs
967 (modify-frame-parameters frame params)
968 ;; If we are recomputing face specs, first collect a list
969 ;; of faces that don't match their face-specs. These are
970 ;; the faces modified on FRAME, and we avoid changing them
971 ;; below. Use a negative list to avoid consing (we assume
972 ;; most faces are unmodified).
973 (dolist (face (face-list))
974 (and (not (get face 'face-override-spec))
975 (not (face-spec-match-p face
976 (face-user-default-spec face)
977 (selected-frame)))
978 (push face locally-modified-faces)))
979 ;; Now change to the new frame parameters
980 (modify-frame-parameters frame params)
981 ;; For all unmodified named faces, choose face specs
982 ;; matching the new frame parameters.
983 (dolist (face (face-list))
984 (unless (memq face locally-modified-faces)
985 (face-spec-recalc face frame)))))))))
987 (defun frame-terminal-default-bg-mode (frame)
988 "Return the default background mode of FRAME.
989 This checks the `frame-background-mode' variable, the X resource
990 named \"backgroundMode\" (if FRAME is an X frame), and finally
991 the `background-mode' terminal parameter."
992 (or frame-background-mode
993 (let ((bg-resource
994 (and (window-system frame)
995 (x-get-resource "backgroundMode" "BackgroundMode"))))
996 (if bg-resource
997 (intern (downcase bg-resource))))
998 (terminal-parameter frame 'background-mode)))
1001 ;;;; Frame configurations
1003 (defun current-frame-configuration ()
1004 "Return a list describing the positions and states of all frames.
1005 Its car is `frame-configuration'.
1006 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
1007 where
1008 FRAME is a frame object,
1009 ALIST is an association list specifying some of FRAME's parameters, and
1010 WINDOW-CONFIG is a window configuration object for FRAME."
1011 (cons 'frame-configuration
1012 (mapcar (lambda (frame)
1013 (list frame
1014 (frame-parameters frame)
1015 (current-window-configuration frame)))
1016 (frame-list))))
1018 (defun set-frame-configuration (configuration &optional nodelete)
1019 "Restore the frames to the state described by CONFIGURATION.
1020 Each frame listed in CONFIGURATION has its position, size, window
1021 configuration, and other parameters set as specified in CONFIGURATION.
1022 However, this function does not restore deleted frames.
1024 Ordinarily, this function deletes all existing frames not
1025 listed in CONFIGURATION. But if optional second argument NODELETE
1026 is given and non-nil, the unwanted frames are iconified instead."
1027 (or (frame-configuration-p configuration)
1028 (signal 'wrong-type-argument
1029 (list 'frame-configuration-p configuration)))
1030 (let ((config-alist (cdr configuration))
1031 frames-to-delete)
1032 (dolist (frame (frame-list))
1033 (let ((parameters (assq frame config-alist)))
1034 (if parameters
1035 (progn
1036 (modify-frame-parameters
1037 frame
1038 ;; Since we can't set a frame's minibuffer status,
1039 ;; we might as well omit the parameter altogether.
1040 (let* ((parms (nth 1 parameters))
1041 (mini (assq 'minibuffer parms))
1042 (name (assq 'name parms))
1043 (explicit-name (cdr (assq 'explicit-name parms))))
1044 (when mini (setq parms (delq mini parms)))
1045 ;; Leave name in iff it was set explicitly.
1046 ;; This should fix the behavior reported in
1047 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
1048 (when (and name (not explicit-name))
1049 (setq parms (delq name parms)))
1050 parms))
1051 (set-window-configuration (nth 2 parameters)))
1052 (setq frames-to-delete (cons frame frames-to-delete)))))
1053 (mapc (if nodelete
1054 ;; Note: making frames invisible here was tried
1055 ;; but led to some strange behavior--each time the frame
1056 ;; was made visible again, the window manager asked afresh
1057 ;; for where to put it.
1058 'iconify-frame
1059 'delete-frame)
1060 frames-to-delete)))
1062 ;;;; Convenience functions for accessing and interactively changing
1063 ;;;; frame parameters.
1065 (defun frame-height (&optional frame)
1066 "Return number of lines available for display on FRAME.
1067 If FRAME is omitted, describe the currently selected frame.
1068 Exactly what is included in the return value depends on the
1069 window-system and toolkit in use - see `frame-pixel-height' for
1070 more details. The lines are in units of the default font height.
1072 The result is roughly related to the frame pixel height via
1073 height in pixels = height in lines * `frame-char-height'.
1074 However, this is only approximate, and is complicated e.g. by the
1075 fact that individual window lines and menu bar lines can have
1076 differing font heights."
1077 (cdr (assq 'height (frame-parameters frame))))
1079 (defun frame-width (&optional frame)
1080 "Return number of columns available for display on FRAME.
1081 If FRAME is omitted, describe the currently selected frame."
1082 (cdr (assq 'width (frame-parameters frame))))
1084 (declare-function x-list-fonts "xfaces.c"
1085 (pattern &optional face frame maximum width))
1087 (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
1089 (defun set-frame-font (font &optional keep-size frames)
1090 "Set the default font to FONT.
1091 When called interactively, prompt for the name of a font, and use
1092 that font on the selected frame. When called from Lisp, FONT
1093 should be a font name (a string), a font object, font entity, or
1094 font spec.
1096 If KEEP-SIZE is nil, keep the number of frame lines and columns
1097 fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
1098 to keep the current frame size fixed (in pixels) by adjusting the
1099 number of lines and columns.
1101 If FRAMES is nil, apply the font to the selected frame only.
1102 If FRAMES is non-nil, it should be a list of frames to act upon,
1103 or t meaning all existing graphical frames.
1104 Also, if FRAMES is non-nil, alter the user's Customization settings
1105 as though the font-related attributes of the `default' face had been
1106 \"set in this session\", so that the font is applied to future frames."
1107 (interactive
1108 (let* ((completion-ignore-case t)
1109 (font (completing-read "Font name: "
1110 ;; x-list-fonts will fail with an error
1111 ;; if this frame doesn't support fonts.
1112 (x-list-fonts "*" nil (selected-frame))
1113 nil nil nil nil
1114 (frame-parameter nil 'font))))
1115 (list font current-prefix-arg nil)))
1116 (when (or (stringp font) (fontp font))
1117 (let* ((this-frame (selected-frame))
1118 ;; FRAMES nil means affect the selected frame.
1119 (frame-list (cond ((null frames)
1120 (list this-frame))
1121 ((eq frames t)
1122 (frame-list))
1123 (t frames)))
1124 height width)
1125 (dolist (f frame-list)
1126 (when (display-multi-font-p f)
1127 (if keep-size
1128 (setq height (* (frame-parameter f 'height)
1129 (frame-char-height f))
1130 width (* (frame-parameter f 'width)
1131 (frame-char-width f))))
1132 ;; When set-face-attribute is called for :font, Emacs
1133 ;; guesses the best font according to other face attributes
1134 ;; (:width, :weight, etc.) so reset them too (Bug#2476).
1135 (set-face-attribute 'default f
1136 :width 'normal :weight 'normal
1137 :slant 'normal :font font)
1138 (if keep-size
1139 (modify-frame-parameters
1141 (list (cons 'height (round height (frame-char-height f)))
1142 (cons 'width (round width (frame-char-width f))))))))
1143 (when frames
1144 ;; Alter the user's Custom setting of the `default' face, but
1145 ;; only for font-related attributes.
1146 (let ((specs (cadr (assq 'user (get 'default 'theme-face))))
1147 (attrs '(:family :foundry :slant :weight :height :width))
1148 (new-specs nil))
1149 (if (null specs) (setq specs '((t nil))))
1150 (dolist (spec specs)
1151 ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
1152 (let ((display (nth 0 spec))
1153 (plist (copy-tree (nth 1 spec))))
1154 ;; Alter only DISPLAY conditions matching this frame.
1155 (when (or (memq display '(t default))
1156 (face-spec-set-match-display display this-frame))
1157 (dolist (attr attrs)
1158 (setq plist (plist-put plist attr
1159 (face-attribute 'default attr)))))
1160 (push (list display plist) new-specs)))
1161 (setq new-specs (nreverse new-specs))
1162 (put 'default 'customized-face new-specs)
1163 (custom-push-theme 'theme-face 'default 'user 'set new-specs)
1164 (put 'default 'face-modified nil))))
1165 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))
1167 (defun set-frame-parameter (frame parameter value)
1168 "Set frame parameter PARAMETER to VALUE on FRAME.
1169 If FRAME is nil, it defaults to the selected frame.
1170 See `modify-frame-parameters'."
1171 (modify-frame-parameters frame (list (cons parameter value))))
1173 (defun set-background-color (color-name)
1174 "Set the background color of the selected frame to COLOR-NAME.
1175 When called interactively, prompt for the name of the color to use.
1176 To get the frame's current background color, use `frame-parameters'."
1177 (interactive (list (read-color "Background color: ")))
1178 (modify-frame-parameters (selected-frame)
1179 (list (cons 'background-color color-name)))
1180 (or window-system
1181 (face-set-after-frame-default (selected-frame))))
1183 (defun set-foreground-color (color-name)
1184 "Set the foreground color of the selected frame to COLOR-NAME.
1185 When called interactively, prompt for the name of the color to use.
1186 To get the frame's current foreground color, use `frame-parameters'."
1187 (interactive (list (read-color "Foreground color: ")))
1188 (modify-frame-parameters (selected-frame)
1189 (list (cons 'foreground-color color-name)))
1190 (or window-system
1191 (face-set-after-frame-default (selected-frame))))
1193 (defun set-cursor-color (color-name)
1194 "Set the text cursor color of the selected frame to COLOR-NAME.
1195 When called interactively, prompt for the name of the color to use.
1196 This works by setting the `cursor-color' frame parameter on the
1197 selected frame.
1199 You can also set the text cursor color, for all frames, by
1200 customizing the `cursor' face."
1201 (interactive (list (read-color "Cursor color: ")))
1202 (modify-frame-parameters (selected-frame)
1203 (list (cons 'cursor-color color-name))))
1205 (defun set-mouse-color (color-name)
1206 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1207 When called interactively, prompt for the name of the color to use.
1208 To get the frame's current mouse color, use `frame-parameters'."
1209 (interactive (list (read-color "Mouse color: ")))
1210 (modify-frame-parameters (selected-frame)
1211 (list (cons 'mouse-color
1212 (or color-name
1213 (cdr (assq 'mouse-color
1214 (frame-parameters))))))))
1216 (defun set-border-color (color-name)
1217 "Set the color of the border of the selected frame to COLOR-NAME.
1218 When called interactively, prompt for the name of the color to use.
1219 To get the frame's current border color, use `frame-parameters'."
1220 (interactive (list (read-color "Border color: ")))
1221 (modify-frame-parameters (selected-frame)
1222 (list (cons 'border-color color-name))))
1224 (define-minor-mode auto-raise-mode
1225 "Toggle whether or not selected frames should auto-raise.
1226 With a prefix argument ARG, enable Auto Raise mode if ARG is
1227 positive, and disable it otherwise. If called from Lisp, enable
1228 the mode if ARG is omitted or nil.
1230 Auto Raise mode does nothing under most window managers, which
1231 switch focus on mouse clicks. It only has an effect if your
1232 window manager switches focus on mouse movement (in which case
1233 you should also change `focus-follows-mouse' to t). Then,
1234 enabling Auto Raise mode causes any graphical Emacs frame which
1235 acquires focus to be automatically raised.
1237 Note that this minor mode controls Emacs's own auto-raise
1238 feature. Window managers that switch focus on mouse movement
1239 often have their own auto-raise feature."
1240 :variable (frame-parameter nil 'auto-raise)
1241 (if (frame-parameter nil 'auto-raise)
1242 (raise-frame)))
1244 (define-minor-mode auto-lower-mode
1245 "Toggle whether or not the selected frame should auto-lower.
1246 With a prefix argument ARG, enable Auto Lower mode if ARG is
1247 positive, and disable it otherwise. If called from Lisp, enable
1248 the mode if ARG is omitted or nil.
1250 Auto Lower mode does nothing under most window managers, which
1251 switch focus on mouse clicks. It only has an effect if your
1252 window manager switches focus on mouse movement (in which case
1253 you should also change `focus-follows-mouse' to t). Then,
1254 enabling Auto Lower Mode causes any graphical Emacs frame which
1255 loses focus to be automatically lowered.
1257 Note that this minor mode controls Emacs's own auto-lower
1258 feature. Window managers that switch focus on mouse movement
1259 often have their own features for raising or lowering frames."
1260 :variable (frame-parameter nil 'auto-lower))
1262 (defun set-frame-name (name)
1263 "Set the name of the selected frame to NAME.
1264 When called interactively, prompt for the name of the frame.
1265 On text terminals, the frame name is displayed on the mode line.
1266 On graphical displays, it is displayed on the frame's title bar."
1267 (interactive "sFrame name: ")
1268 (modify-frame-parameters (selected-frame)
1269 (list (cons 'name name))))
1271 (defun frame-current-scroll-bars (&optional frame)
1272 "Return the current scroll-bar settings in frame FRAME.
1273 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1274 current location of the vertical scroll-bars (left, right, or nil),
1275 and HORIZONTAL specifies the current location of the horizontal scroll
1276 bars (top, bottom, or nil)."
1277 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
1278 (hor nil))
1279 (unless (memq vert '(left right nil))
1280 (setq vert default-frame-scroll-bars))
1281 (cons vert hor)))
1283 (defun frame-monitor-attributes (&optional frame)
1284 "Return the attributes of the physical monitor dominating FRAME.
1285 If FRAME is omitted, describe the currently selected frame.
1287 A frame is dominated by a physical monitor when either the
1288 largest area of the frame resides in the monitor, or the monitor
1289 is the closest to the frame if the frame does not intersect any
1290 physical monitors.
1292 See `display-monitor-attributes-list' for the list of attribute
1293 keys and their meanings."
1294 (or frame (setq frame (selected-frame)))
1295 (cl-loop for attributes in (display-monitor-attributes-list frame)
1296 for frames = (cdr (assq 'frames attributes))
1297 if (memq frame frames) return attributes))
1300 ;;;; Frame/display capabilities.
1302 (declare-function msdos-mouse-p "dosfns.c")
1304 (defun display-mouse-p (&optional display)
1305 "Return non-nil if DISPLAY has a mouse available.
1306 DISPLAY can be a display name, a frame, or nil (meaning the selected
1307 frame's display)."
1308 (let ((frame-type (framep-on-display display)))
1309 (cond
1310 ((eq frame-type 'pc)
1311 (msdos-mouse-p))
1312 ((eq frame-type 'w32)
1313 (with-no-warnings
1314 (> w32-num-mouse-buttons 0)))
1315 ((memq frame-type '(x ns))
1316 t) ;; We assume X and NeXTstep *always* have a pointing device
1318 (or (and (featurep 'xt-mouse)
1319 xterm-mouse-mode)
1320 ;; t-mouse is distributed with the GPM package. It doesn't have
1321 ;; a toggle.
1322 (featurep 't-mouse)
1323 ;; No way to check whether a w32 console has a mouse, assume
1324 ;; it always does.
1325 (boundp 'w32-use-full-screen-buffer))))))
1327 (defun display-popup-menus-p (&optional display)
1328 "Return non-nil if popup menus are supported on DISPLAY.
1329 DISPLAY can be a display name, a frame, or nil (meaning the selected
1330 frame's display).
1331 Support for popup menus requires that the mouse be available."
1332 (display-mouse-p display))
1334 (defun display-graphic-p (&optional display)
1335 "Return non-nil if DISPLAY is a graphic display.
1336 Graphical displays are those which are capable of displaying several
1337 frames and several different fonts at once. This is true for displays
1338 that use a window system such as X, and false for text-only terminals.
1339 DISPLAY can be a display name, a frame, or nil (meaning the selected
1340 frame's display)."
1341 (not (null (memq (framep-on-display display) '(x w32 ns)))))
1343 (defun display-images-p (&optional display)
1344 "Return non-nil if DISPLAY can display images.
1346 DISPLAY can be a display name, a frame, or nil (meaning the selected
1347 frame's display)."
1348 (and (display-graphic-p display)
1349 (fboundp 'image-mask-p)
1350 (fboundp 'image-size)))
1352 (defalias 'display-multi-frame-p 'display-graphic-p)
1353 (defalias 'display-multi-font-p 'display-graphic-p)
1355 (defun display-selections-p (&optional display)
1356 "Return non-nil if DISPLAY supports selections.
1357 A selection is a way to transfer text or other data between programs
1358 via special system buffers called `selection' or `clipboard'.
1359 DISPLAY can be a display name, a frame, or nil (meaning the selected
1360 frame's display)."
1361 (let ((frame-type (framep-on-display display)))
1362 (cond
1363 ((eq frame-type 'pc)
1364 ;; MS-DOG frames support selections when Emacs runs inside
1365 ;; the Windows' DOS Box.
1366 (with-no-warnings
1367 (not (null dos-windows-version))))
1368 ((memq frame-type '(x w32 ns))
1371 nil))))
1373 (declare-function x-display-screens "xfns.c" (&optional terminal))
1375 (defun display-screens (&optional display)
1376 "Return the number of screens associated with DISPLAY.
1377 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1378 (let ((frame-type (framep-on-display display)))
1379 (cond
1380 ((memq frame-type '(x w32 ns))
1381 (x-display-screens display))
1383 1))))
1385 (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
1387 (defun display-pixel-height (&optional display)
1388 "Return the height of DISPLAY's screen in pixels.
1389 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1391 For character terminals, each character counts as a single pixel.
1393 For graphical terminals, note that on \"multi-monitor\" setups this
1394 refers to the pixel height for all physical monitors associated
1395 with DISPLAY. To get information for each physical monitor, use
1396 `display-monitor-attributes-list'."
1397 (let ((frame-type (framep-on-display display)))
1398 (cond
1399 ((memq frame-type '(x w32 ns))
1400 (x-display-pixel-height display))
1402 (frame-height (if (framep display) display (selected-frame)))))))
1404 (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
1406 (defun display-pixel-width (&optional display)
1407 "Return the width of DISPLAY's screen in pixels.
1408 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1410 For character terminals, each character counts as a single pixel.
1412 For graphical terminals, note that on \"multi-monitor\" setups this
1413 refers to the pixel width for all physical monitors associated
1414 with DISPLAY. To get information for each physical monitor, use
1415 `display-monitor-attributes-list'."
1416 (let ((frame-type (framep-on-display display)))
1417 (cond
1418 ((memq frame-type '(x w32 ns))
1419 (x-display-pixel-width display))
1421 (frame-width (if (framep display) display (selected-frame)))))))
1423 (defcustom display-mm-dimensions-alist nil
1424 "Alist for specifying screen dimensions in millimeters.
1425 The functions `display-mm-height' and `display-mm-width' consult
1426 this list before asking the system.
1428 Each element has the form (DISPLAY . (WIDTH . HEIGHT)), e.g.
1429 \(\":0.0\" . (287 . 215)).
1431 If `display' is t, it specifies dimensions for all graphical displays
1432 not explicitly specified."
1433 :version "22.1"
1434 :type '(alist :key-type (choice (string :tag "Display name")
1435 (const :tag "Default" t))
1436 :value-type (cons :tag "Dimensions"
1437 (integer :tag "Width")
1438 (integer :tag "Height")))
1439 :group 'frames)
1441 (declare-function x-display-mm-height "xfns.c" (&optional terminal))
1443 (defun display-mm-height (&optional display)
1444 "Return the height of DISPLAY's screen in millimeters.
1445 If the information is unavailable, this function returns nil.
1446 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1448 You can override what the system thinks the result should be by
1449 adding an entry to `display-mm-dimensions-alist'.
1451 For graphical terminals, note that on \"multi-monitor\" setups this
1452 refers to the height in millimeters for all physical monitors
1453 associated with DISPLAY. To get information for each physical
1454 monitor, use `display-monitor-attributes-list'."
1455 (and (memq (framep-on-display display) '(x w32 ns))
1456 (or (cddr (assoc (or display (frame-parameter nil 'display))
1457 display-mm-dimensions-alist))
1458 (cddr (assoc t display-mm-dimensions-alist))
1459 (x-display-mm-height display))))
1461 (declare-function x-display-mm-width "xfns.c" (&optional terminal))
1463 (defun display-mm-width (&optional display)
1464 "Return the width of DISPLAY's screen in millimeters.
1465 If the information is unavailable, this function returns nil.
1466 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1468 You can override what the system thinks the result should be by
1469 adding an entry to `display-mm-dimensions-alist'.
1471 For graphical terminals, note that on \"multi-monitor\" setups this
1472 refers to the width in millimeters for all physical monitors
1473 associated with DISPLAY. To get information for each physical
1474 monitor, use `display-monitor-attributes-list'."
1475 (and (memq (framep-on-display display) '(x w32 ns))
1476 (or (cadr (assoc (or display (frame-parameter nil 'display))
1477 display-mm-dimensions-alist))
1478 (cadr (assoc t display-mm-dimensions-alist))
1479 (x-display-mm-width display))))
1481 (declare-function x-display-backing-store "xfns.c" (&optional terminal))
1483 ;; In NS port, the return value may be `buffered', `retained', or
1484 ;; `non-retained'. See src/nsfns.m.
1485 (defun display-backing-store (&optional display)
1486 "Return the backing store capability of DISPLAY's screen.
1487 The value may be `always', `when-mapped', `not-useful', or nil if
1488 the question is inapplicable to a certain kind of display.
1489 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1490 (let ((frame-type (framep-on-display display)))
1491 (cond
1492 ((memq frame-type '(x w32 ns))
1493 (x-display-backing-store display))
1495 'not-useful))))
1497 (declare-function x-display-save-under "xfns.c" (&optional terminal))
1499 (defun display-save-under (&optional display)
1500 "Return non-nil if DISPLAY's screen supports the SaveUnder feature.
1501 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1502 (let ((frame-type (framep-on-display display)))
1503 (cond
1504 ((memq frame-type '(x w32 ns))
1505 (x-display-save-under display))
1507 'not-useful))))
1509 (declare-function x-display-planes "xfns.c" (&optional terminal))
1511 (defun display-planes (&optional display)
1512 "Return the number of planes supported by DISPLAY.
1513 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1514 (let ((frame-type (framep-on-display display)))
1515 (cond
1516 ((memq frame-type '(x w32 ns))
1517 (x-display-planes display))
1518 ((eq frame-type 'pc)
1521 (truncate (log (length (tty-color-alist)) 2))))))
1523 (declare-function x-display-color-cells "xfns.c" (&optional terminal))
1525 (defun display-color-cells (&optional display)
1526 "Return the number of color cells supported by DISPLAY.
1527 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1528 (let ((frame-type (framep-on-display display)))
1529 (cond
1530 ((memq frame-type '(x w32 ns))
1531 (x-display-color-cells display))
1532 ((eq frame-type 'pc)
1535 (tty-display-color-cells display)))))
1537 (declare-function x-display-visual-class "xfns.c" (&optional terminal))
1539 (defun display-visual-class (&optional display)
1540 "Return the visual class of DISPLAY.
1541 The value is one of the symbols `static-gray', `gray-scale',
1542 `static-color', `pseudo-color', `true-color', or `direct-color'.
1543 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1544 (let ((frame-type (framep-on-display display)))
1545 (cond
1546 ((memq frame-type '(x w32 ns))
1547 (x-display-visual-class display))
1548 ((and (memq frame-type '(pc t))
1549 (tty-display-color-p display))
1550 'static-color)
1552 'static-gray))))
1554 (declare-function x-display-monitor-attributes-list "xfns.c"
1555 (&optional terminal))
1556 (declare-function w32-display-monitor-attributes-list "w32fns.c"
1557 (&optional display))
1558 (declare-function ns-display-monitor-attributes-list "nsfns.m"
1559 (&optional terminal))
1561 (defun display-monitor-attributes-list (&optional display)
1562 "Return a list of physical monitor attributes on DISPLAY.
1563 Each element of the list represents the attributes of each
1564 physical monitor. The first element corresponds to the primary
1565 monitor.
1567 Attributes for a physical monitor is represented as an alist of
1568 attribute keys and values as follows:
1570 geometry -- Position and size in pixels in the form of
1571 (X Y WIDTH HEIGHT)
1572 workarea -- Position and size of the workarea in pixels in the
1573 form of (X Y WIDTH HEIGHT)
1574 mm-size -- Width and height in millimeters in the form of
1575 (WIDTH HEIGHT)
1576 frames -- List of frames dominated by the physical monitor
1577 name (*) -- Name of the physical monitor as a string
1579 where X, Y, WIDTH, and HEIGHT are integers. Keys labeled
1580 with (*) are optional.
1582 A frame is dominated by a physical monitor when either the
1583 largest area of the frame resides in the monitor, or the monitor
1584 is the closest to the frame if the frame does not intersect any
1585 physical monitors. Every non-tip frame (including invisible one)
1586 in a graphical display is dominated by exactly one physical
1587 monitor at a time, though it can span multiple (or no) physical
1588 monitors.
1589 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1590 (let ((frame-type (framep-on-display display)))
1591 (cond
1592 ((eq frame-type 'x)
1593 (x-display-monitor-attributes-list display))
1594 ((eq frame-type 'w32)
1595 (w32-display-monitor-attributes-list display))
1596 ((eq frame-type 'ns)
1597 (ns-display-monitor-attributes-list display))
1599 (let ((geometry (list 0 0 (display-pixel-width display)
1600 (display-pixel-height display))))
1601 `(((geometry . ,geometry)
1602 (workarea . ,geometry)
1603 (mm-size . (,(display-mm-width display)
1604 ,(display-mm-height display)))
1605 (frames . ,(frames-on-display-list display)))))))))
1608 ;;;; Frame geometry values
1610 (defun frame-geom-value-cons (type value &optional frame)
1611 "Return equivalent geometry value for FRAME as a cons with car `+'.
1612 A geometry value equivalent to VALUE for FRAME is returned,
1613 where the value is a cons with car `+', not numeric.
1614 TYPE is the car of the original geometry spec (TYPE . VALUE).
1615 It is `top' or `left', depending on which edge VALUE is related to.
1616 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1617 If VALUE is a number, then it is converted to a cons value, perhaps
1618 relative to the opposite frame edge from that in the original spec.
1619 FRAME defaults to the selected frame.
1621 Examples (measures in pixels) -
1622 Assuming display height/width=1024, frame height/width=600:
1623 300 inside display edge: 300 => (+ 300)
1624 (+ 300) => (+ 300)
1625 300 inside opposite display edge: (- 300) => (+ 124)
1626 -300 => (+ 124)
1627 300 beyond display edge
1628 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1629 300 beyond display edge
1630 (= 724 inside opposite display edge): (- -300) => (+ 724)
1632 In the 3rd, 4th, and 6th examples, the returned value is relative to
1633 the opposite frame edge from the edge indicated in the input spec."
1634 (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
1635 value)
1636 ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
1637 (t ; e.g. -300, (- 300), (- -300)
1638 (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
1639 (x-display-pixel-width)
1640 (x-display-pixel-height))
1641 (if (integerp value) (- value) (cadr value))
1642 (if (eq 'left type)
1643 (frame-pixel-width frame)
1644 (frame-pixel-height frame)))))))
1646 (defun frame-geom-spec-cons (spec &optional frame)
1647 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1648 A geometry specification equivalent to SPEC for FRAME is returned,
1649 where the value is a cons with car `+', not numeric.
1650 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1651 If VALUE is a number, then it is converted to a cons value, perhaps
1652 relative to the opposite frame edge from that in the original spec.
1653 FRAME defaults to the selected frame.
1655 Examples (measures in pixels) -
1656 Assuming display height=1024, frame height=600:
1657 top 300 below display top: (top . 300) => (top + 300)
1658 (top + 300) => (top + 300)
1659 bottom 300 above display bottom: (top - 300) => (top + 124)
1660 (top . -300) => (top + 124)
1661 top 300 above display top
1662 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1663 bottom 300 below display bottom
1664 (= top 724 below display top): (top - -300) => (top + 724)
1666 In the 3rd, 4th, and 6th examples, the returned value is relative to
1667 the opposite frame edge from the edge indicated in the input spec."
1668 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
1671 (defun delete-other-frames (&optional frame)
1672 "Delete all frames on the current terminal, except FRAME.
1673 If FRAME uses another frame's minibuffer, the minibuffer frame is
1674 left untouched. FRAME nil or omitted means use the selected frame."
1675 (interactive)
1676 (unless frame
1677 (setq frame (selected-frame)))
1678 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1679 (frames (delq mini-frame (delq frame (frame-list)))))
1680 ;; Only consider frames on the same terminal.
1681 (dolist (frame (prog1 frames (setq frames nil)))
1682 (if (eq (frame-terminal) (frame-terminal frame))
1683 (push frame frames)))
1684 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1685 ;; signals an error when trying to delete a mini-frame that's
1686 ;; still in use by another frame.
1687 (dolist (frame frames)
1688 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1689 (delete-frame frame)))
1690 ;; Delete minibuffer-only frames.
1691 (dolist (frame frames)
1692 (when (eq (frame-parameter frame 'minibuffer) 'only)
1693 (delete-frame frame)))))
1695 ;; miscellaneous obsolescence declarations
1696 (define-obsolete-variable-alias 'delete-frame-hook
1697 'delete-frame-functions "22.1")
1700 ;; Blinking cursor
1702 (defgroup cursor nil
1703 "Displaying text cursors."
1704 :version "21.1"
1705 :group 'frames)
1707 (defcustom blink-cursor-delay 0.5
1708 "Seconds of idle time after which cursor starts to blink."
1709 :type 'number
1710 :group 'cursor)
1712 (defcustom blink-cursor-interval 0.5
1713 "Length of cursor blink interval in seconds."
1714 :type 'number
1715 :group 'cursor)
1717 (defcustom blink-cursor-blinks 10
1718 "How many times to blink before using a solid cursor on NS, X, and MS-Windows.
1719 Use 0 or negative value to blink forever."
1720 :version "24.4"
1721 :type 'integer
1722 :group 'cursor)
1724 (defvar blink-cursor-blinks-done 1
1725 "Number of blinks done since we started blinking on NS, X, and MS-Windows.")
1727 (defvar blink-cursor-idle-timer nil
1728 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1729 The function `blink-cursor-start' is called when the timer fires.")
1731 (defvar blink-cursor-timer nil
1732 "Timer started from `blink-cursor-start'.
1733 This timer calls `blink-cursor-timer-function' every
1734 `blink-cursor-interval' seconds.")
1736 (defun blink-cursor-start ()
1737 "Timer function called from the timer `blink-cursor-idle-timer'.
1738 This starts the timer `blink-cursor-timer', which makes the cursor blink
1739 if appropriate. It also arranges to cancel that timer when the next
1740 command starts, by installing a pre-command hook."
1741 (when (null blink-cursor-timer)
1742 ;; Set up the timer first, so that if this signals an error,
1743 ;; blink-cursor-end is not added to pre-command-hook.
1744 (setq blink-cursor-blinks-done 1)
1745 (setq blink-cursor-timer
1746 (run-with-timer blink-cursor-interval blink-cursor-interval
1747 'blink-cursor-timer-function))
1748 (add-hook 'pre-command-hook 'blink-cursor-end)
1749 (internal-show-cursor nil nil)))
1751 (defun blink-cursor-timer-function ()
1752 "Timer function of timer `blink-cursor-timer'."
1753 (internal-show-cursor nil (not (internal-show-cursor-p)))
1754 ;; Each blink is two calls to this function.
1755 (setq blink-cursor-blinks-done (1+ blink-cursor-blinks-done))
1756 (when (and (> blink-cursor-blinks 0)
1757 (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done))
1758 (blink-cursor-suspend)
1759 (add-hook 'post-command-hook 'blink-cursor-check)))
1762 (defun blink-cursor-end ()
1763 "Stop cursor blinking.
1764 This is installed as a pre-command hook by `blink-cursor-start'.
1765 When run, it cancels the timer `blink-cursor-timer' and removes
1766 itself as a pre-command hook."
1767 (remove-hook 'pre-command-hook 'blink-cursor-end)
1768 (internal-show-cursor nil t)
1769 (when blink-cursor-timer
1770 (cancel-timer blink-cursor-timer)
1771 (setq blink-cursor-timer nil)))
1773 (defun blink-cursor-suspend ()
1774 "Suspend cursor blinking.
1775 This is called when no frame has focus and timers can be suspended.
1776 Timers are restarted by `blink-cursor-check', which is called when a
1777 frame receives focus."
1778 (blink-cursor-end)
1779 (when blink-cursor-idle-timer
1780 (cancel-timer blink-cursor-idle-timer)
1781 (setq blink-cursor-idle-timer nil)))
1783 (defun blink-cursor-check ()
1784 "Check if cursor blinking shall be restarted.
1785 This is done when a frame gets focus. Blink timers may be stopped by
1786 `blink-cursor-suspend'."
1787 (when (and blink-cursor-mode
1788 (not blink-cursor-idle-timer))
1789 (remove-hook 'post-command-hook 'blink-cursor-check)
1790 (setq blink-cursor-idle-timer
1791 (run-with-idle-timer blink-cursor-delay
1792 blink-cursor-delay
1793 'blink-cursor-start))))
1795 (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
1797 (define-minor-mode blink-cursor-mode
1798 "Toggle cursor blinking (Blink Cursor mode).
1799 With a prefix argument ARG, enable Blink Cursor mode if ARG is
1800 positive, and disable it otherwise. If called from Lisp, enable
1801 the mode if ARG is omitted or nil.
1803 If the value of `blink-cursor-blinks' is positive (10 by default),
1804 the cursor stops blinking after that number of blinks, if Emacs
1805 gets no input during that time.
1807 See also `blink-cursor-interval' and `blink-cursor-delay'.
1809 This command is effective only on graphical frames. On text-only
1810 terminals, cursor blinking is controlled by the terminal."
1811 :init-value (not (or noninteractive
1812 no-blinking-cursor
1813 (eq system-type 'ms-dos)
1814 (not (memq window-system '(x w32 ns)))))
1815 :initialize 'custom-initialize-delay
1816 :group 'cursor
1817 :global t
1818 (blink-cursor-suspend)
1819 (remove-hook 'focus-in-hook #'blink-cursor-check)
1820 (remove-hook 'focus-out-hook #'blink-cursor-suspend)
1821 (when blink-cursor-mode
1822 (add-hook 'focus-in-hook #'blink-cursor-check)
1823 (add-hook 'focus-out-hook #'blink-cursor-suspend)
1824 (setq blink-cursor-idle-timer
1825 (run-with-idle-timer blink-cursor-delay
1826 blink-cursor-delay
1827 #'blink-cursor-start))))
1830 ;; Frame maximization/fullscreen
1832 (defun toggle-frame-maximized ()
1833 "Toggle maximization state of the selected frame.
1834 Maximize the selected frame or un-maximize if it is already maximized.
1835 Respect window manager screen decorations.
1836 If the frame is in fullscreen mode, don't change its mode,
1837 just toggle the temporary frame parameter `maximized',
1838 so the frame will go to the right maximization state
1839 after disabling fullscreen mode.
1840 See also `toggle-frame-fullscreen'."
1841 (interactive)
1842 (if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1843 (modify-frame-parameters
1845 `((maximized
1846 . ,(unless (eq (frame-parameter nil 'maximized) 'maximized)
1847 'maximized))))
1848 (modify-frame-parameters
1850 `((fullscreen
1851 . ,(unless (eq (frame-parameter nil 'fullscreen) 'maximized)
1852 'maximized))))))
1854 (defun toggle-frame-fullscreen ()
1855 "Toggle fullscreen mode of the selected frame.
1856 Enable fullscreen mode of the selected frame or disable if it is
1857 already fullscreen. Ignore window manager screen decorations.
1858 When turning on fullscreen mode, remember the previous value of the
1859 maximization state in the temporary frame parameter `maximized'.
1860 Restore the maximization state when turning off fullscreen mode.
1861 See also `toggle-frame-maximized'."
1862 (interactive)
1863 (modify-frame-parameters
1865 `((maximized
1866 . ,(unless (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1867 (frame-parameter nil 'fullscreen)))
1868 (fullscreen
1869 . ,(if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1870 (if (eq (frame-parameter nil 'maximized) 'maximized)
1871 'maximized)
1872 'fullscreen)))))
1875 ;;;; Key bindings
1877 (define-key ctl-x-5-map "2" 'make-frame-command)
1878 (define-key ctl-x-5-map "1" 'delete-other-frames)
1879 (define-key ctl-x-5-map "0" 'delete-frame)
1880 (define-key ctl-x-5-map "o" 'other-frame)
1881 (define-key global-map [f11] 'toggle-frame-fullscreen)
1882 (define-key global-map [(meta f10)] 'toggle-frame-maximized)
1883 (define-key esc-map [f10] 'toggle-frame-maximized)
1886 ;; Misc.
1888 ;; Only marked as obsolete in 24.3.
1889 (define-obsolete-variable-alias 'automatic-hscrolling
1890 'auto-hscroll-mode "22.1")
1892 (make-variable-buffer-local 'show-trailing-whitespace)
1894 ;; Defined in dispnew.c.
1895 (make-obsolete-variable
1896 'window-system-version "it does not give useful information." "24.3")
1898 (provide 'frame)
1900 ;;; frame.el ends here