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