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