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