Merge from emacs-24; up to 2014-07-16T17:06:12Z!rgm@gnu.org
[emacs.git] / lisp / frame.el
blob0b26e356f078465d6f464bf3cde2d7e1b6784a86
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 `(framep (selected-frame)))
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 t ,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 (cdr (assq 'terminal parameters)))))
652 (cond
653 ((null type) (error "Terminal %s does not exist"
654 (cdr (assq 'terminal parameters))))
655 (t type))))
656 ((assq 'window-system parameters)
657 (cdr (assq 'window-system parameters)))
658 (display
659 (or (window-system-for-display display)
660 (error "Don't know how to interpret display %S"
661 display)))
662 (t window-system)))
663 (oldframe (selected-frame))
664 (params parameters)
665 frame)
667 (unless (get w 'window-system-initialized)
668 (funcall (gui-method window-system-initialization w) display)
669 (setq x-display-name display)
670 (put w 'window-system-initialized t))
672 ;; Add parameters from `window-system-default-frame-alist'.
673 (dolist (p (cdr (assq w window-system-default-frame-alist)))
674 (unless (assq (car p) params)
675 (push p params)))
676 ;; Add parameters from `default-frame-alist'.
677 (dolist (p default-frame-alist)
678 (unless (assq (car p) params)
679 (push p params)))
680 ;; Now make the frame.
681 (run-hooks 'before-make-frame-hook)
682 (setq frame
683 (funcall (gui-method frame-creation-function (or w t)) params))
684 (normal-erase-is-backspace-setup-frame frame)
685 ;; Inherit the original frame's parameters.
686 (dolist (param frame-inherited-parameters)
687 (unless (assq param parameters) ;Overridden by explicit parameters.
688 (let ((val (frame-parameter oldframe param)))
689 (when val (set-frame-parameter frame param val)))))
690 (run-hook-with-args 'after-make-frame-functions frame)
691 frame))
693 (defun filtered-frame-list (predicate)
694 "Return a list of all live frames which satisfy PREDICATE."
695 (let* ((frames (frame-list))
696 (list frames))
697 (while (consp frames)
698 (unless (funcall predicate (car frames))
699 (setcar frames nil))
700 (setq frames (cdr frames)))
701 (delq nil list)))
703 (defun minibuffer-frame-list ()
704 "Return a list of all frames with their own minibuffers."
705 (filtered-frame-list
706 (lambda (frame)
707 (eq frame (window-frame (minibuffer-window frame))))))
709 ;; Used to be called `terminal-id' in termdev.el.
710 (defun get-device-terminal (device)
711 "Return the terminal corresponding to DEVICE.
712 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
713 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
714 (cond
715 ((or (null device) (framep device))
716 (frame-terminal device))
717 ((stringp device)
718 (let ((f (car (filtered-frame-list
719 (lambda (frame)
720 (or (equal (frame-parameter frame 'display) device)
721 (equal (frame-parameter frame 'tty) device)))))))
722 (or f (error "Display %s does not exist" device))
723 (frame-terminal f)))
724 ((terminal-live-p device) device)
726 (error "Invalid argument %s in `get-device-terminal'" device))))
728 (defun frames-on-display-list (&optional device)
729 "Return a list of all frames on DEVICE.
731 DEVICE should be a terminal, a frame,
732 or a name of an X display or tty (a string of the form
733 HOST:SERVER.SCREEN).
735 If DEVICE is omitted or nil, it defaults to the selected
736 frame's terminal device."
737 (let* ((terminal (get-device-terminal device))
738 (func #'(lambda (frame)
739 (eq (frame-terminal frame) terminal))))
740 (filtered-frame-list func)))
742 (defun framep-on-display (&optional terminal)
743 "Return the type of frames on TERMINAL.
744 TERMINAL may be a terminal id, a display name or a frame. If it
745 is a frame, its type is returned. If TERMINAL is omitted or nil,
746 it defaults to the selected frame's terminal device. All frames
747 on a given display are of the same type."
748 (or (terminal-live-p terminal)
749 (framep terminal)
750 (framep (car (frames-on-display-list terminal)))))
752 (defun frame-remove-geometry-params (param-list)
753 "Return the parameter list PARAM-LIST, but with geometry specs removed.
754 This deletes all bindings in PARAM-LIST for `top', `left', `width',
755 `height', `user-size' and `user-position' parameters.
756 Emacs uses this to avoid overriding explicit moves and resizings from
757 the user during startup."
758 (setq param-list (cons nil param-list))
759 (let ((tail param-list))
760 (while (consp (cdr tail))
761 (if (and (consp (car (cdr tail)))
762 (memq (car (car (cdr tail)))
763 '(height width top left user-position user-size)))
764 (progn
765 (setq frame-initial-geometry-arguments
766 (cons (car (cdr tail)) frame-initial-geometry-arguments))
767 (setcdr tail (cdr (cdr tail))))
768 (setq tail (cdr tail)))))
769 (setq frame-initial-geometry-arguments
770 (nreverse frame-initial-geometry-arguments))
771 (cdr param-list))
773 (declare-function x-focus-frame "frame.c" (frame))
775 (defun select-frame-set-input-focus (frame &optional norecord)
776 "Select FRAME, raise it, and set input focus, if possible.
777 If `mouse-autoselect-window' is non-nil, also move mouse pointer
778 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
779 is non-nil, move mouse cursor to FRAME.
781 Optional argument NORECORD means to neither change the order of
782 recently selected windows nor the buffer list."
783 (select-frame frame norecord)
784 (raise-frame frame)
785 ;; Ensure, if possible, that FRAME gets input focus.
786 (when (memq (window-system frame) '(x w32 ns))
787 (x-focus-frame frame))
788 ;; Move mouse cursor if necessary.
789 (cond
790 (mouse-autoselect-window
791 (let ((edges (window-inside-edges (frame-selected-window frame))))
792 ;; Move mouse cursor into FRAME's selected window to avoid that
793 ;; Emacs mouse-autoselects another window.
794 (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
795 (focus-follows-mouse
796 ;; Move mouse cursor into FRAME to avoid that another frame gets
797 ;; selected by the window manager.
798 (set-mouse-position frame (1- (frame-width frame)) 0))))
800 (defun other-frame (arg)
801 "Select the ARGth different visible frame on current display, and raise it.
802 All frames are arranged in a cyclic order.
803 This command selects the frame ARG steps away in that order.
804 A negative ARG moves in the opposite order.
806 To make this command work properly, you must tell Emacs
807 how the system (or the window manager) generally handles
808 focus-switching between windows. If moving the mouse onto a window
809 selects it (gives it focus), set `focus-follows-mouse' to t.
810 Otherwise, that variable should be nil."
811 (interactive "p")
812 (let ((frame (selected-frame)))
813 (while (> arg 0)
814 (setq frame (next-frame frame))
815 (while (not (eq (frame-visible-p frame) t))
816 (setq frame (next-frame frame)))
817 (setq arg (1- arg)))
818 (while (< arg 0)
819 (setq frame (previous-frame frame))
820 (while (not (eq (frame-visible-p frame) t))
821 (setq frame (previous-frame frame)))
822 (setq arg (1+ arg)))
823 (select-frame-set-input-focus frame)))
825 (defun iconify-or-deiconify-frame ()
826 "Iconify the selected frame, or deiconify if it's currently an icon."
827 (interactive)
828 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
829 (iconify-frame)
830 (make-frame-visible)))
832 (defun suspend-frame ()
833 "Do whatever is right to suspend the current frame.
834 Calls `suspend-emacs' if invoked from the controlling tty device,
835 `suspend-tty' from a secondary tty device, and
836 `iconify-or-deiconify-frame' from an X frame."
837 (interactive)
838 (let ((type (framep (selected-frame))))
839 (cond
840 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
841 ((eq type t)
842 (if (controlling-tty-p)
843 (suspend-emacs)
844 (suspend-tty)))
845 (t (suspend-emacs)))))
847 (defun make-frame-names-alist ()
848 ;; Only consider the frames on the same display.
849 (let* ((current-frame (selected-frame))
850 (falist
851 (cons
852 (cons (frame-parameter current-frame 'name) current-frame) nil))
853 (frame (next-frame nil 0)))
854 (while (not (eq frame current-frame))
855 (progn
856 (push (cons (frame-parameter frame 'name) frame) falist)
857 (setq frame (next-frame frame 0))))
858 falist))
860 (defvar frame-name-history nil)
861 (defun select-frame-by-name (name)
862 "Select the frame on the current terminal whose name is NAME and raise it.
863 If there is no frame by that name, signal an error."
864 (interactive
865 (let* ((frame-names-alist (make-frame-names-alist))
866 (default (car (car frame-names-alist)))
867 (input (completing-read
868 (format "Select Frame (default %s): " default)
869 frame-names-alist nil t nil 'frame-name-history)))
870 (if (= (length input) 0)
871 (list default)
872 (list input))))
873 (let* ((frame-names-alist (make-frame-names-alist))
874 (frame (cdr (assoc name frame-names-alist))))
875 (if frame
876 (select-frame-set-input-focus frame)
877 (error "There is no frame named `%s'" name))))
880 ;;;; Background mode.
882 (defcustom frame-background-mode nil
883 "The brightness of the background.
884 Set this to the symbol `dark' if your background color is dark,
885 `light' if your background is light, or nil (automatic by default)
886 if you want Emacs to examine the brightness for you.
888 If you change this without using customize, you should use
889 `frame-set-background-mode' to update existing frames;
890 e.g. (mapc 'frame-set-background-mode (frame-list))."
891 :group 'faces
892 :set #'(lambda (var value)
893 (set-default var value)
894 (mapc 'frame-set-background-mode (frame-list)))
895 :initialize 'custom-initialize-changed
896 :type '(choice (const dark)
897 (const light)
898 (const :tag "automatic" nil)))
900 (declare-function x-get-resource "frame.c"
901 (attribute class &optional component subclass))
903 ;; Only used if window-system is not null.
904 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
906 (defvar inhibit-frame-set-background-mode nil)
908 (defun frame-set-background-mode (frame &optional keep-face-specs)
909 "Set up display-dependent faces on FRAME.
910 Display-dependent faces are those which have different definitions
911 according to the `background-mode' and `display-type' frame parameters.
913 If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
914 face specs for the new background mode."
915 (unless inhibit-frame-set-background-mode
916 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
917 (bg-color (frame-parameter frame 'background-color))
918 (tty-type (tty-type frame))
919 (default-bg-mode
920 (if (or (window-system frame)
921 (and tty-type
922 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
923 tty-type)))
924 'light
925 'dark))
926 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
927 (bg-mode
928 (cond (frame-default-bg-mode)
929 ((equal bg-color "unspecified-fg") ; inverted colors
930 non-default-bg-mode)
931 ((not (color-values bg-color frame))
932 default-bg-mode)
933 ((>= (apply '+ (color-values bg-color frame))
934 ;; Just looking at the screen, colors whose
935 ;; values add up to .6 of the white total
936 ;; still look dark to me.
937 (* (apply '+ (color-values "white" frame)) .6))
938 'light)
939 (t 'dark)))
940 (display-type
941 (cond ((null (window-system frame))
942 (if (tty-display-color-p frame) 'color 'mono))
943 ((display-color-p frame)
944 'color)
945 ((x-display-grayscale-p frame)
946 'grayscale)
947 (t 'mono)))
948 (old-bg-mode
949 (frame-parameter frame 'background-mode))
950 (old-display-type
951 (frame-parameter frame 'display-type)))
953 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
954 (let ((locally-modified-faces nil)
955 ;; Prevent face-spec-recalc from calling this function
956 ;; again, resulting in a loop (bug#911).
957 (inhibit-frame-set-background-mode t)
958 (params (list (cons 'background-mode bg-mode)
959 (cons 'display-type display-type))))
960 (if keep-face-specs
961 (modify-frame-parameters frame params)
962 ;; If we are recomputing face specs, first collect a list
963 ;; of faces that don't match their face-specs. These are
964 ;; the faces modified on FRAME, and we avoid changing them
965 ;; below. Use a negative list to avoid consing (we assume
966 ;; most faces are unmodified).
967 (dolist (face (face-list))
968 (and (not (get face 'face-override-spec))
969 (not (face-spec-match-p face
970 (face-user-default-spec face)
971 (selected-frame)))
972 (push face locally-modified-faces)))
973 ;; Now change to the new frame parameters
974 (modify-frame-parameters frame params)
975 ;; For all unmodified named faces, choose face specs
976 ;; matching the new frame parameters.
977 (dolist (face (face-list))
978 (unless (memq face locally-modified-faces)
979 (face-spec-recalc face frame)))))))))
981 (defun frame-terminal-default-bg-mode (frame)
982 "Return the default background mode of FRAME.
983 This checks the `frame-background-mode' variable, the X resource
984 named \"backgroundMode\" (if FRAME is an X frame), and finally
985 the `background-mode' terminal parameter."
986 (or frame-background-mode
987 (let ((bg-resource
988 (and (window-system frame)
989 (x-get-resource "backgroundMode" "BackgroundMode"))))
990 (if bg-resource
991 (intern (downcase bg-resource))))
992 (terminal-parameter frame 'background-mode)))
995 ;;;; Frame configurations
997 (defun current-frame-configuration ()
998 "Return a list describing the positions and states of all frames.
999 Its car is `frame-configuration'.
1000 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
1001 where
1002 FRAME is a frame object,
1003 ALIST is an association list specifying some of FRAME's parameters, and
1004 WINDOW-CONFIG is a window configuration object for FRAME."
1005 (cons 'frame-configuration
1006 (mapcar (lambda (frame)
1007 (list frame
1008 (frame-parameters frame)
1009 (current-window-configuration frame)))
1010 (frame-list))))
1012 (defun set-frame-configuration (configuration &optional nodelete)
1013 "Restore the frames to the state described by CONFIGURATION.
1014 Each frame listed in CONFIGURATION has its position, size, window
1015 configuration, and other parameters set as specified in CONFIGURATION.
1016 However, this function does not restore deleted frames.
1018 Ordinarily, this function deletes all existing frames not
1019 listed in CONFIGURATION. But if optional second argument NODELETE
1020 is given and non-nil, the unwanted frames are iconified instead."
1021 (or (frame-configuration-p configuration)
1022 (signal 'wrong-type-argument
1023 (list 'frame-configuration-p configuration)))
1024 (let ((config-alist (cdr configuration))
1025 frames-to-delete)
1026 (dolist (frame (frame-list))
1027 (let ((parameters (assq frame config-alist)))
1028 (if parameters
1029 (progn
1030 (modify-frame-parameters
1031 frame
1032 ;; Since we can't set a frame's minibuffer status,
1033 ;; we might as well omit the parameter altogether.
1034 (let* ((parms (nth 1 parameters))
1035 (mini (assq 'minibuffer parms))
1036 (name (assq 'name parms))
1037 (explicit-name (cdr (assq 'explicit-name parms))))
1038 (when mini (setq parms (delq mini parms)))
1039 ;; Leave name in iff it was set explicitly.
1040 ;; This should fix the behavior reported in
1041 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
1042 (when (and name (not explicit-name))
1043 (setq parms (delq name parms)))
1044 parms))
1045 (set-window-configuration (nth 2 parameters)))
1046 (setq frames-to-delete (cons frame frames-to-delete)))))
1047 (mapc (if nodelete
1048 ;; Note: making frames invisible here was tried
1049 ;; but led to some strange behavior--each time the frame
1050 ;; was made visible again, the window manager asked afresh
1051 ;; for where to put it.
1052 'iconify-frame
1053 'delete-frame)
1054 frames-to-delete)))
1056 ;;;; Convenience functions for accessing and interactively changing
1057 ;;;; frame parameters.
1059 (defun frame-height (&optional frame)
1060 "Return number of lines available for display on FRAME.
1061 If FRAME is omitted, describe the currently selected frame.
1062 Exactly what is included in the return value depends on the
1063 window-system and toolkit in use - see `frame-pixel-height' for
1064 more details. The lines are in units of the default font height.
1066 The result is roughly related to the frame pixel height via
1067 height in pixels = height in lines * `frame-char-height'.
1068 However, this is only approximate, and is complicated e.g. by the
1069 fact that individual window lines and menu bar lines can have
1070 differing font heights."
1071 (cdr (assq 'height (frame-parameters frame))))
1073 (defun frame-width (&optional frame)
1074 "Return number of columns available for display on FRAME.
1075 If FRAME is omitted, describe the currently selected frame."
1076 (cdr (assq 'width (frame-parameters frame))))
1078 (declare-function x-list-fonts "xfaces.c"
1079 (pattern &optional face frame maximum width))
1081 (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
1083 (defun set-frame-font (font &optional keep-size frames)
1084 "Set the default font to FONT.
1085 When called interactively, prompt for the name of a font, and use
1086 that font on the selected frame. When called from Lisp, FONT
1087 should be a font name (a string), a font object, font entity, or
1088 font spec.
1090 If KEEP-SIZE is nil, keep the number of frame lines and columns
1091 fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
1092 to keep the current frame size fixed (in pixels) by adjusting the
1093 number of lines and columns.
1095 If FRAMES is nil, apply the font to the selected frame only.
1096 If FRAMES is non-nil, it should be a list of frames to act upon,
1097 or t meaning all existing graphical frames.
1098 Also, if FRAMES is non-nil, alter the user's Customization settings
1099 as though the font-related attributes of the `default' face had been
1100 \"set in this session\", so that the font is applied to future frames."
1101 (interactive
1102 (let* ((completion-ignore-case t)
1103 (font (completing-read "Font name: "
1104 ;; x-list-fonts will fail with an error
1105 ;; if this frame doesn't support fonts.
1106 (x-list-fonts "*" nil (selected-frame))
1107 nil nil nil nil
1108 (frame-parameter nil 'font))))
1109 (list font current-prefix-arg nil)))
1110 (when (or (stringp font) (fontp font))
1111 (let* ((this-frame (selected-frame))
1112 ;; FRAMES nil means affect the selected frame.
1113 (frame-list (cond ((null frames)
1114 (list this-frame))
1115 ((eq frames t)
1116 (frame-list))
1117 (t frames)))
1118 height width)
1119 (dolist (f frame-list)
1120 (when (display-multi-font-p f)
1121 (if keep-size
1122 (setq height (* (frame-parameter f 'height)
1123 (frame-char-height f))
1124 width (* (frame-parameter f 'width)
1125 (frame-char-width f))))
1126 ;; When set-face-attribute is called for :font, Emacs
1127 ;; guesses the best font according to other face attributes
1128 ;; (:width, :weight, etc.) so reset them too (Bug#2476).
1129 (set-face-attribute 'default f
1130 :width 'normal :weight 'normal
1131 :slant 'normal :font font)
1132 (if keep-size
1133 (modify-frame-parameters
1135 (list (cons 'height (round height (frame-char-height f)))
1136 (cons 'width (round width (frame-char-width f))))))))
1137 (when frames
1138 ;; Alter the user's Custom setting of the `default' face, but
1139 ;; only for font-related attributes.
1140 (let ((specs (cadr (assq 'user (get 'default 'theme-face))))
1141 (attrs '(:family :foundry :slant :weight :height :width))
1142 (new-specs nil))
1143 (if (null specs) (setq specs '((t nil))))
1144 (dolist (spec specs)
1145 ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
1146 (let ((display (nth 0 spec))
1147 (plist (copy-tree (nth 1 spec))))
1148 ;; Alter only DISPLAY conditions matching this frame.
1149 (when (or (memq display '(t default))
1150 (face-spec-set-match-display display this-frame))
1151 (dolist (attr attrs)
1152 (setq plist (plist-put plist attr
1153 (face-attribute 'default attr)))))
1154 (push (list display plist) new-specs)))
1155 (setq new-specs (nreverse new-specs))
1156 (put 'default 'customized-face new-specs)
1157 (custom-push-theme 'theme-face 'default 'user 'set new-specs)
1158 (put 'default 'face-modified nil))))
1159 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))
1161 (defun set-frame-parameter (frame parameter value)
1162 "Set frame parameter PARAMETER to VALUE on FRAME.
1163 If FRAME is nil, it defaults to the selected frame.
1164 See `modify-frame-parameters'."
1165 (modify-frame-parameters frame (list (cons parameter value))))
1167 (defun set-background-color (color-name)
1168 "Set the background color of the selected frame to COLOR-NAME.
1169 When called interactively, prompt for the name of the color to use.
1170 To get the frame's current background color, use `frame-parameters'."
1171 (interactive (list (read-color "Background color: ")))
1172 (modify-frame-parameters (selected-frame)
1173 (list (cons 'background-color color-name)))
1174 (or window-system
1175 (face-set-after-frame-default (selected-frame))))
1177 (defun set-foreground-color (color-name)
1178 "Set the foreground color of the selected frame to COLOR-NAME.
1179 When called interactively, prompt for the name of the color to use.
1180 To get the frame's current foreground color, use `frame-parameters'."
1181 (interactive (list (read-color "Foreground color: ")))
1182 (modify-frame-parameters (selected-frame)
1183 (list (cons 'foreground-color color-name)))
1184 (or window-system
1185 (face-set-after-frame-default (selected-frame))))
1187 (defun set-cursor-color (color-name)
1188 "Set the text cursor color of the selected frame to COLOR-NAME.
1189 When called interactively, prompt for the name of the color to use.
1190 This works by setting the `cursor-color' frame parameter on the
1191 selected frame.
1193 You can also set the text cursor color, for all frames, by
1194 customizing the `cursor' face."
1195 (interactive (list (read-color "Cursor color: ")))
1196 (modify-frame-parameters (selected-frame)
1197 (list (cons 'cursor-color color-name))))
1199 (defun set-mouse-color (color-name)
1200 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1201 When called interactively, prompt for the name of the color to use.
1202 To get the frame's current mouse color, use `frame-parameters'."
1203 (interactive (list (read-color "Mouse color: ")))
1204 (modify-frame-parameters (selected-frame)
1205 (list (cons 'mouse-color
1206 (or color-name
1207 (cdr (assq 'mouse-color
1208 (frame-parameters))))))))
1210 (defun set-border-color (color-name)
1211 "Set the color of the border of the selected frame to COLOR-NAME.
1212 When called interactively, prompt for the name of the color to use.
1213 To get the frame's current border color, use `frame-parameters'."
1214 (interactive (list (read-color "Border color: ")))
1215 (modify-frame-parameters (selected-frame)
1216 (list (cons 'border-color color-name))))
1218 (define-minor-mode auto-raise-mode
1219 "Toggle whether or not selected frames should auto-raise.
1220 With a prefix argument ARG, enable Auto Raise mode if ARG is
1221 positive, and disable it otherwise. If called from Lisp, enable
1222 the mode if ARG is omitted or nil.
1224 Auto Raise mode does nothing under most window managers, which
1225 switch focus on mouse clicks. It only has an effect if your
1226 window manager switches focus on mouse movement (in which case
1227 you should also change `focus-follows-mouse' to t). Then,
1228 enabling Auto Raise mode causes any graphical Emacs frame which
1229 acquires focus to be automatically raised.
1231 Note that this minor mode controls Emacs's own auto-raise
1232 feature. Window managers that switch focus on mouse movement
1233 often have their own auto-raise feature."
1234 :variable (frame-parameter nil 'auto-raise)
1235 (if (frame-parameter nil 'auto-raise)
1236 (raise-frame)))
1238 (define-minor-mode auto-lower-mode
1239 "Toggle whether or not the selected frame should auto-lower.
1240 With a prefix argument ARG, enable Auto Lower mode if ARG is
1241 positive, and disable it otherwise. If called from Lisp, enable
1242 the mode if ARG is omitted or nil.
1244 Auto Lower mode does nothing under most window managers, which
1245 switch focus on mouse clicks. It only has an effect if your
1246 window manager switches focus on mouse movement (in which case
1247 you should also change `focus-follows-mouse' to t). Then,
1248 enabling Auto Lower Mode causes any graphical Emacs frame which
1249 loses focus to be automatically lowered.
1251 Note that this minor mode controls Emacs's own auto-lower
1252 feature. Window managers that switch focus on mouse movement
1253 often have their own features for raising or lowering frames."
1254 :variable (frame-parameter nil 'auto-lower))
1256 (defun set-frame-name (name)
1257 "Set the name of the selected frame to NAME.
1258 When called interactively, prompt for the name of the frame.
1259 On text terminals, the frame name is displayed on the mode line.
1260 On graphical displays, it is displayed on the frame's title bar."
1261 (interactive "sFrame name: ")
1262 (modify-frame-parameters (selected-frame)
1263 (list (cons 'name name))))
1265 (defun frame-current-scroll-bars (&optional frame)
1266 "Return the current scroll-bar settings in frame FRAME.
1267 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1268 current location of the vertical scroll-bars (left, right, or nil),
1269 and HORIZONTAL specifies the current location of the horizontal scroll
1270 bars (top, bottom, or nil)."
1271 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
1272 (hor nil))
1273 (unless (memq vert '(left right nil))
1274 (setq vert default-frame-scroll-bars))
1275 (cons vert hor)))
1277 (defun frame-monitor-attributes (&optional frame)
1278 "Return the attributes of the physical monitor dominating FRAME.
1279 If FRAME is omitted, describe the currently selected frame.
1281 A frame is dominated by a physical monitor when either the
1282 largest area of the frame resides in the monitor, or the monitor
1283 is the closest to the frame if the frame does not intersect any
1284 physical monitors.
1286 See `display-monitor-attributes-list' for the list of attribute
1287 keys and their meanings."
1288 (or frame (setq frame (selected-frame)))
1289 (cl-loop for attributes in (display-monitor-attributes-list frame)
1290 for frames = (cdr (assq 'frames attributes))
1291 if (memq frame frames) return attributes))
1294 ;;;; Frame/display capabilities.
1296 (declare-function msdos-mouse-p "dosfns.c")
1298 (defun display-mouse-p (&optional display)
1299 "Return non-nil if DISPLAY has a mouse available.
1300 DISPLAY can be a display name, a frame, or nil (meaning the selected
1301 frame's display)."
1302 (let ((frame-type (framep-on-display display)))
1303 (cond
1304 ((eq frame-type 'pc)
1305 (msdos-mouse-p))
1306 ((eq frame-type 'w32)
1307 (with-no-warnings
1308 (> w32-num-mouse-buttons 0)))
1309 ((memq frame-type '(x ns))
1310 t) ;; We assume X and NeXTstep *always* have a pointing device
1312 (or (and (featurep 'xt-mouse)
1313 xterm-mouse-mode)
1314 ;; t-mouse is distributed with the GPM package. It doesn't have
1315 ;; a toggle.
1316 (featurep 't-mouse)
1317 ;; No way to check whether a w32 console has a mouse, assume
1318 ;; it always does.
1319 (boundp 'w32-use-full-screen-buffer))))))
1321 (defun display-popup-menus-p (&optional display)
1322 "Return non-nil if popup menus are supported on DISPLAY.
1323 DISPLAY can be a display name, a frame, or nil (meaning the selected
1324 frame's display).
1325 Support for popup menus requires that the mouse be available."
1326 (display-mouse-p display))
1328 (defun display-graphic-p (&optional display)
1329 "Return non-nil if DISPLAY is a graphic display.
1330 Graphical displays are those which are capable of displaying several
1331 frames and several different fonts at once. This is true for displays
1332 that use a window system such as X, and false for text-only terminals.
1333 DISPLAY can be a display name, a frame, or nil (meaning the selected
1334 frame's display)."
1335 (not (null (memq (framep-on-display display) '(x w32 ns)))))
1337 (defun display-images-p (&optional display)
1338 "Return non-nil if DISPLAY can display images.
1340 DISPLAY can be a display name, a frame, or nil (meaning the selected
1341 frame's display)."
1342 (and (display-graphic-p display)
1343 (fboundp 'image-mask-p)
1344 (fboundp 'image-size)))
1346 (defalias 'display-multi-frame-p 'display-graphic-p)
1347 (defalias 'display-multi-font-p 'display-graphic-p)
1349 (defun display-selections-p (&optional display)
1350 "Return non-nil if DISPLAY supports selections.
1351 A selection is a way to transfer text or other data between programs
1352 via special system buffers called `selection' or `clipboard'.
1353 DISPLAY can be a display name, a frame, or nil (meaning the selected
1354 frame's display)."
1355 (let ((frame-type (framep-on-display display)))
1356 (cond
1357 ((eq frame-type 'pc)
1358 ;; MS-DOS frames support selections when Emacs runs inside
1359 ;; a Windows DOS Box.
1360 (with-no-warnings
1361 (not (null dos-windows-version))))
1362 ((memq frame-type '(x w32 ns))
1365 nil))))
1367 (declare-function x-display-screens "xfns.c" (&optional terminal))
1369 (defun display-screens (&optional display)
1370 "Return the number of screens associated with DISPLAY.
1371 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1372 (let ((frame-type (framep-on-display display)))
1373 (cond
1374 ((memq frame-type '(x w32 ns))
1375 (x-display-screens display))
1377 1))))
1379 (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
1381 (defun display-pixel-height (&optional display)
1382 "Return the height of DISPLAY's screen in pixels.
1383 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1385 For character terminals, each character counts as a single pixel.
1387 For graphical terminals, note that on \"multi-monitor\" setups this
1388 refers to the pixel height for all physical monitors associated
1389 with DISPLAY. To get information for each physical monitor, use
1390 `display-monitor-attributes-list'."
1391 (let ((frame-type (framep-on-display display)))
1392 (cond
1393 ((memq frame-type '(x w32 ns))
1394 (x-display-pixel-height display))
1396 (frame-height (if (framep display) display (selected-frame)))))))
1398 (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
1400 (defun display-pixel-width (&optional display)
1401 "Return the width of DISPLAY's screen in pixels.
1402 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1404 For character terminals, each character counts as a single pixel.
1406 For graphical terminals, note that on \"multi-monitor\" setups this
1407 refers to the pixel width for all physical monitors associated
1408 with DISPLAY. To get information for each physical monitor, use
1409 `display-monitor-attributes-list'."
1410 (let ((frame-type (framep-on-display display)))
1411 (cond
1412 ((memq frame-type '(x w32 ns))
1413 (x-display-pixel-width display))
1415 (frame-width (if (framep display) display (selected-frame)))))))
1417 (defcustom display-mm-dimensions-alist nil
1418 "Alist for specifying screen dimensions in millimeters.
1419 The functions `display-mm-height' and `display-mm-width' consult
1420 this list before asking the system.
1422 Each element has the form (DISPLAY . (WIDTH . HEIGHT)), e.g.
1423 \(\":0.0\" . (287 . 215)).
1425 If `display' is t, it specifies dimensions for all graphical displays
1426 not explicitly specified."
1427 :version "22.1"
1428 :type '(alist :key-type (choice (string :tag "Display name")
1429 (const :tag "Default" t))
1430 :value-type (cons :tag "Dimensions"
1431 (integer :tag "Width")
1432 (integer :tag "Height")))
1433 :group 'frames)
1435 (declare-function x-display-mm-height "xfns.c" (&optional terminal))
1437 (defun display-mm-height (&optional display)
1438 "Return the height of DISPLAY's screen in millimeters.
1439 If the information is unavailable, this function returns nil.
1440 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1442 You can override what the system thinks the result should be by
1443 adding an entry to `display-mm-dimensions-alist'.
1445 For graphical terminals, note that on \"multi-monitor\" setups this
1446 refers to the height in millimeters for all physical monitors
1447 associated with DISPLAY. To get information for each physical
1448 monitor, use `display-monitor-attributes-list'."
1449 (and (memq (framep-on-display display) '(x w32 ns))
1450 (or (cddr (assoc (or display (frame-parameter nil 'display))
1451 display-mm-dimensions-alist))
1452 (cddr (assoc t display-mm-dimensions-alist))
1453 (x-display-mm-height display))))
1455 (declare-function x-display-mm-width "xfns.c" (&optional terminal))
1457 (defun display-mm-width (&optional display)
1458 "Return the width of DISPLAY's screen in millimeters.
1459 If the information is unavailable, this function returns nil.
1460 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1462 You can override what the system thinks the result should be by
1463 adding an entry to `display-mm-dimensions-alist'.
1465 For graphical terminals, note that on \"multi-monitor\" setups this
1466 refers to the width in millimeters for all physical monitors
1467 associated with DISPLAY. To get information for each physical
1468 monitor, use `display-monitor-attributes-list'."
1469 (and (memq (framep-on-display display) '(x w32 ns))
1470 (or (cadr (assoc (or display (frame-parameter nil 'display))
1471 display-mm-dimensions-alist))
1472 (cadr (assoc t display-mm-dimensions-alist))
1473 (x-display-mm-width display))))
1475 (declare-function x-display-backing-store "xfns.c" (&optional terminal))
1477 ;; In NS port, the return value may be `buffered', `retained', or
1478 ;; `non-retained'. See src/nsfns.m.
1479 (defun display-backing-store (&optional display)
1480 "Return the backing store capability of DISPLAY's screen.
1481 The value may be `always', `when-mapped', `not-useful', or nil if
1482 the question is inapplicable to a certain kind of display.
1483 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1484 (let ((frame-type (framep-on-display display)))
1485 (cond
1486 ((memq frame-type '(x w32 ns))
1487 (x-display-backing-store display))
1489 'not-useful))))
1491 (declare-function x-display-save-under "xfns.c" (&optional terminal))
1493 (defun display-save-under (&optional display)
1494 "Return non-nil if DISPLAY's screen supports the SaveUnder feature.
1495 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1496 (let ((frame-type (framep-on-display display)))
1497 (cond
1498 ((memq frame-type '(x w32 ns))
1499 (x-display-save-under display))
1501 'not-useful))))
1503 (declare-function x-display-planes "xfns.c" (&optional terminal))
1505 (defun display-planes (&optional display)
1506 "Return the number of planes supported by DISPLAY.
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-planes display))
1512 ((eq frame-type 'pc)
1515 (truncate (log (length (tty-color-alist)) 2))))))
1517 (declare-function x-display-color-cells "xfns.c" (&optional terminal))
1519 (defun display-color-cells (&optional display)
1520 "Return the number of color cells supported by DISPLAY.
1521 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1522 (let ((frame-type (framep-on-display display)))
1523 (cond
1524 ((memq frame-type '(x w32 ns))
1525 (x-display-color-cells display))
1526 ((eq frame-type 'pc)
1529 (tty-display-color-cells display)))))
1531 (declare-function x-display-visual-class "xfns.c" (&optional terminal))
1533 (defun display-visual-class (&optional display)
1534 "Return the visual class of DISPLAY.
1535 The value is one of the symbols `static-gray', `gray-scale',
1536 `static-color', `pseudo-color', `true-color', or `direct-color'.
1537 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1538 (let ((frame-type (framep-on-display display)))
1539 (cond
1540 ((memq frame-type '(x w32 ns))
1541 (x-display-visual-class display))
1542 ((and (memq frame-type '(pc t))
1543 (tty-display-color-p display))
1544 'static-color)
1546 'static-gray))))
1548 (declare-function x-display-monitor-attributes-list "xfns.c"
1549 (&optional terminal))
1550 (declare-function w32-display-monitor-attributes-list "w32fns.c"
1551 (&optional display))
1552 (declare-function ns-display-monitor-attributes-list "nsfns.m"
1553 (&optional terminal))
1555 (defun display-monitor-attributes-list (&optional display)
1556 "Return a list of physical monitor attributes on DISPLAY.
1557 Each element of the list represents the attributes of each
1558 physical monitor. The first element corresponds to the primary
1559 monitor.
1561 Attributes for a physical monitor is represented as an alist of
1562 attribute keys and values as follows:
1564 geometry -- Position and size in pixels in the form of
1565 (X Y WIDTH HEIGHT)
1566 workarea -- Position and size of the workarea in pixels in the
1567 form of (X Y WIDTH HEIGHT)
1568 mm-size -- Width and height in millimeters in the form of
1569 (WIDTH HEIGHT)
1570 frames -- List of frames dominated by the physical monitor
1571 name (*) -- Name of the physical monitor as a string
1573 where X, Y, WIDTH, and HEIGHT are integers. Keys labeled
1574 with (*) are optional.
1576 A frame is dominated by a physical monitor when either the
1577 largest area of the frame resides in the monitor, or the monitor
1578 is the closest to the frame if the frame does not intersect any
1579 physical monitors. Every non-tip frame (including invisible one)
1580 in a graphical display is dominated by exactly one physical
1581 monitor at a time, though it can span multiple (or no) physical
1582 monitors.
1583 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1584 (let ((frame-type (framep-on-display display)))
1585 (cond
1586 ((eq frame-type 'x)
1587 (x-display-monitor-attributes-list display))
1588 ((eq frame-type 'w32)
1589 (w32-display-monitor-attributes-list display))
1590 ((eq frame-type 'ns)
1591 (ns-display-monitor-attributes-list display))
1593 (let ((geometry (list 0 0 (display-pixel-width display)
1594 (display-pixel-height display))))
1595 `(((geometry . ,geometry)
1596 (workarea . ,geometry)
1597 (mm-size . (,(display-mm-width display)
1598 ,(display-mm-height display)))
1599 (frames . ,(frames-on-display-list display)))))))))
1602 ;;;; Frame geometry values
1604 (defun frame-geom-value-cons (type value &optional frame)
1605 "Return equivalent geometry value for FRAME as a cons with car `+'.
1606 A geometry value equivalent to VALUE for FRAME is returned,
1607 where the value is a cons with car `+', not numeric.
1608 TYPE is the car of the original geometry spec (TYPE . VALUE).
1609 It is `top' or `left', depending on which edge VALUE is related to.
1610 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1611 If VALUE is a number, then it is converted to a cons value, perhaps
1612 relative to the opposite frame edge from that in the original spec.
1613 FRAME defaults to the selected frame.
1615 Examples (measures in pixels) -
1616 Assuming display height/width=1024, frame height/width=600:
1617 300 inside display edge: 300 => (+ 300)
1618 (+ 300) => (+ 300)
1619 300 inside opposite display edge: (- 300) => (+ 124)
1620 -300 => (+ 124)
1621 300 beyond display edge
1622 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1623 300 beyond display edge
1624 (= 724 inside opposite display edge): (- -300) => (+ 724)
1626 In the 3rd, 4th, and 6th examples, the returned value is relative to
1627 the opposite frame edge from the edge indicated in the input spec."
1628 (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
1629 value)
1630 ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
1631 (t ; e.g. -300, (- 300), (- -300)
1632 (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
1633 (x-display-pixel-width)
1634 (x-display-pixel-height))
1635 (if (integerp value) (- value) (cadr value))
1636 (if (eq 'left type)
1637 (frame-pixel-width frame)
1638 (frame-pixel-height frame)))))))
1640 (defun frame-geom-spec-cons (spec &optional frame)
1641 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1642 A geometry specification equivalent to SPEC for FRAME is returned,
1643 where the value is a cons with car `+', not numeric.
1644 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1645 If VALUE is a number, then it is converted to a cons value, perhaps
1646 relative to the opposite frame edge from that in the original spec.
1647 FRAME defaults to the selected frame.
1649 Examples (measures in pixels) -
1650 Assuming display height=1024, frame height=600:
1651 top 300 below display top: (top . 300) => (top + 300)
1652 (top + 300) => (top + 300)
1653 bottom 300 above display bottom: (top - 300) => (top + 124)
1654 (top . -300) => (top + 124)
1655 top 300 above display top
1656 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1657 bottom 300 below display bottom
1658 (= top 724 below display top): (top - -300) => (top + 724)
1660 In the 3rd, 4th, and 6th examples, the returned value is relative to
1661 the opposite frame edge from the edge indicated in the input spec."
1662 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
1665 (defun delete-other-frames (&optional frame)
1666 "Delete all frames on the current terminal, except FRAME.
1667 If FRAME uses another frame's minibuffer, the minibuffer frame is
1668 left untouched. FRAME nil or omitted means use the selected frame."
1669 (interactive)
1670 (unless frame
1671 (setq frame (selected-frame)))
1672 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1673 (frames (delq mini-frame (delq frame (frame-list)))))
1674 ;; Only consider frames on the same terminal.
1675 (dolist (frame (prog1 frames (setq frames nil)))
1676 (if (eq (frame-terminal) (frame-terminal frame))
1677 (push frame frames)))
1678 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1679 ;; signals an error when trying to delete a mini-frame that's
1680 ;; still in use by another frame.
1681 (dolist (frame frames)
1682 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1683 (delete-frame frame)))
1684 ;; Delete minibuffer-only frames.
1685 (dolist (frame frames)
1686 (when (eq (frame-parameter frame 'minibuffer) 'only)
1687 (delete-frame frame)))))
1689 ;; miscellaneous obsolescence declarations
1690 (define-obsolete-variable-alias 'delete-frame-hook
1691 'delete-frame-functions "22.1")
1694 ;; Blinking cursor
1696 (defgroup cursor nil
1697 "Displaying text cursors."
1698 :version "21.1"
1699 :group 'frames)
1701 (defcustom blink-cursor-delay 0.5
1702 "Seconds of idle time after which cursor starts to blink."
1703 :type 'number
1704 :group 'cursor)
1706 (defcustom blink-cursor-interval 0.5
1707 "Length of cursor blink interval in seconds."
1708 :type 'number
1709 :group 'cursor)
1711 (defcustom blink-cursor-blinks 10
1712 "How many times to blink before using a solid cursor on NS, X, and MS-Windows.
1713 Use 0 or negative value to blink forever."
1714 :version "24.4"
1715 :type 'integer
1716 :group 'cursor)
1718 (defvar blink-cursor-blinks-done 1
1719 "Number of blinks done since we started blinking on NS, X, and MS-Windows.")
1721 (defvar blink-cursor-idle-timer nil
1722 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1723 The function `blink-cursor-start' is called when the timer fires.")
1725 (defvar blink-cursor-timer nil
1726 "Timer started from `blink-cursor-start'.
1727 This timer calls `blink-cursor-timer-function' every
1728 `blink-cursor-interval' seconds.")
1730 (defun blink-cursor-start ()
1731 "Timer function called from the timer `blink-cursor-idle-timer'.
1732 This starts the timer `blink-cursor-timer', which makes the cursor blink
1733 if appropriate. It also arranges to cancel that timer when the next
1734 command starts, by installing a pre-command hook."
1735 (when (null blink-cursor-timer)
1736 ;; Set up the timer first, so that if this signals an error,
1737 ;; blink-cursor-end is not added to pre-command-hook.
1738 (setq blink-cursor-blinks-done 1)
1739 (setq blink-cursor-timer
1740 (run-with-timer blink-cursor-interval blink-cursor-interval
1741 'blink-cursor-timer-function))
1742 (add-hook 'pre-command-hook 'blink-cursor-end)
1743 (internal-show-cursor nil nil)))
1745 (defun blink-cursor-timer-function ()
1746 "Timer function of timer `blink-cursor-timer'."
1747 (internal-show-cursor nil (not (internal-show-cursor-p)))
1748 ;; Each blink is two calls to this function.
1749 (setq blink-cursor-blinks-done (1+ blink-cursor-blinks-done))
1750 (when (and (> blink-cursor-blinks 0)
1751 (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done))
1752 (blink-cursor-suspend)
1753 (add-hook 'post-command-hook 'blink-cursor-check)))
1756 (defun blink-cursor-end ()
1757 "Stop cursor blinking.
1758 This is installed as a pre-command hook by `blink-cursor-start'.
1759 When run, it cancels the timer `blink-cursor-timer' and removes
1760 itself as a pre-command hook."
1761 (remove-hook 'pre-command-hook 'blink-cursor-end)
1762 (internal-show-cursor nil t)
1763 (when blink-cursor-timer
1764 (cancel-timer blink-cursor-timer)
1765 (setq blink-cursor-timer nil)))
1767 (defun blink-cursor-suspend ()
1768 "Suspend cursor blinking.
1769 This is called when no frame has focus and timers can be suspended.
1770 Timers are restarted by `blink-cursor-check', which is called when a
1771 frame receives focus."
1772 (blink-cursor-end)
1773 (when blink-cursor-idle-timer
1774 (cancel-timer blink-cursor-idle-timer)
1775 (setq blink-cursor-idle-timer nil)))
1777 (defun blink-cursor-check ()
1778 "Check if cursor blinking shall be restarted.
1779 This is done when a frame gets focus. Blink timers may be stopped by
1780 `blink-cursor-suspend'."
1781 (when (and blink-cursor-mode
1782 (not blink-cursor-idle-timer))
1783 (remove-hook 'post-command-hook 'blink-cursor-check)
1784 (setq blink-cursor-idle-timer
1785 (run-with-idle-timer blink-cursor-delay
1786 blink-cursor-delay
1787 'blink-cursor-start))))
1789 (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
1791 (define-minor-mode blink-cursor-mode
1792 "Toggle cursor blinking (Blink Cursor mode).
1793 With a prefix argument ARG, enable Blink Cursor mode if ARG is
1794 positive, and disable it otherwise. If called from Lisp, enable
1795 the mode if ARG is omitted or nil.
1797 If the value of `blink-cursor-blinks' is positive (10 by default),
1798 the cursor stops blinking after that number of blinks, if Emacs
1799 gets no input during that time.
1801 See also `blink-cursor-interval' and `blink-cursor-delay'.
1803 This command is effective only on graphical frames. On text-only
1804 terminals, cursor blinking is controlled by the terminal."
1805 :init-value (not (or noninteractive
1806 no-blinking-cursor
1807 (eq system-type 'ms-dos)
1808 (not (memq window-system '(x w32 ns)))))
1809 :initialize 'custom-initialize-delay
1810 :group 'cursor
1811 :global t
1812 (blink-cursor-suspend)
1813 (remove-hook 'focus-in-hook #'blink-cursor-check)
1814 (remove-hook 'focus-out-hook #'blink-cursor-suspend)
1815 (when blink-cursor-mode
1816 (add-hook 'focus-in-hook #'blink-cursor-check)
1817 (add-hook 'focus-out-hook #'blink-cursor-suspend)
1818 (setq blink-cursor-idle-timer
1819 (run-with-idle-timer blink-cursor-delay
1820 blink-cursor-delay
1821 #'blink-cursor-start))))
1824 ;; Frame maximization/fullscreen
1826 (defun toggle-frame-maximized ()
1827 "Toggle maximization state of the selected frame.
1828 Maximize the selected frame or un-maximize if it is already maximized.
1829 Respect window manager screen decorations.
1830 If the frame is in fullscreen mode, don't change its mode,
1831 just toggle the temporary frame parameter `maximized',
1832 so the frame will go to the right maximization state
1833 after disabling fullscreen mode.
1835 Note that with some window managers you may have to set
1836 `frame-resize-pixelwise' to non-nil in order to make a frame
1837 appear truly maximized.
1839 See also `toggle-frame-fullscreen'."
1840 (interactive)
1841 (if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1842 (modify-frame-parameters
1844 `((maximized
1845 . ,(unless (eq (frame-parameter nil 'maximized) 'maximized)
1846 'maximized))))
1847 (modify-frame-parameters
1849 `((fullscreen
1850 . ,(unless (eq (frame-parameter nil 'fullscreen) 'maximized)
1851 'maximized))))))
1853 (defun toggle-frame-fullscreen ()
1854 "Toggle fullscreen mode of the selected frame.
1855 Enable fullscreen mode of the selected frame or disable if it is
1856 already fullscreen. Ignore window manager screen decorations.
1857 When turning on fullscreen mode, remember the previous value of the
1858 maximization state in the temporary frame parameter `maximized'.
1859 Restore the maximization state when turning off fullscreen mode.
1861 Note that with some window managers you may have to set
1862 `frame-resize-pixelwise' to non-nil in order to make a frame
1863 appear truly fullscreen.
1865 See also `toggle-frame-maximized'."
1866 (interactive)
1867 (modify-frame-parameters
1869 `((maximized
1870 . ,(unless (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1871 (frame-parameter nil 'fullscreen)))
1872 (fullscreen
1873 . ,(if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1874 (if (eq (frame-parameter nil 'maximized) 'maximized)
1875 'maximized)
1876 'fullscreen)))))
1879 ;;;; Key bindings
1881 (define-key ctl-x-5-map "2" 'make-frame-command)
1882 (define-key ctl-x-5-map "1" 'delete-other-frames)
1883 (define-key ctl-x-5-map "0" 'delete-frame)
1884 (define-key ctl-x-5-map "o" 'other-frame)
1885 (define-key global-map [f11] 'toggle-frame-fullscreen)
1886 (define-key global-map [(meta f10)] 'toggle-frame-maximized)
1887 (define-key esc-map [f10] 'toggle-frame-maximized)
1890 ;; Misc.
1892 ;; Only marked as obsolete in 24.3.
1893 (define-obsolete-variable-alias 'automatic-hscrolling
1894 'auto-hscroll-mode "22.1")
1896 (make-variable-buffer-local 'show-trailing-whitespace)
1898 ;; Defined in dispnew.c.
1899 (make-obsolete-variable
1900 'window-system-version "it does not give useful information." "24.3")
1902 (provide 'frame)
1904 ;;; frame.el ends here