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