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