gnus-article-read-summary-keys: Don't move point for WDD and WDW commands
[emacs.git] / lisp / frame.el
blobb7a551692812dc6626521ab2635715f50955f401
1 ;;; frame.el --- multi-frame management independent of window systems -*- lexical-binding:t -*-
3 ;; Copyright (C) 1993-1994, 1996-1997, 2000-2017 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-generic-define-context-rewriter window-system (value)
37 ;; If `value' is a `consp', it's probably an old-style specializer,
38 ;; so just use it, and anyway `eql' isn't very useful on cons cells.
39 `(window-system ,(if (consp value) value `(eql ,value))))
41 (cl-defmethod frame-creation-function (params &context (window-system nil))
42 ;; It's tempting to get rid of tty-create-frame-with-faces and turn it into
43 ;; this method (i.e. move this method to faces.el), but faces.el is loaded
44 ;; much earlier from loadup.el (before cl-generic and even before
45 ;; cl-preloaded), so we'd first have to reorder that part.
46 (tty-create-frame-with-faces params))
48 (defvar window-system-default-frame-alist nil
49 "Window-system dependent default frame parameters.
50 The value should be an alist of elements (WINDOW-SYSTEM . ALIST),
51 where WINDOW-SYSTEM is a window system symbol (as returned by `framep')
52 and ALIST is a frame parameter alist like `default-frame-alist'.
53 Then, for frames on WINDOW-SYSTEM, any parameters specified in
54 ALIST supersede the corresponding parameters specified in
55 `default-frame-alist'.")
57 (defvar display-format-alist nil
58 "Alist of patterns to decode display names.
59 The car of each entry is a regular expression matching a display
60 name string. The cdr is a symbol giving the window-system that
61 handles the corresponding kind of display.")
63 ;; The initial value given here used to ask for a minibuffer.
64 ;; But that's not necessary, because the default is to have one.
65 ;; By not specifying it here, we let an X resource specify it.
66 (defcustom initial-frame-alist nil
67 "Alist of parameters for the initial X window frame.
68 You can set this in your init file; for example,
70 (setq initial-frame-alist
71 \\='((top . 1) (left . 1) (width . 80) (height . 55)))
73 Parameters specified here supersede the values given in
74 `default-frame-alist'.
76 If the value calls for a frame without a minibuffer, and you have
77 not created a minibuffer frame on your own, a minibuffer frame is
78 created according to `minibuffer-frame-alist'.
80 You can specify geometry-related options for just the initial
81 frame by setting this variable in your init file; however, they
82 won't take effect until Emacs reads your init file, which happens
83 after creating the initial frame. If you want the initial frame
84 to have the proper geometry as soon as it appears, you need to
85 use this three-step process:
86 * Specify X resources to give the geometry you want.
87 * Set `default-frame-alist' to override these options so that they
88 don't affect subsequent frames.
89 * Set `initial-frame-alist' in a way that matches the X resources,
90 to override what you put in `default-frame-alist'."
91 :type '(repeat (cons :format "%v"
92 (symbol :tag "Parameter")
93 (sexp :tag "Value")))
94 :group 'frames)
96 (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
97 "Alist of parameters for the initial minibuffer frame.
98 This is the minibuffer frame created if `initial-frame-alist'
99 calls for a frame without a minibuffer. The parameters specified
100 here supersede those given in `default-frame-alist', for the
101 initial minibuffer frame.
103 You can set this in your init file; for example,
105 (setq minibuffer-frame-alist
106 \\='((top . 1) (left . 1) (width . 80) (height . 2)))
108 It is not necessary to include (minibuffer . only); that is
109 appended when the minibuffer frame is created."
110 :type '(repeat (cons :format "%v"
111 (symbol :tag "Parameter")
112 (sexp :tag "Value")))
113 :group 'frames)
115 (defun handle-delete-frame (event)
116 "Handle delete-frame events from the X server."
117 (interactive "e")
118 (let* ((frame (posn-window (event-start event))))
119 (if (catch 'other-frame
120 (dolist (frame-1 (frame-list))
121 ;; A valid "other" frame is visible, has its `delete-before'
122 ;; parameter unset and is not a child frame.
123 (when (and (not (eq frame-1 frame))
124 (frame-visible-p frame-1)
125 (not (frame-parent frame-1))
126 (not (frame-parameter frame-1 'delete-before)))
127 (throw 'other-frame t))))
128 (delete-frame frame t)
129 ;; Gildea@x.org says it is ok to ask questions before terminating.
130 (save-buffers-kill-emacs))))
132 (defun handle-focus-in (_event)
133 "Handle a focus-in event.
134 Focus-in events are usually bound to this function.
135 Focus-in events occur when a frame has focus, but a switch-frame event
136 is not generated.
137 This function runs the hook `focus-in-hook'."
138 (interactive "e")
139 (run-hooks 'focus-in-hook))
141 (defun handle-focus-out (_event)
142 "Handle a focus-out event.
143 Focus-out events are usually bound to this function.
144 Focus-out events occur when no frame has focus.
145 This function runs the hook `focus-out-hook'."
146 (interactive "e")
147 (run-hooks 'focus-out-hook))
149 (defun handle-move-frame (event)
150 "Handle a move-frame event.
151 This function runs the abnormal hook `move-frame-functions'."
152 (interactive "e")
153 (let ((frame (posn-window (event-start event))))
154 (run-hook-with-args 'move-frame-functions frame)))
156 ;;;; Arrangement of frames at startup
158 ;; 1) Load the window system startup file from the lisp library and read the
159 ;; high-priority arguments (-q and the like). The window system startup
160 ;; file should create any frames specified in the window system defaults.
162 ;; 2) If no frames have been opened, we open an initial text frame.
164 ;; 3) Once the init file is done, we apply any newly set parameters
165 ;; in initial-frame-alist to the frame.
167 ;; If we create the initial frame, this is it.
168 (defvar frame-initial-frame nil)
170 ;; Record the parameters used in frame-initialize to make the initial frame.
171 (defvar frame-initial-frame-alist)
173 (defvar frame-initial-geometry-arguments nil)
175 ;; startup.el calls this function before loading the user's init
176 ;; file - if there is no frame with a minibuffer open now, create
177 ;; one to display messages while loading the init file.
178 (defun frame-initialize ()
179 "Create an initial frame if necessary."
180 ;; Are we actually running under a window system at all?
181 (if (and initial-window-system
182 (not noninteractive)
183 (not (eq initial-window-system 'pc)))
184 (progn
185 ;; If there is no frame with a minibuffer besides the terminal
186 ;; frame, then we need to create the opening frame. Make sure
187 ;; it has a minibuffer, but let initial-frame-alist omit the
188 ;; minibuffer spec.
189 (or (delq terminal-frame (minibuffer-frame-list))
190 (progn
191 (setq frame-initial-frame-alist
192 (append initial-frame-alist default-frame-alist nil))
193 (setq frame-initial-frame-alist
194 (cons (cons 'window-system initial-window-system)
195 frame-initial-frame-alist))
196 (setq default-minibuffer-frame
197 (setq frame-initial-frame
198 (make-frame frame-initial-frame-alist)))
199 ;; Delete any specifications for window geometry parameters
200 ;; so that we won't reapply them in frame-notice-user-settings.
201 ;; It would be wrong to reapply them then,
202 ;; because that would override explicit user resizing.
203 (setq initial-frame-alist
204 (frame-remove-geometry-params initial-frame-alist))))
205 ;; Copy the environment of the Emacs process into the new frame.
206 (set-frame-parameter frame-initial-frame 'environment
207 (frame-parameter terminal-frame 'environment))
208 ;; At this point, we know that we have a frame open, so we
209 ;; can delete the terminal frame.
210 (delete-frame terminal-frame)
211 (setq terminal-frame nil))))
213 (defvar frame-notice-user-settings t
214 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
216 (declare-function tool-bar-mode "tool-bar" (&optional arg))
217 (declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise))
219 (defalias 'tool-bar-lines-needed 'tool-bar-height)
221 ;; startup.el calls this function after loading the user's init
222 ;; file. Now default-frame-alist and initial-frame-alist contain
223 ;; information to which we must react; do what needs to be done.
224 (defun frame-notice-user-settings ()
225 "Act on user's init file settings of frame parameters.
226 React to settings of `initial-frame-alist',
227 `window-system-default-frame-alist' and `default-frame-alist'
228 there (in decreasing order of priority)."
229 ;; Creating and deleting frames may shift the selected frame around,
230 ;; and thus the current buffer. Protect against that. We don't
231 ;; want to use save-excursion here, because that may also try to set
232 ;; the buffer of the selected window, which fails when the selected
233 ;; window is the minibuffer.
234 (let ((old-buffer (current-buffer))
235 (window-system-frame-alist
236 (cdr (assq initial-window-system
237 window-system-default-frame-alist))))
239 (when (and frame-notice-user-settings
240 (null frame-initial-frame))
241 ;; This case happens when we don't have a window system, and
242 ;; also for MS-DOS frames.
243 (let ((parms (frame-parameters)))
244 ;; Don't change the frame names.
245 (setq parms (delq (assq 'name parms) parms))
246 ;; Can't modify the minibuffer parameter, so don't try.
247 (setq parms (delq (assq 'minibuffer parms) parms))
248 (modify-frame-parameters
250 (if initial-window-system
251 parms
252 ;; initial-frame-alist and default-frame-alist were already
253 ;; applied in pc-win.el.
254 (append initial-frame-alist window-system-frame-alist
255 default-frame-alist parms nil)))
256 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
257 (let ((newparms (frame-parameters))
258 (frame (selected-frame)))
259 (tty-handle-reverse-video frame newparms)
260 ;; tty-handle-reverse-video might change the frame's
261 ;; color parameters, and we need to use the updated
262 ;; value below.
263 (setq newparms (frame-parameters))
264 ;; If we changed the background color, we need to update
265 ;; the background-mode parameter, and maybe some faces,
266 ;; too.
267 (when (assq 'background-color newparms)
268 (unless (or (assq 'background-mode initial-frame-alist)
269 (assq 'background-mode default-frame-alist))
270 (frame-set-background-mode frame))
271 (face-set-after-frame-default frame newparms))))))
273 ;; If the initial frame is still around, apply initial-frame-alist
274 ;; and default-frame-alist to it.
275 (when (frame-live-p frame-initial-frame)
276 ;; When tool-bar has been switched off, correct the frame size
277 ;; by the lines added in x-create-frame for the tool-bar and
278 ;; switch `tool-bar-mode' off.
279 (when (display-graphic-p)
280 (let* ((init-lines
281 (assq 'tool-bar-lines initial-frame-alist))
282 (other-lines
283 (or (assq 'tool-bar-lines window-system-frame-alist)
284 (assq 'tool-bar-lines default-frame-alist)))
285 (lines (or init-lines other-lines))
286 (height (tool-bar-height frame-initial-frame t)))
287 ;; Adjust frame top if either zero (nil) tool bar lines have
288 ;; been requested in the most relevant of the frame's alists
289 ;; or tool bar mode has been explicitly turned off in the
290 ;; user's init file.
291 (when (and (> height 0)
292 (or (and lines
293 (or (null (cdr lines))
294 (eq 0 (cdr lines))))
295 (not tool-bar-mode)))
296 (let* ((initial-top
297 (cdr (assq 'top frame-initial-geometry-arguments)))
298 (top (frame-parameter frame-initial-frame 'top)))
299 (when (and (consp initial-top) (eq '- (car initial-top)))
300 (let ((adjusted-top
301 (cond
302 ((and (consp top) (eq '+ (car top)))
303 (list '+ (+ (cadr top) height)))
304 ((and (consp top) (eq '- (car top)))
305 (list '- (- (cadr top) height)))
306 (t (+ top height)))))
307 (modify-frame-parameters
308 frame-initial-frame `((top . ,adjusted-top))))))
309 ;; Reset `tool-bar-mode' when zero tool bar lines have been
310 ;; requested for the window-system or default frame alists.
311 (when (and tool-bar-mode
312 (and other-lines
313 (or (null (cdr other-lines))
314 (eq 0 (cdr other-lines)))))
315 (tool-bar-mode -1)))))
317 ;; The initial frame we create above always has a minibuffer.
318 ;; If the user wants to remove it, or make it a minibuffer-only
319 ;; frame, then we'll have to delete the current frame and make a
320 ;; new one; you can't remove or add a root window to/from an
321 ;; existing frame.
323 ;; NOTE: default-frame-alist was nil when we created the
324 ;; existing frame. We need to explicitly include
325 ;; default-frame-alist in the parameters of the screen we
326 ;; create here, so that its new value, gleaned from the user's
327 ;; init file, will be applied to the existing screen.
328 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
329 (assq 'minibuffer window-system-frame-alist)
330 (assq 'minibuffer default-frame-alist)
331 '(minibuffer . t)))
333 ;; Create the new frame.
334 (let (parms new)
335 ;; MS-Windows needs this to avoid inflooping below.
336 (if (eq system-type 'windows-nt)
337 (sit-for 0 t))
338 ;; If the frame isn't visible yet, wait till it is.
339 ;; If the user has to position the window,
340 ;; Emacs doesn't know its real position until
341 ;; the frame is seen to be visible.
342 (while (not (cdr (assq 'visibility
343 (frame-parameters frame-initial-frame))))
344 (sleep-for 1))
345 (setq parms (frame-parameters frame-initial-frame))
347 ;; Get rid of `name' unless it was specified explicitly before.
348 (or (assq 'name frame-initial-frame-alist)
349 (setq parms (delq (assq 'name parms) parms)))
350 ;; An explicit parent-id is a request to XEmbed the frame.
351 (or (assq 'parent-id frame-initial-frame-alist)
352 (setq parms (delq (assq 'parent-id parms) parms)))
354 (setq parms (append initial-frame-alist
355 window-system-frame-alist
356 default-frame-alist
357 parms
358 nil))
360 ;; Get rid of `reverse', because that was handled
361 ;; when we first made the frame.
362 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
364 (if (assq 'height frame-initial-geometry-arguments)
365 (setq parms (assq-delete-all 'height parms)))
366 (if (assq 'width frame-initial-geometry-arguments)
367 (setq parms (assq-delete-all 'width parms)))
368 (if (assq 'left frame-initial-geometry-arguments)
369 (setq parms (assq-delete-all 'left parms)))
370 (if (assq 'top frame-initial-geometry-arguments)
371 (setq parms (assq-delete-all 'top parms)))
372 (setq new
373 (make-frame
374 ;; Use the geometry args that created the existing
375 ;; frame, rather than the parms we get for it.
376 (append frame-initial-geometry-arguments
377 '((user-size . t) (user-position . t))
378 parms)))
379 ;; The initial frame, which we are about to delete, may be
380 ;; the only frame with a minibuffer. If it is, create a
381 ;; new one.
382 (or (delq frame-initial-frame (minibuffer-frame-list))
383 (make-initial-minibuffer-frame nil))
385 ;; If the initial frame is serving as a surrogate
386 ;; minibuffer frame for any frames, we need to wean them
387 ;; onto a new frame. The default-minibuffer-frame
388 ;; variable must be handled similarly.
389 (let ((users-of-initial
390 (filtered-frame-list
391 (lambda (frame)
392 (and (not (eq frame frame-initial-frame))
393 (eq (window-frame
394 (minibuffer-window frame))
395 frame-initial-frame))))))
396 (if (or users-of-initial
397 (eq default-minibuffer-frame frame-initial-frame))
399 ;; Choose an appropriate frame. Prefer frames which
400 ;; are only minibuffers.
401 (let* ((new-surrogate
402 (car
403 (or (filtered-frame-list
404 (lambda (frame)
405 (eq (cdr (assq 'minibuffer
406 (frame-parameters frame)))
407 'only)))
408 (minibuffer-frame-list))))
409 (new-minibuffer (minibuffer-window new-surrogate)))
411 (if (eq default-minibuffer-frame frame-initial-frame)
412 (setq default-minibuffer-frame new-surrogate))
414 ;; Wean the frames using frame-initial-frame as
415 ;; their minibuffer frame.
416 (dolist (frame users-of-initial)
417 (modify-frame-parameters
418 frame (list (cons 'minibuffer new-minibuffer)))))))
420 ;; Redirect events enqueued at this frame to the new frame.
421 ;; Is this a good idea?
422 (redirect-frame-focus frame-initial-frame new)
424 ;; Finally, get rid of the old frame.
425 (delete-frame frame-initial-frame t))
427 ;; Otherwise, we don't need all that rigmarole; just apply
428 ;; the new parameters.
429 (let (newparms allparms tail)
430 (setq allparms (append initial-frame-alist
431 window-system-frame-alist
432 default-frame-alist nil))
433 (if (assq 'height frame-initial-geometry-arguments)
434 (setq allparms (assq-delete-all 'height allparms)))
435 (if (assq 'width frame-initial-geometry-arguments)
436 (setq allparms (assq-delete-all 'width allparms)))
437 (if (assq 'left frame-initial-geometry-arguments)
438 (setq allparms (assq-delete-all 'left allparms)))
439 (if (assq 'top frame-initial-geometry-arguments)
440 (setq allparms (assq-delete-all 'top allparms)))
441 (setq tail allparms)
442 ;; Find just the parms that have changed since we first
443 ;; made this frame. Those are the ones actually set by
444 ;; the init file. For those parms whose values we already knew
445 ;; (such as those spec'd by command line options)
446 ;; it is undesirable to specify the parm again
447 ;; once the user has seen the frame and been able to alter it
448 ;; manually.
449 (let (newval oldval)
450 (dolist (entry tail)
451 (setq oldval (assq (car entry) frame-initial-frame-alist))
452 (setq newval (cdr (assq (car entry) allparms)))
453 (or (and oldval (eq (cdr oldval) newval))
454 (setq newparms
455 (cons (cons (car entry) newval) newparms)))))
456 (setq newparms (nreverse newparms))
458 (let ((new-bg (assq 'background-color newparms)))
459 ;; If the `background-color' parameter is changed, apply
460 ;; it first, then make sure that the `background-mode'
461 ;; parameter and other faces are updated, before applying
462 ;; the other parameters.
463 (when new-bg
464 (modify-frame-parameters frame-initial-frame
465 (list new-bg))
466 (unless (assq 'background-mode newparms)
467 (frame-set-background-mode frame-initial-frame))
468 (face-set-after-frame-default frame-initial-frame)
469 (setq newparms (delq new-bg newparms)))
471 (when (numberp (car frame-size-history))
472 (setq frame-size-history
473 (cons (1- (car frame-size-history))
474 (cons
475 (list frame-initial-frame
476 "FRAME-NOTICE-USER"
477 nil newparms)
478 (cdr frame-size-history)))))
480 (modify-frame-parameters frame-initial-frame newparms)))))
482 ;; Restore the original buffer.
483 (set-buffer old-buffer)
485 ;; Make sure the initial frame can be GC'd if it is ever deleted.
486 ;; Make sure frame-notice-user-settings does nothing if called twice.
487 (setq frame-notice-user-settings nil)
488 (setq frame-initial-frame nil)))
490 (defun make-initial-minibuffer-frame (display)
491 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
492 (if display
493 (make-frame-on-display display parms)
494 (make-frame parms))))
496 ;;;; Creation of additional frames, and other frame miscellanea
498 (defun modify-all-frames-parameters (alist)
499 "Modify all current and future frames' parameters according to ALIST.
500 This changes `default-frame-alist' and possibly `initial-frame-alist'.
501 Furthermore, this function removes all parameters in ALIST from
502 `window-system-default-frame-alist'.
503 See help of `modify-frame-parameters' for more information."
504 (dolist (frame (frame-list))
505 (modify-frame-parameters frame alist))
507 (dolist (pair alist) ;; conses to add/replace
508 ;; initial-frame-alist needs setting only when
509 ;; frame-notice-user-settings is true.
510 (and frame-notice-user-settings
511 (setq initial-frame-alist
512 (assq-delete-all (car pair) initial-frame-alist)))
513 (setq default-frame-alist
514 (assq-delete-all (car pair) default-frame-alist))
515 ;; Remove any similar settings from the window-system specific
516 ;; parameters---they would override default-frame-alist.
517 (dolist (w window-system-default-frame-alist)
518 (setcdr w (assq-delete-all (car pair) (cdr w)))))
520 (and frame-notice-user-settings
521 (setq initial-frame-alist (append initial-frame-alist alist)))
522 (setq default-frame-alist (append default-frame-alist alist)))
524 (defun get-other-frame ()
525 "Return some frame other than the current frame.
526 Create one if necessary. Note that the minibuffer frame, if separate,
527 is not considered (see `next-frame')."
528 (if (equal (next-frame) (selected-frame)) (make-frame) (next-frame)))
530 (defun next-multiframe-window ()
531 "Select the next window, regardless of which frame it is on."
532 (interactive)
533 (select-window (next-window (selected-window)
534 (> (minibuffer-depth) 0)
536 (select-frame-set-input-focus (selected-frame)))
538 (defun previous-multiframe-window ()
539 "Select the previous window, regardless of which frame it is on."
540 (interactive)
541 (select-window (previous-window (selected-window)
542 (> (minibuffer-depth) 0)
544 (select-frame-set-input-focus (selected-frame)))
546 (defun window-system-for-display (display)
547 "Return the window system for DISPLAY.
548 Return nil if we don't know how to interpret DISPLAY."
549 ;; MS-Windows doesn't know how to create a GUI frame in a -nw session.
550 (if (and (eq system-type 'windows-nt)
551 (null (window-system))
552 (not (daemonp)))
554 (cl-loop for descriptor in display-format-alist
555 for pattern = (car descriptor)
556 for system = (cdr descriptor)
557 when (string-match-p pattern display) return system)))
559 (defun make-frame-on-display (display &optional parameters)
560 "Make a frame on display DISPLAY.
561 The optional argument PARAMETERS specifies additional frame parameters."
562 (interactive "sMake frame on display: ")
563 (make-frame (cons (cons 'display display) parameters)))
565 (declare-function x-close-connection "xfns.c" (terminal))
567 (defun close-display-connection (display)
568 "Close the connection to a display, deleting all its associated frames.
569 For DISPLAY, specify either a frame or a display name (a string).
570 If DISPLAY is nil, that stands for the selected frame's display."
571 (interactive
572 (list
573 (let* ((default (frame-parameter nil 'display))
574 (display (completing-read
575 (format "Close display (default %s): " default)
576 (delete-dups
577 (mapcar (lambda (frame)
578 (frame-parameter frame 'display))
579 (frame-list)))
580 nil t nil nil
581 default)))
582 (if (zerop (length display)) default display))))
583 (let ((frames (delq nil
584 (mapcar (lambda (frame)
585 (if (equal display
586 (frame-parameter frame 'display))
587 frame))
588 (frame-list)))))
589 (if (and (consp frames)
590 (not (y-or-n-p (if (cdr frames)
591 (format "Delete %s frames? " (length frames))
592 (format "Delete %s ? " (car frames))))))
593 (error "Abort!")
594 (mapc 'delete-frame frames)
595 (x-close-connection display))))
597 (defun make-frame-command ()
598 "Make a new frame, on the same terminal as the selected frame.
599 If the terminal is a text-only terminal, this also selects the
600 new frame."
601 (interactive)
602 (if (display-graphic-p)
603 (make-frame)
604 (select-frame (make-frame))))
606 (defvar before-make-frame-hook nil
607 "Functions to run before a frame is created.")
609 (defvar after-make-frame-functions nil
610 "Functions to run after a frame is created.
611 The functions are run with one arg, the newly created frame.")
613 (defvar after-setting-font-hook nil
614 "Functions to run after a frame's font has been changed.")
616 ;; Alias, kept temporarily.
617 (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
619 (defvar frame-inherited-parameters '()
620 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
622 (defvar x-display-name)
624 (defun make-frame (&optional parameters)
625 "Return a newly created frame displaying the current buffer.
626 Optional argument PARAMETERS is an alist of frame parameters for
627 the new frame. Each element of PARAMETERS should have the
628 form (NAME . VALUE), for example:
630 (name . STRING) The frame should be named STRING.
632 (width . NUMBER) The frame should be NUMBER characters in width.
633 (height . NUMBER) The frame should be NUMBER text lines high.
635 You cannot specify either `width' or `height', you must specify
636 neither or both.
638 (minibuffer . t) The frame should have a minibuffer.
639 (minibuffer . nil) The frame should have no minibuffer.
640 (minibuffer . only) The frame should contain only a minibuffer.
641 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
643 (window-system . nil) The frame should be displayed on a terminal device.
644 (window-system . x) The frame should be displayed in an X window.
646 (display . \":0\") The frame should appear on display :0.
648 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
650 In addition, any parameter specified in `default-frame-alist',
651 but not present in PARAMETERS, is applied.
653 Before creating the frame (via `frame-creation-function-alist'),
654 this function runs the hook `before-make-frame-hook'. After
655 creating the frame, it runs the hook `after-make-frame-functions'
656 with one arg, the newly created frame.
658 If a display parameter is supplied and a window-system is not,
659 guess the window-system from the display.
661 On graphical displays, this function does not itself make the new
662 frame the selected frame. However, the window system may select
663 the new frame according to its own rules."
664 (interactive)
665 (let* ((display (cdr (assq 'display parameters)))
666 (w (cond
667 ((assq 'terminal parameters)
668 (let ((type (terminal-live-p
669 (cdr (assq 'terminal parameters)))))
670 (cond
671 ((eq t type) nil)
672 ((null type) (error "Terminal %s does not exist"
673 (cdr (assq 'terminal parameters))))
674 (t type))))
675 ((assq 'window-system parameters)
676 (cdr (assq 'window-system parameters)))
677 (display
678 (or (window-system-for-display display)
679 (error "Don't know how to interpret display %S"
680 display)))
681 (t window-system)))
682 (oldframe (selected-frame))
683 (params parameters)
684 frame)
686 (unless (get w 'window-system-initialized)
687 (let ((window-system w)) ;Hack attack!
688 (window-system-initialization display))
689 (setq x-display-name display)
690 (put w 'window-system-initialized t))
692 ;; Add parameters from `window-system-default-frame-alist'.
693 (dolist (p (cdr (assq w window-system-default-frame-alist)))
694 (unless (assq (car p) params)
695 (push p params)))
696 ;; Add parameters from `default-frame-alist'.
697 (dolist (p default-frame-alist)
698 (unless (assq (car p) params)
699 (push p params)))
700 ;; Now make the frame.
701 (run-hooks 'before-make-frame-hook)
703 ;; (setq frame-size-history '(1000))
705 (setq frame (let ((window-system w)) ;Hack attack!
706 (frame-creation-function params)))
707 (normal-erase-is-backspace-setup-frame frame)
708 ;; Inherit the original frame's parameters.
709 (dolist (param frame-inherited-parameters)
710 (unless (assq param parameters) ;Overridden by explicit parameters.
711 (let ((val (frame-parameter oldframe param)))
712 (when val (set-frame-parameter frame param val)))))
714 (when (numberp (car frame-size-history))
715 (setq frame-size-history
716 (cons (1- (car frame-size-history))
717 (cons (list frame "MAKE-FRAME")
718 (cdr frame-size-history)))))
720 ;; We can run `window-configuration-change-hook' for this frame now.
721 (frame-after-make-frame frame t)
722 (run-hook-with-args 'after-make-frame-functions frame)
723 frame))
725 (defun filtered-frame-list (predicate)
726 "Return a list of all live frames which satisfy PREDICATE."
727 (let* ((frames (frame-list))
728 (list frames))
729 (while (consp frames)
730 (unless (funcall predicate (car frames))
731 (setcar frames nil))
732 (setq frames (cdr frames)))
733 (delq nil list)))
735 (defun minibuffer-frame-list ()
736 "Return a list of all frames with their own minibuffers."
737 (filtered-frame-list
738 (lambda (frame)
739 (eq frame (window-frame (minibuffer-window frame))))))
741 ;; Used to be called `terminal-id' in termdev.el.
742 (defun get-device-terminal (device)
743 "Return the terminal corresponding to DEVICE.
744 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
745 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
746 (cond
747 ((or (null device) (framep device))
748 (frame-terminal device))
749 ((stringp device)
750 (let ((f (car (filtered-frame-list
751 (lambda (frame)
752 (or (equal (frame-parameter frame 'display) device)
753 (equal (frame-parameter frame 'tty) device)))))))
754 (or f (error "Display %s does not exist" device))
755 (frame-terminal f)))
756 ((terminal-live-p device) device)
758 (error "Invalid argument %s in `get-device-terminal'" device))))
760 (defun frames-on-display-list (&optional device)
761 "Return a list of all frames on DEVICE.
763 DEVICE should be a terminal, a frame,
764 or a name of an X display or tty (a string of the form
765 HOST:SERVER.SCREEN).
767 If DEVICE is omitted or nil, it defaults to the selected
768 frame's terminal device."
769 (let* ((terminal (get-device-terminal device))
770 (func #'(lambda (frame)
771 (eq (frame-terminal frame) terminal))))
772 (filtered-frame-list func)))
774 (defun framep-on-display (&optional terminal)
775 "Return the type of frames on TERMINAL.
776 TERMINAL may be a terminal id, a display name or a frame. If it
777 is a frame, its type is returned. If TERMINAL is omitted or nil,
778 it defaults to the selected frame's terminal device. All frames
779 on a given display are of the same type."
780 (or (terminal-live-p terminal)
781 (framep terminal)
782 (framep (car (frames-on-display-list terminal)))))
784 (defun frame-remove-geometry-params (param-list)
785 "Return the parameter list PARAM-LIST, but with geometry specs removed.
786 This deletes all bindings in PARAM-LIST for `top', `left', `width',
787 `height', `user-size' and `user-position' parameters.
788 Emacs uses this to avoid overriding explicit moves and resizings from
789 the user during startup."
790 (setq param-list (cons nil param-list))
791 (let ((tail param-list))
792 (while (consp (cdr tail))
793 (if (and (consp (car (cdr tail)))
794 (memq (car (car (cdr tail)))
795 '(height width top left user-position user-size)))
796 (progn
797 (setq frame-initial-geometry-arguments
798 (cons (car (cdr tail)) frame-initial-geometry-arguments))
799 (setcdr tail (cdr (cdr tail))))
800 (setq tail (cdr tail)))))
801 (setq frame-initial-geometry-arguments
802 (nreverse frame-initial-geometry-arguments))
803 (cdr param-list))
805 (declare-function x-focus-frame "frame.c" (frame))
807 (defun select-frame-set-input-focus (frame &optional norecord)
808 "Select FRAME, raise it, and set input focus, if possible.
809 If `mouse-autoselect-window' is non-nil, also move mouse pointer
810 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
811 is non-nil, move mouse cursor to FRAME.
813 Optional argument NORECORD means to neither change the order of
814 recently selected windows nor the buffer list."
815 (select-frame frame norecord)
816 (raise-frame frame)
817 ;; Ensure, if possible, that FRAME gets input focus.
818 (when (memq (window-system frame) '(x w32 ns))
819 (x-focus-frame frame))
820 ;; Move mouse cursor if necessary.
821 (cond
822 (mouse-autoselect-window
823 (let ((edges (window-inside-edges (frame-selected-window frame))))
824 ;; Move mouse cursor into FRAME's selected window to avoid that
825 ;; Emacs mouse-autoselects another window.
826 (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
827 (focus-follows-mouse
828 ;; Move mouse cursor into FRAME to avoid that another frame gets
829 ;; selected by the window manager.
830 (set-mouse-position frame (1- (frame-width frame)) 0))))
832 (defun other-frame (arg)
833 "Select the ARGth different visible frame on current display, and raise it.
834 All frames are arranged in a cyclic order.
835 This command selects the frame ARG steps away in that order.
836 A negative ARG moves in the opposite order.
838 To make this command work properly, you must tell Emacs how the
839 system (or the window manager) generally handles focus-switching
840 between windows. If moving the mouse onto a window selects
841 it (gives it focus), set `focus-follows-mouse' to t. Otherwise,
842 that variable should be nil."
843 (interactive "p")
844 (let ((sframe (selected-frame))
845 (frame (selected-frame)))
846 (while (> arg 0)
847 (setq frame (next-frame frame))
848 (while (and (not (eq frame sframe))
849 (not (eq (frame-visible-p frame) t)))
850 (setq frame (next-frame frame)))
851 (setq arg (1- arg)))
852 (while (< arg 0)
853 (setq frame (previous-frame frame))
854 (while (and (not (eq frame sframe))
855 (not (eq (frame-visible-p frame) t)))
856 (setq frame (previous-frame frame)))
857 (setq arg (1+ arg)))
858 (select-frame-set-input-focus frame)))
860 (defun iconify-or-deiconify-frame ()
861 "Iconify the selected frame, or deiconify if it's currently an icon."
862 (interactive)
863 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
864 (iconify-frame)
865 (make-frame-visible)))
867 (defun suspend-frame ()
868 "Do whatever is right to suspend the current frame.
869 Calls `suspend-emacs' if invoked from the controlling tty device,
870 `suspend-tty' from a secondary tty device, and
871 `iconify-or-deiconify-frame' from an X frame."
872 (interactive)
873 (let ((type (framep (selected-frame))))
874 (cond
875 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
876 ((eq type t)
877 (if (controlling-tty-p)
878 (suspend-emacs)
879 (suspend-tty)))
880 (t (suspend-emacs)))))
882 (defun make-frame-names-alist ()
883 ;; Only consider the frames on the same display.
884 (let* ((current-frame (selected-frame))
885 (falist
886 (cons
887 (cons (frame-parameter current-frame 'name) current-frame) nil))
888 (frame (next-frame nil 0)))
889 (while (not (eq frame current-frame))
890 (progn
891 (push (cons (frame-parameter frame 'name) frame) falist)
892 (setq frame (next-frame frame 0))))
893 falist))
895 (defvar frame-name-history nil)
896 (defun select-frame-by-name (name)
897 "Select the frame on the current terminal whose name is NAME and raise it.
898 If there is no frame by that name, signal an error."
899 (interactive
900 (let* ((frame-names-alist (make-frame-names-alist))
901 (default (car (car frame-names-alist)))
902 (input (completing-read
903 (format "Select Frame (default %s): " default)
904 frame-names-alist nil t nil 'frame-name-history)))
905 (if (= (length input) 0)
906 (list default)
907 (list input))))
908 (let* ((frame-names-alist (make-frame-names-alist))
909 (frame (cdr (assoc name frame-names-alist))))
910 (if frame
911 (select-frame-set-input-focus frame)
912 (error "There is no frame named `%s'" name))))
915 ;;;; Background mode.
917 (defcustom frame-background-mode nil
918 "The brightness of the background.
919 Set this to the symbol `dark' if your background color is dark,
920 `light' if your background is light, or nil (automatic by default)
921 if you want Emacs to examine the brightness for you.
923 If you change this without using customize, you should use
924 `frame-set-background-mode' to update existing frames;
925 e.g. (mapc \\='frame-set-background-mode (frame-list))."
926 :group 'faces
927 :set #'(lambda (var value)
928 (set-default var value)
929 (mapc 'frame-set-background-mode (frame-list)))
930 :initialize 'custom-initialize-changed
931 :type '(choice (const dark)
932 (const light)
933 (const :tag "automatic" nil)))
935 (declare-function x-get-resource "frame.c"
936 (attribute class &optional component subclass))
938 ;; Only used if window-system is not null.
939 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
941 (defvar inhibit-frame-set-background-mode nil)
943 (defun frame-set-background-mode (frame &optional keep-face-specs)
944 "Set up display-dependent faces on FRAME.
945 Display-dependent faces are those which have different definitions
946 according to the `background-mode' and `display-type' frame parameters.
948 If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
949 face specs for the new background mode."
950 (unless inhibit-frame-set-background-mode
951 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
952 (bg-color (frame-parameter frame 'background-color))
953 (tty-type (tty-type frame))
954 (default-bg-mode
955 (if (or (window-system frame)
956 (and tty-type
957 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
958 tty-type)))
959 'light
960 'dark))
961 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
962 (bg-mode
963 (cond (frame-default-bg-mode)
964 ((equal bg-color "unspecified-fg") ; inverted colors
965 non-default-bg-mode)
966 ((not (color-values bg-color frame))
967 default-bg-mode)
968 ((>= (apply '+ (color-values bg-color frame))
969 ;; Just looking at the screen, colors whose
970 ;; values add up to .6 of the white total
971 ;; still look dark to me.
972 (* (apply '+ (color-values "white" frame)) .6))
973 'light)
974 (t 'dark)))
975 (display-type
976 (cond ((null (window-system frame))
977 (if (tty-display-color-p frame) 'color 'mono))
978 ((display-color-p frame)
979 'color)
980 ((x-display-grayscale-p frame)
981 'grayscale)
982 (t 'mono)))
983 (old-bg-mode
984 (frame-parameter frame 'background-mode))
985 (old-display-type
986 (frame-parameter frame 'display-type)))
988 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
989 (let ((locally-modified-faces nil)
990 ;; Prevent face-spec-recalc from calling this function
991 ;; again, resulting in a loop (bug#911).
992 (inhibit-frame-set-background-mode t)
993 (params (list (cons 'background-mode bg-mode)
994 (cons 'display-type display-type))))
995 (if keep-face-specs
996 (modify-frame-parameters frame params)
997 ;; If we are recomputing face specs, first collect a list
998 ;; of faces that don't match their face-specs. These are
999 ;; the faces modified on FRAME, and we avoid changing them
1000 ;; below. Use a negative list to avoid consing (we assume
1001 ;; most faces are unmodified).
1002 (dolist (face (face-list))
1003 (and (not (get face 'face-override-spec))
1004 (not (face-spec-match-p face
1005 (face-user-default-spec face)
1006 (selected-frame)))
1007 (push face locally-modified-faces)))
1008 ;; Now change to the new frame parameters
1009 (modify-frame-parameters frame params)
1010 ;; For all unmodified named faces, choose face specs
1011 ;; matching the new frame parameters.
1012 (dolist (face (face-list))
1013 (unless (memq face locally-modified-faces)
1014 (face-spec-recalc face frame)))))))))
1016 (defun frame-terminal-default-bg-mode (frame)
1017 "Return the default background mode of FRAME.
1018 This checks the `frame-background-mode' variable, the X resource
1019 named \"backgroundMode\" (if FRAME is an X frame), and finally
1020 the `background-mode' terminal parameter."
1021 (or frame-background-mode
1022 (let ((bg-resource
1023 (and (window-system frame)
1024 (x-get-resource "backgroundMode" "BackgroundMode"))))
1025 (if bg-resource
1026 (intern (downcase bg-resource))))
1027 (terminal-parameter frame 'background-mode)))
1030 ;;;; Frame configurations
1032 (defun current-frame-configuration ()
1033 "Return a list describing the positions and states of all frames.
1034 Its car is `frame-configuration'.
1035 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
1036 where
1037 FRAME is a frame object,
1038 ALIST is an association list specifying some of FRAME's parameters, and
1039 WINDOW-CONFIG is a window configuration object for FRAME."
1040 (cons 'frame-configuration
1041 (mapcar (lambda (frame)
1042 (list frame
1043 (frame-parameters frame)
1044 (current-window-configuration frame)))
1045 (frame-list))))
1047 (defun set-frame-configuration (configuration &optional nodelete)
1048 "Restore the frames to the state described by CONFIGURATION.
1049 Each frame listed in CONFIGURATION has its position, size, window
1050 configuration, and other parameters set as specified in CONFIGURATION.
1051 However, this function does not restore deleted frames.
1053 Ordinarily, this function deletes all existing frames not
1054 listed in CONFIGURATION. But if optional second argument NODELETE
1055 is given and non-nil, the unwanted frames are iconified instead."
1056 (or (frame-configuration-p configuration)
1057 (signal 'wrong-type-argument
1058 (list 'frame-configuration-p configuration)))
1059 (let ((config-alist (cdr configuration))
1060 frames-to-delete)
1061 (dolist (frame (frame-list))
1062 (let ((parameters (assq frame config-alist)))
1063 (if parameters
1064 (progn
1065 (modify-frame-parameters
1066 frame
1067 ;; Since we can't set a frame's minibuffer status,
1068 ;; we might as well omit the parameter altogether.
1069 (let* ((parms (nth 1 parameters))
1070 (mini (assq 'minibuffer parms))
1071 (name (assq 'name parms))
1072 (explicit-name (cdr (assq 'explicit-name parms))))
1073 (when mini (setq parms (delq mini parms)))
1074 ;; Leave name in iff it was set explicitly.
1075 ;; This should fix the behavior reported in
1076 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
1077 (when (and name (not explicit-name))
1078 (setq parms (delq name parms)))
1079 parms))
1080 (set-window-configuration (nth 2 parameters)))
1081 (setq frames-to-delete (cons frame frames-to-delete)))))
1082 (mapc (if nodelete
1083 ;; Note: making frames invisible here was tried
1084 ;; but led to some strange behavior--each time the frame
1085 ;; was made visible again, the window manager asked afresh
1086 ;; for where to put it.
1087 'iconify-frame
1088 'delete-frame)
1089 frames-to-delete)))
1091 ;;;; Convenience functions for accessing and interactively changing
1092 ;;;; frame parameters.
1094 (defun frame-height (&optional frame)
1095 "Return number of lines available for display on FRAME.
1096 If FRAME is omitted, describe the currently selected frame.
1097 Exactly what is included in the return value depends on the
1098 window-system and toolkit in use - see `frame-pixel-height' for
1099 more details. The lines are in units of the default font height.
1101 The result is roughly related to the frame pixel height via
1102 height in pixels = height in lines * `frame-char-height'.
1103 However, this is only approximate, and is complicated e.g. by the
1104 fact that individual window lines and menu bar lines can have
1105 differing font heights."
1106 (cdr (assq 'height (frame-parameters frame))))
1108 (defun frame-width (&optional frame)
1109 "Return number of columns available for display on FRAME.
1110 If FRAME is omitted, describe the currently selected frame."
1111 (cdr (assq 'width (frame-parameters frame))))
1113 (declare-function x-list-fonts "xfaces.c"
1114 (pattern &optional face frame maximum width))
1116 (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
1118 (defun set-frame-font (font &optional keep-size frames)
1119 "Set the default font to FONT.
1120 When called interactively, prompt for the name of a font, and use
1121 that font on the selected frame. When called from Lisp, FONT
1122 should be a font name (a string), a font object, font entity, or
1123 font spec.
1125 If KEEP-SIZE is nil, keep the number of frame lines and columns
1126 fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
1127 to keep the current frame size fixed (in pixels) by adjusting the
1128 number of lines and columns.
1130 If FRAMES is nil, apply the font to the selected frame only.
1131 If FRAMES is non-nil, it should be a list of frames to act upon,
1132 or t meaning all existing graphical frames.
1133 Also, if FRAMES is non-nil, alter the user's Customization settings
1134 as though the font-related attributes of the `default' face had been
1135 \"set in this session\", so that the font is applied to future frames."
1136 (interactive
1137 (let* ((completion-ignore-case t)
1138 (font (completing-read "Font name: "
1139 ;; x-list-fonts will fail with an error
1140 ;; if this frame doesn't support fonts.
1141 (x-list-fonts "*" nil (selected-frame))
1142 nil nil nil nil
1143 (frame-parameter nil 'font))))
1144 (list font current-prefix-arg nil)))
1145 (when (or (stringp font) (fontp font))
1146 (let* ((this-frame (selected-frame))
1147 ;; FRAMES nil means affect the selected frame.
1148 (frame-list (cond ((null frames)
1149 (list this-frame))
1150 ((eq frames t)
1151 (frame-list))
1152 (t frames)))
1153 height width)
1154 (dolist (f frame-list)
1155 (when (display-multi-font-p f)
1156 (if keep-size
1157 (setq height (* (frame-parameter f 'height)
1158 (frame-char-height f))
1159 width (* (frame-parameter f 'width)
1160 (frame-char-width f))))
1161 ;; When set-face-attribute is called for :font, Emacs
1162 ;; guesses the best font according to other face attributes
1163 ;; (:width, :weight, etc.) so reset them too (Bug#2476).
1164 (set-face-attribute 'default f
1165 :width 'normal :weight 'normal
1166 :slant 'normal :font font)
1167 (if keep-size
1168 (modify-frame-parameters
1170 (list (cons 'height (round height (frame-char-height f)))
1171 (cons 'width (round width (frame-char-width f))))))))
1172 (when frames
1173 ;; Alter the user's Custom setting of the `default' face, but
1174 ;; only for font-related attributes.
1175 (let ((specs (cadr (assq 'user (get 'default 'theme-face))))
1176 (attrs '(:family :foundry :slant :weight :height :width))
1177 (new-specs nil))
1178 (if (null specs) (setq specs '((t nil))))
1179 (dolist (spec specs)
1180 ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
1181 (let ((display (nth 0 spec))
1182 (plist (copy-tree (nth 1 spec))))
1183 ;; Alter only DISPLAY conditions matching this frame.
1184 (when (or (memq display '(t default))
1185 (face-spec-set-match-display display this-frame))
1186 (dolist (attr attrs)
1187 (setq plist (plist-put plist attr
1188 (face-attribute 'default attr)))))
1189 (push (list display plist) new-specs)))
1190 (setq new-specs (nreverse new-specs))
1191 (put 'default 'customized-face new-specs)
1192 (custom-push-theme 'theme-face 'default 'user 'set new-specs)
1193 (put 'default 'face-modified nil))))
1194 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))
1196 (defun set-frame-parameter (frame parameter value)
1197 "Set frame parameter PARAMETER to VALUE on FRAME.
1198 If FRAME is nil, it defaults to the selected frame.
1199 See `modify-frame-parameters'."
1200 (modify-frame-parameters frame (list (cons parameter value))))
1202 (defun set-background-color (color-name)
1203 "Set the background color of the selected frame to COLOR-NAME.
1204 When called interactively, prompt for the name of the color to use.
1205 To get the frame's current background color, use `frame-parameters'."
1206 (interactive (list (read-color "Background color: ")))
1207 (modify-frame-parameters (selected-frame)
1208 (list (cons 'background-color color-name)))
1209 (or window-system
1210 (face-set-after-frame-default (selected-frame)
1211 (list
1212 (cons 'background-color color-name)
1213 ;; Pass the foreground-color as
1214 ;; well, if defined, to avoid
1215 ;; losing it when faces are reset
1216 ;; to their defaults.
1217 (assq 'foreground-color
1218 (frame-parameters))))))
1220 (defun set-foreground-color (color-name)
1221 "Set the foreground color of the selected frame to COLOR-NAME.
1222 When called interactively, prompt for the name of the color to use.
1223 To get the frame's current foreground color, use `frame-parameters'."
1224 (interactive (list (read-color "Foreground color: ")))
1225 (modify-frame-parameters (selected-frame)
1226 (list (cons 'foreground-color color-name)))
1227 (or window-system
1228 (face-set-after-frame-default (selected-frame)
1229 (list
1230 (cons 'foreground-color color-name)
1231 ;; Pass the background-color as
1232 ;; well, if defined, to avoid
1233 ;; losing it when faces are reset
1234 ;; to their defaults.
1235 (assq 'background-color
1236 (frame-parameters))))))
1238 (defun set-cursor-color (color-name)
1239 "Set the text cursor color of the selected frame to COLOR-NAME.
1240 When called interactively, prompt for the name of the color to use.
1241 This works by setting the `cursor-color' frame parameter on the
1242 selected frame.
1244 You can also set the text cursor color, for all frames, by
1245 customizing the `cursor' face."
1246 (interactive (list (read-color "Cursor color: ")))
1247 (modify-frame-parameters (selected-frame)
1248 (list (cons 'cursor-color color-name))))
1250 (defun set-mouse-color (color-name)
1251 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1252 When called interactively, prompt for the name of the color to use.
1253 To get the frame's current mouse color, use `frame-parameters'."
1254 (interactive (list (read-color "Mouse color: ")))
1255 (modify-frame-parameters (selected-frame)
1256 (list (cons 'mouse-color
1257 (or color-name
1258 (cdr (assq 'mouse-color
1259 (frame-parameters))))))))
1261 (defun set-border-color (color-name)
1262 "Set the color of the border of the selected frame to COLOR-NAME.
1263 When called interactively, prompt for the name of the color to use.
1264 To get the frame's current border color, use `frame-parameters'."
1265 (interactive (list (read-color "Border color: ")))
1266 (modify-frame-parameters (selected-frame)
1267 (list (cons 'border-color color-name))))
1269 (define-minor-mode auto-raise-mode
1270 "Toggle whether or not selected frames should auto-raise.
1271 With a prefix argument ARG, enable Auto Raise mode if ARG is
1272 positive, and disable it otherwise. If called from Lisp, enable
1273 the mode if ARG is omitted or nil.
1275 Auto Raise mode does nothing under most window managers, which
1276 switch focus on mouse clicks. It only has an effect if your
1277 window manager switches focus on mouse movement (in which case
1278 you should also change `focus-follows-mouse' to t). Then,
1279 enabling Auto Raise mode causes any graphical Emacs frame which
1280 acquires focus to be automatically raised.
1282 Note that this minor mode controls Emacs's own auto-raise
1283 feature. Window managers that switch focus on mouse movement
1284 often have their own auto-raise feature."
1285 :variable (frame-parameter nil 'auto-raise)
1286 (if (frame-parameter nil 'auto-raise)
1287 (raise-frame)))
1289 (define-minor-mode auto-lower-mode
1290 "Toggle whether or not the selected frame should auto-lower.
1291 With a prefix argument ARG, enable Auto Lower mode if ARG is
1292 positive, and disable it otherwise. If called from Lisp, enable
1293 the mode if ARG is omitted or nil.
1295 Auto Lower mode does nothing under most window managers, which
1296 switch focus on mouse clicks. It only has an effect if your
1297 window manager switches focus on mouse movement (in which case
1298 you should also change `focus-follows-mouse' to t). Then,
1299 enabling Auto Lower Mode causes any graphical Emacs frame which
1300 loses focus to be automatically lowered.
1302 Note that this minor mode controls Emacs's own auto-lower
1303 feature. Window managers that switch focus on mouse movement
1304 often have their own features for raising or lowering frames."
1305 :variable (frame-parameter nil 'auto-lower))
1307 (defun set-frame-name (name)
1308 "Set the name of the selected frame to NAME.
1309 When called interactively, prompt for the name of the frame.
1310 On text terminals, the frame name is displayed on the mode line.
1311 On graphical displays, it is displayed on the frame's title bar."
1312 (interactive "sFrame name: ")
1313 (modify-frame-parameters (selected-frame)
1314 (list (cons 'name name))))
1316 (defun frame-current-scroll-bars (&optional frame)
1317 "Return the current scroll-bar types for frame FRAME.
1318 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies
1319 the current location of the vertical scroll-bars (`left', `right'
1320 or nil), and HORIZONTAL specifies the current location of the
1321 horizontal scroll bars (`bottom' or nil). FRAME must specify a
1322 live frame and defaults to the selected one."
1323 (let* ((frame (window-normalize-frame frame))
1324 (vertical (frame-parameter frame 'vertical-scroll-bars))
1325 (horizontal (frame-parameter frame 'horizontal-scroll-bars)))
1326 (unless (memq vertical '(left right nil))
1327 (setq vertical default-frame-scroll-bars))
1328 (cons vertical (and horizontal 'bottom))))
1330 (declare-function x-frame-geometry "xfns.c" (&optional frame))
1331 (declare-function w32-frame-geometry "w32fns.c" (&optional frame))
1332 (declare-function ns-frame-geometry "nsfns.m" (&optional frame))
1334 (defun frame-geometry (&optional frame)
1335 "Return geometric attributes of FRAME.
1336 FRAME must be a live frame and defaults to the selected one. The return
1337 value is an association list of the attributes listed below. All height
1338 and width values are in pixels.
1340 `outer-position' is a cons of the outer left and top edges of FRAME
1341 relative to the origin - the position (0, 0) - of FRAME's display.
1343 `outer-size' is a cons of the outer width and height of FRAME. The
1344 outer size includes the title bar and the external borders as well as
1345 any menu and/or tool bar of frame.
1347 `external-border-size' is a cons of the horizontal and vertical width of
1348 FRAME's external borders as supplied by the window manager.
1350 `title-bar-size' is a cons of the width and height of the title bar of
1351 FRAME as supplied by the window manager. If both of them are zero,
1352 FRAME has no title bar. If only the width is zero, Emacs was not
1353 able to retrieve the width information.
1355 `menu-bar-external', if non-nil, means the menu bar is external (never
1356 included in the inner edges of FRAME).
1358 `menu-bar-size' is a cons of the width and height of the menu bar of
1359 FRAME.
1361 `tool-bar-external', if non-nil, means the tool bar is external (never
1362 included in the inner edges of FRAME).
1364 `tool-bar-position' tells on which side the tool bar on FRAME is and can
1365 be one of `left', `top', `right' or `bottom'. If this is nil, FRAME
1366 has no tool bar.
1368 `tool-bar-size' is a cons of the width and height of the tool bar of
1369 FRAME.
1371 `internal-border-width' is the width of the internal border of
1372 FRAME."
1373 (let* ((frame (window-normalize-frame frame))
1374 (frame-type (framep-on-display frame)))
1375 (cond
1376 ((eq frame-type 'x)
1377 (x-frame-geometry frame))
1378 ((eq frame-type 'w32)
1379 (w32-frame-geometry frame))
1380 ((eq frame-type 'ns)
1381 (ns-frame-geometry frame))
1383 (list
1384 '(outer-position 0 . 0)
1385 (cons 'outer-size (cons (frame-width frame) (frame-height frame)))
1386 '(external-border-size 0 . 0)
1387 '(outer-border-width . 0)
1388 '(title-bar-size 0 . 0)
1389 '(menu-bar-external . nil)
1390 (let ((menu-bar-lines (frame-parameter frame 'menu-bar-lines)))
1391 (cons 'menu-bar-size
1392 (if menu-bar-lines
1393 (cons (frame-width frame) 1)
1394 1 0)))
1395 '(tool-bar-external . nil)
1396 '(tool-bar-position . nil)
1397 '(tool-bar-size 0 . 0)
1398 (cons 'internal-border-width
1399 (frame-parameter frame 'internal-border-width)))))))
1401 (defun frame--size-history (&optional frame)
1402 "Print history of resize operations for FRAME.
1403 Print prettified version of `frame-size-history' into a buffer
1404 called *frame-size-history*. Optional argument FRAME denotes the
1405 frame whose history will be printed. FRAME defaults to the
1406 selected frame."
1407 (let ((history (reverse frame-size-history))
1408 entry)
1409 (setq frame (window-normalize-frame frame))
1410 (with-current-buffer (get-buffer-create "*frame-size-history*")
1411 (erase-buffer)
1412 (insert (format "Frame size history of %s\n" frame))
1413 (while (listp (setq entry (pop history)))
1414 (when (eq (car entry) frame)
1415 (pop entry)
1416 (insert (format "%s" (pop entry)))
1417 (move-to-column 24 t)
1418 (while entry
1419 (insert (format " %s" (pop entry))))
1420 (insert "\n"))))))
1422 (declare-function x-frame-edges "xfns.c" (&optional frame type))
1423 (declare-function w32-frame-edges "w32fns.c" (&optional frame type))
1424 (declare-function ns-frame-edges "nsfns.m" (&optional frame type))
1426 (defun frame-edges (&optional frame type)
1427 "Return coordinates of FRAME's edges.
1428 FRAME must be a live frame and defaults to the selected one. The
1429 list returned has the form (LEFT TOP RIGHT BOTTOM) where all
1430 values are in pixels relative to the origin - the position (0, 0)
1431 - of FRAME's display. For terminal frames all values are
1432 relative to LEFT and TOP which are both zero.
1434 Optional argument TYPE specifies the type of the edges. TYPE
1435 `outer-edges' means to return the outer edges of FRAME. TYPE
1436 `native-edges' (or nil) means to return the native edges of
1437 FRAME. TYPE `inner-edges' means to return the inner edges of
1438 FRAME."
1439 (let* ((frame (window-normalize-frame frame))
1440 (frame-type (framep-on-display frame)))
1441 (cond
1442 ((eq frame-type 'x)
1443 (x-frame-edges frame type))
1444 ((eq frame-type 'w32)
1445 (w32-frame-edges frame type))
1446 ((eq frame-type 'ns)
1447 (ns-frame-edges frame type))
1449 (list 0 0 (frame-width frame) (frame-height frame))))))
1451 (declare-function w32-mouse-absolute-pixel-position "w32fns.c")
1452 (declare-function x-mouse-absolute-pixel-position "xfns.c")
1454 (defun mouse-absolute-pixel-position ()
1455 "Return absolute position of mouse cursor in pixels.
1456 The position is returned as a cons cell (X . Y) of the
1457 coordinates of the mouse cursor position in pixels relative to a
1458 position (0, 0) of the selected frame's terminal."
1459 (let ((frame-type (framep-on-display)))
1460 (cond
1461 ((eq frame-type 'x)
1462 (x-mouse-absolute-pixel-position))
1463 ((eq frame-type 'w32)
1464 (w32-mouse-absolute-pixel-position))
1466 (cons 0 0)))))
1468 (declare-function ns-set-mouse-absolute-pixel-position "nsfns.m" (x y))
1469 (declare-function w32-set-mouse-absolute-pixel-position "w32fns.c" (x y))
1470 (declare-function x-set-mouse-absolute-pixel-position "xfns.c" (x y))
1472 (defun set-mouse-absolute-pixel-position (x y)
1473 "Move mouse pointer to absolute pixel position (X, Y).
1474 The coordinates X and Y are interpreted in pixels relative to a
1475 position (0, 0) of the selected frame's terminal."
1476 (let ((frame-type (framep-on-display)))
1477 (cond
1478 ((eq frame-type 'ns)
1479 (ns-set-mouse-absolute-pixel-position x y))
1480 ((eq frame-type 'x)
1481 (x-set-mouse-absolute-pixel-position x y))
1482 ((eq frame-type 'w32)
1483 (w32-set-mouse-absolute-pixel-position x y)))))
1485 (defun frame-monitor-attributes (&optional frame)
1486 "Return the attributes of the physical monitor dominating FRAME.
1487 If FRAME is omitted or nil, describe the currently selected frame.
1489 A frame is dominated by a physical monitor when either the
1490 largest area of the frame resides in the monitor, or the monitor
1491 is the closest to the frame if the frame does not intersect any
1492 physical monitors.
1494 See `display-monitor-attributes-list' for the list of attribute
1495 keys and their meanings."
1496 (or frame (setq frame (selected-frame)))
1497 (cl-loop for attributes in (display-monitor-attributes-list frame)
1498 for frames = (cdr (assq 'frames attributes))
1499 if (memq frame frames) return attributes))
1501 (defun frame-monitor-attribute (attribute &optional frame x y)
1502 "Return the value of ATTRIBUTE on FRAME's monitor.
1503 If FRAME is omitted or nil, use currently selected frame.
1505 By default, the current monitor is the physical monitor
1506 dominating the selected frame. A frame is dominated by a
1507 physical monitor when either the largest area of the frame
1508 resides in the monitor, or the monitor is the closest to the
1509 frame if the frame does not intersect any physical monitors.
1511 If X and Y are both numbers, then ignore the value of FRAME; the
1512 monitor is determined to be the physical monitor that contains
1513 the pixel coordinate (X, Y).
1515 See `display-monitor-attributes-list' for the list of attribute
1516 keys and their meanings."
1517 (if (and (numberp x)
1518 (numberp y))
1519 (cl-loop for monitor in (display-monitor-attributes-list)
1520 for geometry = (alist-get 'geometry monitor)
1521 for min-x = (pop geometry)
1522 for min-y = (pop geometry)
1523 for max-x = (+ min-x (pop geometry))
1524 for max-y = (+ min-y (car geometry))
1525 when (and (<= min-x x)
1526 (< x max-x)
1527 (<= min-y y)
1528 (< y max-y))
1529 return (alist-get attribute monitor))
1530 (alist-get attribute (frame-monitor-attributes frame))))
1532 (defun frame-monitor-geometry (&optional frame x y)
1533 "Return the geometry of FRAME's monitor.
1534 FRAME can be a frame name, a terminal name, or a frame.
1535 If FRAME is omitted or nil, use the currently selected frame.
1537 By default, the current monitor is said to be the physical
1538 monitor dominating the selected frame. A frame is dominated by
1539 a physical monitor when either the largest area of the frame resides
1540 in the monitor, or the monitor is the closest to the frame if the
1541 frame does not intersect any physical monitors.
1543 If X and Y are both numbers, then ignore the value of FRAME; the
1544 monitor is determined to be the physical monitor that contains
1545 the pixel coordinate (X, Y).
1547 See `display-monitor-attributes-list' for information on the
1548 geometry attribute."
1549 (frame-monitor-attribute 'geometry frame x y))
1551 (defun frame-monitor-workarea (&optional frame x y)
1552 "Return the workarea of FRAME's monitor.
1553 FRAME can be a frame name, a terminal name, or a frame.
1554 If FRAME is omitted or nil, use currently selected frame.
1556 By default, the current monitor is said to be the physical
1557 monitor dominating the selected frame. A frame is dominated by
1558 a physical monitor when either the largest area of the frame resides
1559 in the monitor, or the monitor is the closest to the frame if the
1560 frame does not intersect any physical monitors.
1562 If X and Y are both numbers, then ignore the value of FRAME; the
1563 monitor is determined to be the physical monitor that contains
1564 the pixel coordinate (X, Y).
1566 See `display-monitor-attributes-list' for information on the
1567 workarea attribute."
1568 (frame-monitor-attribute 'workarea frame x y))
1570 (declare-function x-frame-list-z-order "xfns.c" (&optional display))
1571 (declare-function w32-frame-list-z-order "w32fns.c" (&optional display))
1572 (declare-function ns-frame-list-z-order "nsfns.m" (&optional display))
1574 (defun frame-list-z-order (&optional display)
1575 "Return list of Emacs' frames, in Z (stacking) order.
1576 The optional argument DISPLAY specifies which display to poll.
1577 DISPLAY should be either a frame or a display name (a string).
1578 If omitted or nil, that stands for the selected frame's display.
1580 Frames are listed from topmost (first) to bottommost (last). As
1581 a special case, if DISPLAY is non-nil and specifies a live frame,
1582 return the child frames of that frame in Z (stacking) order.
1584 Return nil if DISPLAY contains no Emacs frame."
1585 (let ((frame-type (framep-on-display display)))
1586 (cond
1587 ((eq frame-type 'x)
1588 (x-frame-list-z-order display))
1589 ((eq frame-type 'w32)
1590 (w32-frame-list-z-order display))
1591 ((eq frame-type 'ns)
1592 (ns-frame-list-z-order display)))))
1594 (declare-function x-frame-restack "xfns.c" (frame1 frame2 &optional above))
1595 (declare-function w32-frame-restack "w32fns.c" (frame1 frame2 &optional above))
1596 (declare-function ns-frame-restack "nsfns.m" (frame1 frame2 &optional above))
1598 (defun frame-restack (frame1 frame2 &optional above)
1599 "Restack FRAME1 below FRAME2.
1600 This implies that if both frames are visible and the display
1601 areas of these frames overlap, FRAME2 will (partially) obscure
1602 FRAME1. If the optional third argument ABOVE is non-nil, restack
1603 FRAME1 above FRAME2. This means that if both frames are visible
1604 and the display areas of these frames overlap, FRAME1 will
1605 \(partially) obscure FRAME2.
1607 This may be thought of as an atomic action performed in two
1608 steps: The first step removes FRAME1's window-system window from
1609 the display. The second step reinserts FRAME1's window
1610 below (above if ABOVE is true) that of FRAME2. Hence the
1611 position of FRAME2 in its display's Z (stacking) order relative
1612 to all other frames excluding FRAME1 remains unaltered.
1614 Some window managers may refuse to restack windows. "
1615 (if (and (frame-live-p frame1)
1616 (frame-live-p frame2)
1617 (equal (frame-parameter frame1 'display)
1618 (frame-parameter frame2 'display)))
1619 (let ((frame-type (framep-on-display frame1)))
1620 (cond
1621 ((eq frame-type 'x)
1622 (x-frame-restack frame1 frame2 above))
1623 ((eq frame-type 'w32)
1624 (w32-frame-restack frame1 frame2 above))
1625 ((eq frame-type 'ns)
1626 (ns-frame-restack frame1 frame2 above))))
1627 (error "Cannot restack frames")))
1629 (defun frame-size-changed-p (&optional frame)
1630 "Return non-nil when the size of FRAME has changed.
1631 More precisely, return non-nil when the inner width or height of
1632 FRAME has changed since `window-size-change-functions' was run
1633 for FRAME."
1634 (let* ((frame (window-normalize-frame frame))
1635 (root (frame-root-window frame))
1636 (mini (minibuffer-window frame))
1637 (mini-height-before-size-change 0)
1638 (mini-height 0))
1639 ;; FRAME's minibuffer window counts iff it's on FRAME and FRAME is
1640 ;; not a minibuffer-only frame.
1641 (when (and (eq (window-frame mini) frame) (not (eq mini root)))
1642 (setq mini-height-before-size-change
1643 (window-pixel-height-before-size-change mini))
1644 (setq mini-height (window-pixel-height mini)))
1645 ;; Return non-nil when either the width of the root or the sum of
1646 ;; the heights of root and minibuffer window changed.
1647 (or (/= (window-pixel-width-before-size-change root)
1648 (window-pixel-width root))
1649 (/= (+ (window-pixel-height-before-size-change root)
1650 mini-height-before-size-change)
1651 (+ (window-pixel-height root) mini-height)))))
1653 ;;;; Frame/display capabilities.
1655 (declare-function msdos-mouse-p "dosfns.c")
1657 (defun display-mouse-p (&optional display)
1658 "Return non-nil if DISPLAY has a mouse available.
1659 DISPLAY can be a display name, a frame, or nil (meaning the selected
1660 frame's display)."
1661 (let ((frame-type (framep-on-display display)))
1662 (cond
1663 ((eq frame-type 'pc)
1664 (msdos-mouse-p))
1665 ((eq frame-type 'w32)
1666 (with-no-warnings
1667 (> w32-num-mouse-buttons 0)))
1668 ((memq frame-type '(x ns))
1669 t) ;; We assume X and NeXTstep *always* have a pointing device
1671 (or (and (featurep 'xt-mouse)
1672 xterm-mouse-mode)
1673 ;; t-mouse is distributed with the GPM package. It doesn't have
1674 ;; a toggle.
1675 (featurep 't-mouse)
1676 ;; No way to check whether a w32 console has a mouse, assume
1677 ;; it always does.
1678 (boundp 'w32-use-full-screen-buffer))))))
1680 (defun display-popup-menus-p (&optional display)
1681 "Return non-nil if popup menus are supported on DISPLAY.
1682 DISPLAY can be a display name, a frame, or nil (meaning the selected
1683 frame's display).
1684 Support for popup menus requires that the mouse be available."
1685 (display-mouse-p display))
1687 (defun display-graphic-p (&optional display)
1688 "Return non-nil if DISPLAY is a graphic display.
1689 Graphical displays are those which are capable of displaying several
1690 frames and several different fonts at once. This is true for displays
1691 that use a window system such as X, and false for text-only terminals.
1692 DISPLAY can be a display name, a frame, or nil (meaning the selected
1693 frame's display)."
1694 (not (null (memq (framep-on-display display) '(x w32 ns)))))
1696 (defun display-images-p (&optional display)
1697 "Return non-nil if DISPLAY can display images.
1699 DISPLAY can be a display name, a frame, or nil (meaning the selected
1700 frame's display)."
1701 (and (display-graphic-p display)
1702 (fboundp 'image-mask-p)
1703 (fboundp 'image-size)))
1705 (defalias 'display-multi-frame-p 'display-graphic-p)
1706 (defalias 'display-multi-font-p 'display-graphic-p)
1708 (defun display-selections-p (&optional display)
1709 "Return non-nil if DISPLAY supports selections.
1710 A selection is a way to transfer text or other data between programs
1711 via special system buffers called `selection' or `clipboard'.
1712 DISPLAY can be a display name, a frame, or nil (meaning the selected
1713 frame's display)."
1714 (let ((frame-type (framep-on-display display)))
1715 (cond
1716 ((eq frame-type 'pc)
1717 ;; MS-DOS frames support selections when Emacs runs inside
1718 ;; a Windows DOS Box.
1719 (with-no-warnings
1720 (not (null dos-windows-version))))
1721 ((memq frame-type '(x w32 ns))
1724 nil))))
1726 (declare-function x-display-screens "xfns.c" (&optional terminal))
1728 (defun display-screens (&optional display)
1729 "Return the number of screens associated with DISPLAY.
1730 DISPLAY should be either a frame or a display name (a string).
1731 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1732 (let ((frame-type (framep-on-display display)))
1733 (cond
1734 ((memq frame-type '(x w32 ns))
1735 (x-display-screens display))
1737 1))))
1739 (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
1741 (defun display-pixel-height (&optional display)
1742 "Return the height of DISPLAY's screen in pixels.
1743 DISPLAY can be a display name or a frame.
1744 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1746 For character terminals, each character counts as a single pixel.
1748 For graphical terminals, note that on \"multi-monitor\" setups this
1749 refers to the pixel height for all physical monitors associated
1750 with DISPLAY. To get information for each physical monitor, use
1751 `display-monitor-attributes-list'."
1752 (let ((frame-type (framep-on-display display)))
1753 (cond
1754 ((memq frame-type '(x w32 ns))
1755 (x-display-pixel-height display))
1757 (frame-height (if (framep display) display (selected-frame)))))))
1759 (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
1761 (defun display-pixel-width (&optional display)
1762 "Return the width of DISPLAY's screen in pixels.
1763 DISPLAY can be a display name or a frame.
1764 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1766 For character terminals, each character counts as a single pixel.
1768 For graphical terminals, note that on \"multi-monitor\" setups this
1769 refers to the pixel width for all physical monitors associated
1770 with DISPLAY. To get information for each physical monitor, use
1771 `display-monitor-attributes-list'."
1772 (let ((frame-type (framep-on-display display)))
1773 (cond
1774 ((memq frame-type '(x w32 ns))
1775 (x-display-pixel-width display))
1777 (frame-width (if (framep display) display (selected-frame)))))))
1779 (defcustom display-mm-dimensions-alist nil
1780 "Alist for specifying screen dimensions in millimeters.
1781 The functions `display-mm-height' and `display-mm-width' consult
1782 this list before asking the system.
1784 Each element has the form (DISPLAY . (WIDTH . HEIGHT)), e.g.
1785 \(\":0.0\" . (287 . 215)).
1787 If `display' is t, it specifies dimensions for all graphical displays
1788 not explicitly specified."
1789 :version "22.1"
1790 :type '(alist :key-type (choice (string :tag "Display name")
1791 (const :tag "Default" t))
1792 :value-type (cons :tag "Dimensions"
1793 (integer :tag "Width")
1794 (integer :tag "Height")))
1795 :group 'frames)
1797 (declare-function x-display-mm-height "xfns.c" (&optional terminal))
1799 (defun display-mm-height (&optional display)
1800 "Return the height of DISPLAY's screen in millimeters.
1801 If the information is unavailable, this function returns nil.
1802 DISPLAY can be a display name or a frame.
1803 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1805 You can override what the system thinks the result should be by
1806 adding an entry to `display-mm-dimensions-alist'.
1808 For graphical terminals, note that on \"multi-monitor\" setups this
1809 refers to the height in millimeters for all physical monitors
1810 associated with DISPLAY. To get information for each physical
1811 monitor, use `display-monitor-attributes-list'."
1812 (and (memq (framep-on-display display) '(x w32 ns))
1813 (or (cddr (assoc (or display (frame-parameter nil 'display))
1814 display-mm-dimensions-alist))
1815 (cddr (assoc t display-mm-dimensions-alist))
1816 (x-display-mm-height display))))
1818 (declare-function x-display-mm-width "xfns.c" (&optional terminal))
1820 (defun display-mm-width (&optional display)
1821 "Return the width of DISPLAY's screen in millimeters.
1822 If the information is unavailable, this function returns nil.
1823 DISPLAY can be a display name or a frame.
1824 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1826 You can override what the system thinks the result should be by
1827 adding an entry to `display-mm-dimensions-alist'.
1829 For graphical terminals, note that on \"multi-monitor\" setups this
1830 refers to the width in millimeters for all physical monitors
1831 associated with DISPLAY. To get information for each physical
1832 monitor, use `display-monitor-attributes-list'."
1833 (and (memq (framep-on-display display) '(x w32 ns))
1834 (or (cadr (assoc (or display (frame-parameter nil 'display))
1835 display-mm-dimensions-alist))
1836 (cadr (assoc t display-mm-dimensions-alist))
1837 (x-display-mm-width display))))
1839 (declare-function x-display-backing-store "xfns.c" (&optional terminal))
1841 ;; In NS port, the return value may be `buffered', `retained', or
1842 ;; `non-retained'. See src/nsfns.m.
1843 (defun display-backing-store (&optional display)
1844 "Return the backing store capability of DISPLAY's screen.
1845 The value may be `always', `when-mapped', `not-useful', or nil if
1846 the question is inapplicable to a certain kind of display.
1847 DISPLAY can be a display name or a frame.
1848 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1849 (let ((frame-type (framep-on-display display)))
1850 (cond
1851 ((memq frame-type '(x w32 ns))
1852 (x-display-backing-store display))
1854 'not-useful))))
1856 (declare-function x-display-save-under "xfns.c" (&optional terminal))
1858 (defun display-save-under (&optional display)
1859 "Return non-nil if DISPLAY's screen supports the SaveUnder feature.
1860 DISPLAY can be a display name or a frame.
1861 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1862 (let ((frame-type (framep-on-display display)))
1863 (cond
1864 ((memq frame-type '(x w32 ns))
1865 (x-display-save-under display))
1867 'not-useful))))
1869 (declare-function x-display-planes "xfns.c" (&optional terminal))
1871 (defun display-planes (&optional display)
1872 "Return the number of planes supported by DISPLAY.
1873 DISPLAY can be a display name or a frame.
1874 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1875 (let ((frame-type (framep-on-display display)))
1876 (cond
1877 ((memq frame-type '(x w32 ns))
1878 (x-display-planes display))
1879 ((eq frame-type 'pc)
1882 (truncate (log (length (tty-color-alist)) 2))))))
1884 (declare-function x-display-color-cells "xfns.c" (&optional terminal))
1886 (defun display-color-cells (&optional display)
1887 "Return the number of color cells supported by DISPLAY.
1888 DISPLAY can be a display name or a frame.
1889 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1890 (let ((frame-type (framep-on-display display)))
1891 (cond
1892 ((memq frame-type '(x w32 ns))
1893 (x-display-color-cells display))
1894 ((eq frame-type 'pc)
1897 (tty-display-color-cells display)))))
1899 (declare-function x-display-visual-class "xfns.c" (&optional terminal))
1901 (defun display-visual-class (&optional display)
1902 "Return the visual class of DISPLAY.
1903 The value is one of the symbols `static-gray', `gray-scale',
1904 `static-color', `pseudo-color', `true-color', or `direct-color'.
1905 DISPLAY can be a display name or a frame.
1906 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1907 (let ((frame-type (framep-on-display display)))
1908 (cond
1909 ((memq frame-type '(x w32 ns))
1910 (x-display-visual-class display))
1911 ((and (memq frame-type '(pc t))
1912 (tty-display-color-p display))
1913 'static-color)
1915 'static-gray))))
1917 (declare-function x-display-monitor-attributes-list "xfns.c"
1918 (&optional terminal))
1919 (declare-function w32-display-monitor-attributes-list "w32fns.c"
1920 (&optional display))
1921 (declare-function ns-display-monitor-attributes-list "nsfns.m"
1922 (&optional terminal))
1924 (defun display-monitor-attributes-list (&optional display)
1925 "Return a list of physical monitor attributes on DISPLAY.
1926 DISPLAY can be a display name, a terminal name, or a frame.
1927 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1928 Each element of the list represents the attributes of a physical
1929 monitor. The first element corresponds to the primary monitor.
1931 The attributes for a physical monitor are represented as an alist
1932 of attribute keys and values as follows:
1934 geometry -- Position and size in pixels in the form of (X Y WIDTH HEIGHT)
1935 workarea -- Position and size of the work area in pixels in the
1936 form of (X Y WIDTH HEIGHT)
1937 mm-size -- Width and height in millimeters in the form of
1938 (WIDTH HEIGHT)
1939 frames -- List of frames dominated by the physical monitor
1940 name (*) -- Name of the physical monitor as a string
1941 source (*) -- Source of multi-monitor information as a string
1943 where X, Y, WIDTH, and HEIGHT are integers. X and Y are coordinates
1944 of the top-left corner, and might be negative for monitors other than
1945 the primary one. Keys labeled with (*) are optional.
1947 The \"work area\" is a measure of the \"usable\" display space.
1948 It may be less than the total screen size, owing to space taken up
1949 by window manager features (docks, taskbars, etc.). The precise
1950 details depend on the platform and environment.
1952 The `source' attribute describes the source from which the information
1953 was obtained. On X, this may be one of: \"Gdk\", \"XRandr\", \"Xinerama\",
1954 or \"fallback\".
1956 A frame is dominated by a physical monitor when either the
1957 largest area of the frame resides in the monitor, or the monitor
1958 is the closest to the frame if the frame does not intersect any
1959 physical monitors. Every (non-tooltip) frame (including invisible ones)
1960 in a graphical display is dominated by exactly one physical
1961 monitor at a time, though it can span multiple (or no) physical
1962 monitors."
1963 (let ((frame-type (framep-on-display display)))
1964 (cond
1965 ((eq frame-type 'x)
1966 (x-display-monitor-attributes-list display))
1967 ((eq frame-type 'w32)
1968 (w32-display-monitor-attributes-list display))
1969 ((eq frame-type 'ns)
1970 (ns-display-monitor-attributes-list display))
1972 (let ((geometry (list 0 0 (display-pixel-width display)
1973 (display-pixel-height display))))
1974 `(((geometry . ,geometry)
1975 (workarea . ,geometry)
1976 (mm-size . (,(display-mm-width display)
1977 ,(display-mm-height display)))
1978 (frames . ,(frames-on-display-list display)))))))))
1981 ;;;; Frame geometry values
1983 (defun frame-geom-value-cons (type value &optional frame)
1984 "Return equivalent geometry value for FRAME as a cons with car `+'.
1985 A geometry value equivalent to VALUE for FRAME is returned,
1986 where the value is a cons with car `+', not numeric.
1987 TYPE is the car of the original geometry spec (TYPE . VALUE).
1988 It is `top' or `left', depending on which edge VALUE is related to.
1989 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1990 If VALUE is a number, then it is converted to a cons value, perhaps
1991 relative to the opposite frame edge from that in the original spec.
1992 FRAME defaults to the selected frame.
1994 Examples (measures in pixels) -
1995 Assuming display height/width=1024, frame height/width=600:
1996 300 inside display edge: 300 => (+ 300)
1997 (+ 300) => (+ 300)
1998 300 inside opposite display edge: (- 300) => (+ 124)
1999 -300 => (+ 124)
2000 300 beyond display edge
2001 (= 724 inside opposite display edge): (+ -300) => (+ -300)
2002 300 beyond display edge
2003 (= 724 inside opposite display edge): (- -300) => (+ 724)
2005 In the 3rd, 4th, and 6th examples, the returned value is relative to
2006 the opposite frame edge from the edge indicated in the input spec."
2007 (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
2008 value)
2009 ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
2010 (t ; e.g. -300, (- 300), (- -300)
2011 (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
2012 (x-display-pixel-width)
2013 (x-display-pixel-height))
2014 (if (integerp value) (- value) (cadr value))
2015 (if (eq 'left type)
2016 (frame-pixel-width frame)
2017 (frame-pixel-height frame)))))))
2019 (defun frame-geom-spec-cons (spec &optional frame)
2020 "Return equivalent geometry spec for FRAME as a cons with car `+'.
2021 A geometry specification equivalent to SPEC for FRAME is returned,
2022 where the value is a cons with car `+', not numeric.
2023 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
2024 If VALUE is a number, then it is converted to a cons value, perhaps
2025 relative to the opposite frame edge from that in the original spec.
2026 FRAME defaults to the selected frame.
2028 Examples (measures in pixels) -
2029 Assuming display height=1024, frame height=600:
2030 top 300 below display top: (top . 300) => (top + 300)
2031 (top + 300) => (top + 300)
2032 bottom 300 above display bottom: (top - 300) => (top + 124)
2033 (top . -300) => (top + 124)
2034 top 300 above display top
2035 (= bottom 724 above display bottom): (top + -300) => (top + -300)
2036 bottom 300 below display bottom
2037 (= top 724 below display top): (top - -300) => (top + 724)
2039 In the 3rd, 4th, and 6th examples, the returned value is relative to
2040 the opposite frame edge from the edge indicated in the input spec."
2041 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
2043 (defun delete-other-frames (&optional frame)
2044 "Delete all frames on FRAME's terminal, except FRAME.
2045 If FRAME uses another frame's minibuffer, the minibuffer frame is
2046 left untouched. Do not delete any of FRAME's child frames. If
2047 FRAME is a child frame, delete its siblings only. FRAME must be
2048 a live frame and defaults to the selected one."
2049 (interactive)
2050 (setq frame (window-normalize-frame frame))
2051 (let ((minibuffer-frame (window-frame (minibuffer-window frame)))
2052 (this (next-frame frame t))
2053 (parent (frame-parent frame))
2054 next)
2055 ;; In a first round consider minibuffer-less frames only.
2056 (while (not (eq this frame))
2057 (setq next (next-frame this t))
2058 (unless (or (eq (window-frame (minibuffer-window this)) this)
2059 ;; When FRAME is a child frame, delete its siblings
2060 ;; only.
2061 (and parent (not (eq (frame-parent this) parent)))
2062 ;; Do not delete a child frame of FRAME.
2063 (eq (frame-parent this) frame))
2064 (delete-frame this))
2065 (setq this next))
2066 ;; In a second round consider all remaining frames.
2067 (setq this (next-frame frame t))
2068 (while (not (eq this frame))
2069 (setq next (next-frame this t))
2070 (unless (or (eq this minibuffer-frame)
2071 ;; When FRAME is a child frame, delete its siblings
2072 ;; only.
2073 (and parent (not (eq (frame-parent this) parent)))
2074 ;; Do not delete a child frame of FRAME.
2075 (eq (frame-parent this) frame))
2076 (delete-frame this))
2077 (setq this next))))
2079 ;; miscellaneous obsolescence declarations
2080 (define-obsolete-variable-alias 'delete-frame-hook
2081 'delete-frame-functions "22.1")
2084 ;;; Window dividers.
2085 (defgroup window-divider nil
2086 "Window dividers."
2087 :version "25.1"
2088 :group 'frames
2089 :group 'windows)
2091 (defcustom window-divider-default-places 'right-only
2092 "Default positions of window dividers.
2093 Possible values are `bottom-only' (dividers on the bottom of each
2094 window only), `right-only' (dividers on the right of each window
2095 only), and t (dividers on the bottom and on the right of each
2096 window). The default is `right-only'.
2098 The value takes effect if and only if dividers are enabled by
2099 `window-divider-mode'.
2101 To position dividers on frames individually, use the frame
2102 parameters `bottom-divider-width' and `right-divider-width'."
2103 :type '(choice (const :tag "Bottom only" bottom-only)
2104 (const :tag "Right only" right-only)
2105 (const :tag "Bottom and right" t))
2106 :initialize 'custom-initialize-default
2107 :set (lambda (symbol value)
2108 (set-default symbol value)
2109 (when window-divider-mode
2110 (window-divider-mode-apply t)))
2111 :version "25.1")
2113 (defun window-divider-width-valid-p (value)
2114 "Return non-nil if VALUE is a positive number."
2115 (and (numberp value) (> value 0)))
2117 (defcustom window-divider-default-bottom-width 6
2118 "Default width of dividers on bottom of windows.
2119 The value must be a positive integer and takes effect when bottom
2120 dividers are displayed by `window-divider-mode'.
2122 To adjust bottom dividers for frames individually, use the frame
2123 parameter `bottom-divider-width'."
2124 :type '(restricted-sexp
2125 :tag "Default width of bottom dividers"
2126 :match-alternatives (frame-window-divider-width-valid-p))
2127 :initialize 'custom-initialize-default
2128 :set (lambda (symbol value)
2129 (set-default symbol value)
2130 (when window-divider-mode
2131 (window-divider-mode-apply t)))
2132 :version "25.1")
2134 (defcustom window-divider-default-right-width 6
2135 "Default width of dividers on the right of windows.
2136 The value must be a positive integer and takes effect when right
2137 dividers are displayed by `window-divider-mode'.
2139 To adjust right dividers for frames individually, use the frame
2140 parameter `right-divider-width'."
2141 :type '(restricted-sexp
2142 :tag "Default width of right dividers"
2143 :match-alternatives (frame-window-divider-width-valid-p))
2144 :initialize 'custom-initialize-default
2145 :set (lambda (symbol value)
2146 (set-default symbol value)
2147 (when window-divider-mode
2148 (window-divider-mode-apply t)))
2149 :version "25.1")
2151 (defun window-divider-mode-apply (enable)
2152 "Apply window divider places and widths to all frames.
2153 If ENABLE is nil, apply default places and widths. Else reset
2154 all divider widths to zero."
2155 (let ((bottom (if (and enable
2156 (memq window-divider-default-places
2157 '(bottom-only t)))
2158 window-divider-default-bottom-width
2160 (right (if (and enable
2161 (memq window-divider-default-places
2162 '(right-only t)))
2163 window-divider-default-right-width
2164 0)))
2165 (modify-all-frames-parameters
2166 (list (cons 'bottom-divider-width bottom)
2167 (cons 'right-divider-width right)))
2168 (setq default-frame-alist
2169 (assq-delete-all
2170 'bottom-divider-width default-frame-alist))
2171 (setq default-frame-alist
2172 (assq-delete-all
2173 'right-divider-width default-frame-alist))
2174 (when (> bottom 0)
2175 (setq default-frame-alist
2176 (cons
2177 (cons 'bottom-divider-width bottom)
2178 default-frame-alist)))
2179 (when (> right 0)
2180 (setq default-frame-alist
2181 (cons
2182 (cons 'right-divider-width right)
2183 default-frame-alist)))))
2185 (define-minor-mode window-divider-mode
2186 "Display dividers between windows (Window Divider mode).
2187 With a prefix argument ARG, enable Window Divider mode if ARG is
2188 positive, and disable it otherwise. If called from Lisp, enable
2189 the mode if ARG is omitted or nil.
2191 The option `window-divider-default-places' specifies on which
2192 side of a window dividers are displayed. The options
2193 `window-divider-default-bottom-width' and
2194 `window-divider-default-right-width' specify their respective
2195 widths."
2196 :group 'window-divider
2197 :global t
2198 (window-divider-mode-apply window-divider-mode))
2200 ;; Blinking cursor
2202 (defvar blink-cursor-idle-timer nil
2203 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
2204 The function `blink-cursor-start' is called when the timer fires.")
2206 (defvar blink-cursor-timer nil
2207 "Timer started from `blink-cursor-start'.
2208 This timer calls `blink-cursor-timer-function' every
2209 `blink-cursor-interval' seconds.")
2211 (defgroup cursor nil
2212 "Displaying text cursors."
2213 :version "21.1"
2214 :group 'frames)
2216 (defcustom blink-cursor-delay 0.5
2217 "Seconds of idle time before the first blink of the cursor.
2218 Values smaller than 0.2 sec are treated as 0.2 sec."
2219 :type 'number
2220 :group 'cursor
2221 :set (lambda (symbol value)
2222 (set-default symbol value)
2223 (when blink-cursor-idle-timer (blink-cursor--start-idle-timer))))
2225 (defcustom blink-cursor-interval 0.5
2226 "Length of cursor blink interval in seconds."
2227 :type 'number
2228 :group 'cursor
2229 :set (lambda (symbol value)
2230 (set-default symbol value)
2231 (when blink-cursor-timer (blink-cursor--start-timer))))
2233 (defcustom blink-cursor-blinks 10
2234 "How many times to blink before using a solid cursor on NS, X, and MS-Windows.
2235 Use 0 or negative value to blink forever."
2236 :version "24.4"
2237 :type 'integer
2238 :group 'cursor)
2240 (defvar blink-cursor-blinks-done 1
2241 "Number of blinks done since we started blinking on NS, X, and MS-Windows.")
2243 (defun blink-cursor--start-idle-timer ()
2244 "Start the `blink-cursor-idle-timer'."
2245 (when blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
2246 (setq blink-cursor-idle-timer
2247 ;; The 0.2 sec limitation from below is to avoid erratic
2248 ;; behavior (or downright failure to display the cursor
2249 ;; during command execution) if they set blink-cursor-delay
2250 ;; to a very small or even zero value.
2251 (run-with-idle-timer (max 0.2 blink-cursor-delay)
2252 :repeat #'blink-cursor-start)))
2254 (defun blink-cursor--start-timer ()
2255 "Start the `blink-cursor-timer'."
2256 (when blink-cursor-timer (cancel-timer blink-cursor-timer))
2257 (setq blink-cursor-timer
2258 (run-with-timer blink-cursor-interval blink-cursor-interval
2259 #'blink-cursor-timer-function)))
2261 (defun blink-cursor-start ()
2262 "Timer function called from the timer `blink-cursor-idle-timer'.
2263 This starts the timer `blink-cursor-timer', which makes the cursor blink
2264 if appropriate. It also arranges to cancel that timer when the next
2265 command starts, by installing a pre-command hook."
2266 (when (null blink-cursor-timer)
2267 ;; Set up the timer first, so that if this signals an error,
2268 ;; blink-cursor-end is not added to pre-command-hook.
2269 (setq blink-cursor-blinks-done 1)
2270 (blink-cursor--start-timer)
2271 (add-hook 'pre-command-hook 'blink-cursor-end)
2272 (internal-show-cursor nil nil)))
2274 (defun blink-cursor-timer-function ()
2275 "Timer function of timer `blink-cursor-timer'."
2276 (internal-show-cursor nil (not (internal-show-cursor-p)))
2277 ;; Suspend counting blinks when the w32 menu-bar menu is displayed,
2278 ;; since otherwise menu tooltips will behave erratically.
2279 (or (and (fboundp 'w32--menu-bar-in-use)
2280 (w32--menu-bar-in-use))
2281 (setq blink-cursor-blinks-done (1+ blink-cursor-blinks-done)))
2282 ;; Each blink is two calls to this function.
2283 (when (and (> blink-cursor-blinks 0)
2284 (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done))
2285 (blink-cursor-suspend)
2286 (add-hook 'post-command-hook 'blink-cursor-check)))
2289 (defun blink-cursor-end ()
2290 "Stop cursor blinking.
2291 This is installed as a pre-command hook by `blink-cursor-start'.
2292 When run, it cancels the timer `blink-cursor-timer' and removes
2293 itself as a pre-command hook."
2294 (remove-hook 'pre-command-hook 'blink-cursor-end)
2295 (internal-show-cursor nil t)
2296 (when blink-cursor-timer
2297 (cancel-timer blink-cursor-timer)
2298 (setq blink-cursor-timer nil)))
2300 (defun blink-cursor-suspend ()
2301 "Suspend cursor blinking.
2302 This is called when no frame has focus and timers can be suspended.
2303 Timers are restarted by `blink-cursor-check', which is called when a
2304 frame receives focus."
2305 (blink-cursor-end)
2306 (when blink-cursor-idle-timer
2307 (cancel-timer blink-cursor-idle-timer)
2308 (setq blink-cursor-idle-timer nil)))
2310 (defun blink-cursor-check ()
2311 "Check if cursor blinking shall be restarted.
2312 This is done when a frame gets focus. Blink timers may be stopped by
2313 `blink-cursor-suspend'."
2314 (when (and blink-cursor-mode
2315 (not blink-cursor-idle-timer))
2316 (remove-hook 'post-command-hook 'blink-cursor-check)
2317 (blink-cursor--start-idle-timer)))
2319 (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
2321 (define-minor-mode blink-cursor-mode
2322 "Toggle cursor blinking (Blink Cursor mode).
2323 With a prefix argument ARG, enable Blink Cursor mode if ARG is
2324 positive, and disable it otherwise. If called from Lisp, enable
2325 the mode if ARG is omitted or nil.
2327 If the value of `blink-cursor-blinks' is positive (10 by default),
2328 the cursor stops blinking after that number of blinks, if Emacs
2329 gets no input during that time.
2331 See also `blink-cursor-interval' and `blink-cursor-delay'.
2333 This command is effective only on graphical frames. On text-only
2334 terminals, cursor blinking is controlled by the terminal."
2335 :init-value (not (or noninteractive
2336 no-blinking-cursor
2337 (eq system-type 'ms-dos)
2338 (not (memq window-system '(x w32 ns)))))
2339 :initialize 'custom-initialize-delay
2340 :group 'cursor
2341 :global t
2342 (blink-cursor-suspend)
2343 (remove-hook 'focus-in-hook #'blink-cursor-check)
2344 (remove-hook 'focus-out-hook #'blink-cursor-suspend)
2345 (when blink-cursor-mode
2346 (add-hook 'focus-in-hook #'blink-cursor-check)
2347 (add-hook 'focus-out-hook #'blink-cursor-suspend)
2348 (blink-cursor--start-idle-timer)))
2352 ;; Frame maximization/fullscreen
2354 (defun toggle-frame-maximized ()
2355 "Toggle maximization state of selected frame.
2356 Maximize selected frame or un-maximize if it is already maximized.
2358 If the frame is in fullscreen state, don't change its state, but
2359 set the frame's `fullscreen-restore' parameter to `maximized', so
2360 the frame will be maximized after disabling fullscreen state.
2362 Note that with some window managers you may have to set
2363 `frame-resize-pixelwise' to non-nil in order to make a frame
2364 appear truly maximized. In addition, you may have to set
2365 `x-frame-normalize-before-maximize' in order to enable
2366 transitions from one fullscreen state to another.
2368 See also `toggle-frame-fullscreen'."
2369 (interactive)
2370 (let ((fullscreen (frame-parameter nil 'fullscreen)))
2371 (cond
2372 ((memq fullscreen '(fullscreen fullboth))
2373 (set-frame-parameter nil 'fullscreen-restore 'maximized))
2374 ((eq fullscreen 'maximized)
2375 (set-frame-parameter nil 'fullscreen nil))
2377 (set-frame-parameter nil 'fullscreen 'maximized)))))
2379 (defun toggle-frame-fullscreen ()
2380 "Toggle fullscreen state of selected frame.
2381 Make selected frame fullscreen or restore its previous size if it
2382 is already fullscreen.
2384 Before making the frame fullscreen remember the current value of
2385 the frame's `fullscreen' parameter in the `fullscreen-restore'
2386 parameter of the frame. That value is used to restore the
2387 frame's fullscreen state when toggling fullscreen the next time.
2389 Note that with some window managers you may have to set
2390 `frame-resize-pixelwise' to non-nil in order to make a frame
2391 appear truly fullscreen. In addition, you may have to set
2392 `x-frame-normalize-before-maximize' in order to enable
2393 transitions from one fullscreen state to another.
2395 See also `toggle-frame-maximized'."
2396 (interactive)
2397 (let ((fullscreen (frame-parameter nil 'fullscreen)))
2398 (if (memq fullscreen '(fullscreen fullboth))
2399 (let ((fullscreen-restore (frame-parameter nil 'fullscreen-restore)))
2400 (if (memq fullscreen-restore '(maximized fullheight fullwidth))
2401 (set-frame-parameter nil 'fullscreen fullscreen-restore)
2402 (set-frame-parameter nil 'fullscreen nil)))
2403 (modify-frame-parameters
2404 nil `((fullscreen . fullboth) (fullscreen-restore . ,fullscreen))))))
2406 ;;;; Key bindings
2408 (define-key ctl-x-5-map "2" 'make-frame-command)
2409 (define-key ctl-x-5-map "1" 'delete-other-frames)
2410 (define-key ctl-x-5-map "0" 'delete-frame)
2411 (define-key ctl-x-5-map "o" 'other-frame)
2412 (define-key global-map [f11] 'toggle-frame-fullscreen)
2413 (define-key global-map [(meta f10)] 'toggle-frame-maximized)
2414 (define-key esc-map [f10] 'toggle-frame-maximized)
2417 ;; Misc.
2419 ;; Only marked as obsolete in 24.3.
2420 (define-obsolete-variable-alias 'automatic-hscrolling
2421 'auto-hscroll-mode "22.1")
2423 (make-variable-buffer-local 'show-trailing-whitespace)
2425 ;; Defined in dispnew.c.
2426 (make-obsolete-variable
2427 'window-system-version "it does not give useful information." "24.3")
2429 ;; Variables which should trigger redisplay of the current buffer.
2430 (mapc (lambda (var)
2431 (add-variable-watcher var (symbol-function 'set-buffer-redisplay)))
2432 '(line-spacing
2433 overline-margin
2434 line-prefix
2435 wrap-prefix
2436 truncate-lines
2437 bidi-paragraph-direction
2438 bidi-display-reordering))
2440 (provide 'frame)
2442 ;;; frame.el ends here