Function: frame-set-background-mode

frame-set-background-mode is a byte-compiled function defined in frame.el.gz.

Signature

(frame-set-background-mode FRAME &optional KEEP-FACE-SPECS)

Documentation

Set up display-dependent faces on FRAME.

Display-dependent faces are those which have different definitions according to the background-mode and display-type frame parameters.

If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate face specs for the new background mode.

Probably introduced at or before Emacs version 24.1.

Source Code

;; Defined in /usr/src/emacs/lisp/frame.el.gz
(defun frame-set-background-mode (frame &optional keep-face-specs)
  "Set up display-dependent faces on FRAME.
Display-dependent faces are those which have different definitions
according to the `background-mode' and `display-type' frame parameters.

If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
face specs for the new background mode."
  (unless inhibit-frame-set-background-mode
    (let* ((bg-mode
	    (frame--current-background-mode frame))
	   (display-type
	    (cond ((null (window-system frame))
		   (if (tty-display-color-p frame) 'color 'mono))
		  ((display-color-p frame)
		   'color)
		  ((x-display-grayscale-p frame)
		   'grayscale)
		  (t 'mono)))
	   (old-bg-mode
	    (frame-parameter frame 'background-mode))
	   (old-display-type
	    (frame-parameter frame 'display-type)))

      (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
	(let ((locally-modified-faces nil)
	      ;; Prevent face-spec-recalc from calling this function
	      ;; again, resulting in a loop (bug#911).
	      (inhibit-frame-set-background-mode t)
	      (params (list (cons 'background-mode bg-mode)
			    (cons 'display-type display-type))))
	  (if keep-face-specs
	      (modify-frame-parameters frame params)
	    ;; If we are recomputing face specs, first collect a list
	    ;; of faces that don't match their face-specs.  These are
	    ;; the faces modified on FRAME, and we avoid changing them
	    ;; below.  Use a negative list to avoid consing (we assume
	    ;; most faces are unmodified).
	    (dolist (face (face-list))
	      (and (not (get face 'face-override-spec))
		   (not (and
                         ;; If the face was not yet realized for the
                         ;; frame, face-spec-match-p will signal an
                         ;; error, so treat such a missing face as
                         ;; having a mismatched spec; the call to
                         ;; face-spec-recalc below will then realize
                         ;; the face for the frame.  This happens
                         ;; during startup with -rv on the command
                         ;; line for the initial frame, because frames
                         ;; are not recorded in the pdump file.
                         (gethash face (frame--face-hash-table))
                         (face-spec-match-p face
                                            (face-user-default-spec face)
                                            frame)))
		   (push face locally-modified-faces)))
	    ;; Now change to the new frame parameters
	    (modify-frame-parameters frame params)
	    ;; For all unmodified named faces, choose face specs
	    ;; matching the new frame parameters.
	    (dolist (face (face-list))
	      (unless (memq face locally-modified-faces)
		(face-spec-recalc face frame)))))))))