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