aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-07-03 18:16:07 -0400
committerChong Yidong2011-07-03 18:16:07 -0400
commit1485f4c03a3e887f8e60fefb96e5e3d9ca484cf7 (patch)
tree07c3889b6d224dbf2c2fcc647580c2ff548e56dd
parent9fa3dd45482a9fa8084fae495b3a857a216decf2 (diff)
downloademacs-1485f4c03a3e887f8e60fefb96e5e3d9ca484cf7.tar.gz
emacs-1485f4c03a3e887f8e60fefb96e5e3d9ca484cf7.zip
Fix how custom themes handle faces, so the multi-tty/multi-frame case works.
* lisp/custom.el (custom-push-theme): Don't record faces in `changed' theme; this doesn't work correctly for per-frame face settings. (disable-theme): Use face-set-after-frame-default to reset faces. (custom--frame-color-default): New function. * lisp/frame.el (frame-background-mode, frame-set-background-mode): Moved from faces.el. (frame-default-terminal-background): New function. * src/xfaces.c (Finternal_merge_in_global_face): Modify the foreground and background color parameters if they have been changed.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/custom.el57
-rw-r--r--lisp/faces.el106
-rw-r--r--lisp/frame.el110
-rw-r--r--src/ChangeLog5
-rw-r--r--src/xfaces.c12
6 files changed, 176 insertions, 125 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2e4b6cc22bc..8324f3fdb62 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12011-07-03 Chong Yidong <cyd@stupidchicken.com>
2
3 * frame.el (frame-background-mode, frame-set-background-mode):
4 Moved from faces.el.
5 (frame-default-terminal-background): New function.
6
7 * custom.el (custom-push-theme): Don't record faces in `changed'
8 theme; this doesn't work correctly for per-frame face settings.
9 (disable-theme): Use face-set-after-frame-default to reset faces.
10 (custom--frame-color-default): New function.
11
12011-07-03 Lars Magne Ingebrigtsen <larsi@gnus.org> 122011-07-03 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 13
3 * dired.el (dired-flagging-regexp): Removed unused variable 14 * dired.el (dired-flagging-regexp): Removed unused variable
diff --git a/lisp/custom.el b/lisp/custom.el
index a1c7f3e11e7..11dc1859c00 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -855,25 +855,18 @@ See `custom-known-themes' for a list of known themes."
855 ;; Add a new setting: 855 ;; Add a new setting:
856 (t 856 (t
857 (unless old 857 (unless old
858 ;; If the user changed the value outside of Customize, we 858 ;; If the user changed a variable outside of Customize, save
859 ;; first save the current value to a fake theme, `changed'. 859 ;; the value to a fake theme, `changed'. If the theme is
860 ;; This ensures that the user-set value comes back if the 860 ;; later disabled, we use this to bring back the old value.
861 ;; theme is later disabled. 861 ;;
862 (cond ((and (eq prop 'theme-value) 862 ;; For faces, we just use `face-new-frame-defaults' to
863 (boundp symbol)) 863 ;; recompute when the theme is disabled.
864 (let ((sv (get symbol 'standard-value)) 864 (when (and (eq prop 'theme-value)
865 (val (symbol-value symbol))) 865 (boundp symbol))
866 (unless (and sv (equal (eval (car sv)) val)) 866 (let ((sv (get symbol 'standard-value))
867 (setq old `((changed ,(custom-quote val))))))) 867 (val (symbol-value symbol)))
868 ((and (facep symbol) 868 (unless (and sv (equal (eval (car sv)) val))
869 (not (face-attr-match-p 869 (setq old `((changed ,(custom-quote val))))))))
870 symbol
871 (custom-fix-face-spec
872 (face-spec-choose
873 (get symbol 'face-defface-spec))))))
874 (setq old `((changed
875 (,(append '(t) (custom-face-attributes-get
876 symbol nil)))))))))
877 (put symbol prop (cons (list theme value) old)) 870 (put symbol prop (cons (list theme value) old))
878 (put theme 'theme-settings 871 (put theme 'theme-settings
879 (cons (list prop symbol theme value) theme-settings)))))) 872 (cons (list prop symbol theme value) theme-settings))))))
@@ -1356,11 +1349,33 @@ See `custom-enabled-themes' for a list of enabled themes."
1356 ;; If the face spec specified by this theme is in the 1349 ;; If the face spec specified by this theme is in the
1357 ;; saved-face property, reset that property. 1350 ;; saved-face property, reset that property.
1358 (when (equal (nth 3 s) (get symbol 'saved-face)) 1351 (when (equal (nth 3 s) (get symbol 'saved-face))
1359 (put symbol 'saved-face (and val (cadr (car val))))) 1352 (put symbol 'saved-face (and val (cadr (car val)))))))))
1360 (custom-theme-recalc-face symbol))))) 1353 ;; Recompute faces on all frames.
1354 (dolist (frame (frame-list))
1355 ;; We must reset the fg and bg color frame parameters, or
1356 ;; `face-set-after-frame-default' will use the existing
1357 ;; parameters, which could be from the disabled theme.
1358 (set-frame-parameter frame 'background-color
1359 (custom--frame-color-default
1360 frame :background "background" "Background"
1361 "unspecified-bg" "white"))
1362 (set-frame-parameter frame 'foreground-color
1363 (custom--frame-color-default
1364 frame :foreground "foreground" "Foreground"
1365 "unspecified-fg" "black"))
1366 (face-set-after-frame-default frame))
1361 (setq custom-enabled-themes 1367 (setq custom-enabled-themes
1362 (delq theme custom-enabled-themes))))) 1368 (delq theme custom-enabled-themes)))))
1363 1369
1370(defun custom--frame-color-default (frame attribute resource-attr resource-class
1371 tty-default x-default)
1372 (let ((col (face-attribute 'default attribute t)))
1373 (cond
1374 ((and col (not (eq col 'unspecified))) col)
1375 ((null (window-system frame)) tty-default)
1376 ((setq col (x-get-resource resource-attr resource-class)) col)
1377 (t x-default))))
1378
1364(defun custom-variable-theme-value (variable) 1379(defun custom-variable-theme-value (variable)
1365 "Return (list VALUE) indicating the custom theme value of VARIABLE. 1380 "Return (list VALUE) indicating the custom theme value of VARIABLE.
1366That is to say, it specifies what the value should be according to 1381That is to say, it specifies what the value should be according to
diff --git a/lisp/faces.el b/lisp/faces.el
index c29d8c9bfd8..34e154314b5 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -1821,109 +1821,6 @@ Return nil if it has no specified face."
1821 (cond ((memq 'background-color face) (cdr (memq 'background-color face))) 1821 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1822 ((memq ':background face) (cadr (memq ':background face))))) 1822 ((memq ':background face) (cadr (memq ':background face)))))
1823 (t nil)))) ; Invalid face value. 1823 (t nil)))) ; Invalid face value.
1824
1825;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1826;;; Background mode.
1827;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1828
1829(defcustom frame-background-mode nil
1830 "The brightness of the background.
1831Set this to the symbol `dark' if your background color is dark,
1832`light' if your background is light, or nil (automatic by default)
1833if you want Emacs to examine the brightness for you. Don't set this
1834variable with `setq'; this won't have the expected effect."
1835 :group 'faces
1836 :set #'(lambda (var value)
1837 (set-default var value)
1838 (mapc 'frame-set-background-mode (frame-list)))
1839 :initialize 'custom-initialize-changed
1840 :type '(choice (const dark)
1841 (const light)
1842 (const :tag "automatic" nil)))
1843
1844
1845(declare-function x-get-resource "frame.c"
1846 (attribute class &optional component subclass))
1847
1848(defvar inhibit-frame-set-background-mode nil)
1849
1850(defun frame-set-background-mode (frame &optional keep-face-specs)
1851 "Set up display-dependent faces on FRAME.
1852Display-dependent faces are those which have different definitions
1853according to the `background-mode' and `display-type' frame parameters.
1854
1855If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
1856face specs for the new background mode."
1857 (unless inhibit-frame-set-background-mode
1858 (let* ((bg-resource
1859 (and (window-system frame)
1860 (x-get-resource "backgroundMode" "BackgroundMode")))
1861 (bg-color (frame-parameter frame 'background-color))
1862 (terminal-bg-mode (terminal-parameter frame 'background-mode))
1863 (tty-type (tty-type frame))
1864 (default-bg-mode
1865 (if (or (window-system frame)
1866 (and tty-type
1867 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
1868 tty-type)))
1869 'light
1870 'dark))
1871 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
1872 (bg-mode
1873 (cond (frame-background-mode)
1874 (bg-resource (intern (downcase bg-resource)))
1875 (terminal-bg-mode)
1876 ((equal bg-color "unspecified-fg") ; inverted colors
1877 non-default-bg-mode)
1878 ((not (color-values bg-color frame))
1879 default-bg-mode)
1880 ((>= (apply '+ (color-values bg-color frame))
1881 ;; Just looking at the screen, colors whose
1882 ;; values add up to .6 of the white total
1883 ;; still look dark to me.
1884 (* (apply '+ (color-values "white" frame)) .6))
1885 'light)
1886 (t 'dark)))
1887 (display-type
1888 (cond ((null (window-system frame))
1889 (if (tty-display-color-p frame) 'color 'mono))
1890 ((display-color-p frame)
1891 'color)
1892 ((x-display-grayscale-p frame)
1893 'grayscale)
1894 (t 'mono)))
1895 (old-bg-mode
1896 (frame-parameter frame 'background-mode))
1897 (old-display-type
1898 (frame-parameter frame 'display-type)))
1899
1900 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1901 (let ((locally-modified-faces nil)
1902 ;; Prevent face-spec-recalc from calling this function
1903 ;; again, resulting in a loop (bug#911).
1904 (inhibit-frame-set-background-mode t)
1905 (params (list (cons 'background-mode bg-mode)
1906 (cons 'display-type display-type))))
1907 (if keep-face-specs
1908 (modify-frame-parameters frame params)
1909 ;; If we are recomputing face specs, first collect a list
1910 ;; of faces that don't match their face-specs. These are
1911 ;; the faces modified on FRAME, and we avoid changing them
1912 ;; below. Use a negative list to avoid consing (we assume
1913 ;; most faces are unmodified).
1914 (dolist (face (face-list))
1915 (and (not (get face 'face-override-spec))
1916 (not (face-spec-match-p face
1917 (face-user-default-spec face)
1918 (selected-frame)))
1919 (push face locally-modified-faces)))
1920 ;; Now change to the new frame parameters
1921 (modify-frame-parameters frame params)
1922 ;; For all unmodified named faces, choose face specs
1923 ;; matching the new frame parameters.
1924 (dolist (face (face-list))
1925 (unless (memq face locally-modified-faces)
1926 (face-spec-recalc face frame)))))))))
1927 1824
1928 1825
1929;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1826;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2020,7 +1917,8 @@ settings, X resources, and `face-new-frame-defaults'.
2020Finally, apply any relevant face attributes found amongst the 1917Finally, apply any relevant face attributes found amongst the
2021frame parameters in PARAMETERS." 1918frame parameters in PARAMETERS."
2022 (let ((window-system-p (memq (window-system frame) '(x w32)))) 1919 (let ((window-system-p (memq (window-system frame) '(x w32))))
2023 (dolist (face (nreverse (face-list))) ;Why reverse? --Stef 1920 ;; The `reverse' is so that `default' goes first.
1921 (dolist (face (nreverse (face-list)))
2024 (condition-case () 1922 (condition-case ()
2025 (progn 1923 (progn
2026 ;; Initialize faces from face spec and custom theme. 1924 ;; Initialize faces from face spec and custom theme.
diff --git a/lisp/frame.el b/lisp/frame.el
index 3ceec2657e7..d6f82750347 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -847,6 +847,116 @@ If there is no frame by that name, signal an error."
847 (if frame 847 (if frame
848 (select-frame-set-input-focus frame) 848 (select-frame-set-input-focus frame)
849 (error "There is no frame named `%s'" name)))) 849 (error "There is no frame named `%s'" name))))
850
851
852;;;; Background mode.
853
854(defcustom frame-background-mode nil
855 "The brightness of the background.
856Set this to the symbol `dark' if your background color is dark,
857`light' if your background is light, or nil (automatic by default)
858if you want Emacs to examine the brightness for you. Don't set this
859variable with `setq'; this won't have the expected effect."
860 :group 'faces
861 :set #'(lambda (var value)
862 (set-default var value)
863 (mapc 'frame-set-background-mode (frame-list)))
864 :initialize 'custom-initialize-changed
865 :type '(choice (const dark)
866 (const light)
867 (const :tag "automatic" nil)))
868
869(declare-function x-get-resource "frame.c"
870 (attribute class &optional component subclass))
871
872(defvar inhibit-frame-set-background-mode nil)
873
874(defun frame-set-background-mode (frame &optional keep-face-specs)
875 "Set up display-dependent faces on FRAME.
876Display-dependent faces are those which have different definitions
877according to the `background-mode' and `display-type' frame parameters.
878
879If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
880face specs for the new background mode."
881 (unless inhibit-frame-set-background-mode
882 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
883 (bg-color (frame-parameter frame 'background-color))
884 (tty-type (tty-type frame))
885 (default-bg-mode
886 (if (or (window-system frame)
887 (and tty-type
888 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
889 tty-type)))
890 'light
891 'dark))
892 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
893 (bg-mode
894 (cond (frame-default-bg-mode)
895 ((equal bg-color "unspecified-fg") ; inverted colors
896 non-default-bg-mode)
897 ((not (color-values bg-color frame))
898 default-bg-mode)
899 ((>= (apply '+ (color-values bg-color frame))
900 ;; Just looking at the screen, colors whose
901 ;; values add up to .6 of the white total
902 ;; still look dark to me.
903 (* (apply '+ (color-values "white" frame)) .6))
904 'light)
905 (t 'dark)))
906 (display-type
907 (cond ((null (window-system frame))
908 (if (tty-display-color-p frame) 'color 'mono))
909 ((display-color-p frame)
910 'color)
911 ((x-display-grayscale-p frame)
912 'grayscale)
913 (t 'mono)))
914 (old-bg-mode
915 (frame-parameter frame 'background-mode))
916 (old-display-type
917 (frame-parameter frame 'display-type)))
918
919 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
920 (let ((locally-modified-faces nil)
921 ;; Prevent face-spec-recalc from calling this function
922 ;; again, resulting in a loop (bug#911).
923 (inhibit-frame-set-background-mode t)
924 (params (list (cons 'background-mode bg-mode)
925 (cons 'display-type display-type))))
926 (if keep-face-specs
927 (modify-frame-parameters frame params)
928 ;; If we are recomputing face specs, first collect a list
929 ;; of faces that don't match their face-specs. These are
930 ;; the faces modified on FRAME, and we avoid changing them
931 ;; below. Use a negative list to avoid consing (we assume
932 ;; most faces are unmodified).
933 (dolist (face (face-list))
934 (and (not (get face 'face-override-spec))
935 (not (face-spec-match-p face
936 (face-user-default-spec face)
937 (selected-frame)))
938 (push face locally-modified-faces)))
939 ;; Now change to the new frame parameters
940 (modify-frame-parameters frame params)
941 ;; For all unmodified named faces, choose face specs
942 ;; matching the new frame parameters.
943 (dolist (face (face-list))
944 (unless (memq face locally-modified-faces)
945 (face-spec-recalc face frame)))))))))
946
947(defun frame-terminal-default-bg-mode (frame)
948 "Return the default background mode of FRAME.
949This checks the `frame-background-mode' variable, the X resource
950named \"backgroundMode\" (if FRAME is an X frame), and finally
951the `background-mode' terminal parameter."
952 (or frame-background-mode
953 (let ((bg-resource
954 (and (window-system frame)
955 (x-get-resource "backgroundMode" "BackgroundMode"))))
956 (if bg-resource
957 (intern (downcase bg-resource))))
958 (terminal-parameter frame 'background-mode)))
959
850 960
851;;;; Frame configurations 961;;;; Frame configurations
852 962
diff --git a/src/ChangeLog b/src/ChangeLog
index ad5b9c41c30..b77759527e7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12011-07-03 Chong Yidong <cyd@stupidchicken.com>
2
3 * xfaces.c (Finternal_merge_in_global_face): Modify the foreground
4 and background color parameters if they have been changed.
5
12011-07-03 Lars Magne Ingebrigtsen <larsi@gnus.org> 62011-07-03 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 7
3 * editfns.c (Fformat): Clarify the - and 0 flags (bug#6659). 8 * editfns.c (Fformat): Clarify the - and 0 flags (bug#6659).
diff --git a/src/xfaces.c b/src/xfaces.c
index 4f06bd3ba55..91f4b133466 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -3813,6 +3813,18 @@ Default face attributes override any local face attributes. */)
3813 Fmodify_frame_parameters (frame, Fcons (Fcons (Qfont, name), 3813 Fmodify_frame_parameters (frame, Fcons (Fcons (Qfont, name),
3814 Qnil)); 3814 Qnil));
3815 } 3815 }
3816
3817 if (STRINGP (gvec[LFACE_FOREGROUND_INDEX]))
3818 Fmodify_frame_parameters (frame,
3819 Fcons (Fcons (Qforeground_color,
3820 gvec[LFACE_FOREGROUND_INDEX]),
3821 Qnil));
3822
3823 if (STRINGP (gvec[LFACE_BACKGROUND_INDEX]))
3824 Fmodify_frame_parameters (frame,
3825 Fcons (Fcons (Qbackground_color,
3826 gvec[LFACE_BACKGROUND_INDEX]),
3827 Qnil));
3816 } 3828 }
3817 } 3829 }
3818 3830