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