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