Mercurial > emacs
annotate lisp/dynamic-setting.el @ 110244:e801f2c8daf3
Merge from mainline.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Thu, 02 Sep 2010 05:10:45 +0000 |
parents | 1b626601d32d |
children |
rev | line source |
---|---|
108024
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
1 ;;; dynamic-setting.el --- Support dynamic changes |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
2 |
106815 | 3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
4 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
5 ;; Author: Jan Djärv <jan.h.d@swipnet.se> |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
6 ;; Maintainer: FSF |
108024
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
7 ;; Keywords: font, system-font, tool-bar-style |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
109749
diff
changeset
|
8 ;; Package: emacs |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
9 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
11 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
15 ;; (at your option) any later version. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
16 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
21 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
24 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
25 ;;; Commentary: |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
26 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
27 ;; This file provides the lisp part of the GConf and XSetting code in |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
28 ;; xsetting.c. But it is nothing that prevents it from being used by |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
29 ;; other configuration schemes. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
30 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
31 ;;; Code: |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
32 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
33 ;;; Customizable variables |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
34 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
35 (declare-function font-get-system-font "xsettings.c" ()) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
36 |
106102
0cdf7c60b414
* font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents:
106097
diff
changeset
|
37 (defvar font-use-system-font) |
0cdf7c60b414
* font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents:
106097
diff
changeset
|
38 |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
39 (defun font-setting-change-default-font (display-or-frame set-font) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
40 "Change font and/or font settings for frames on display DISPLAY-OR-FRAME. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
41 If DISPLAY-OR-FRAME is a frame, the display is the one for that frame. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
42 |
106102
0cdf7c60b414
* font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents:
106097
diff
changeset
|
43 If SET-FONT is non-nil, change the font for frames. Otherwise re-apply the |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
44 current form for the frame (i.e. hinting or somesuch changed)." |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
45 |
106102
0cdf7c60b414
* font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents:
106097
diff
changeset
|
46 (let ((new-font (and (fboundp 'font-get-system-font) |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
47 (font-get-system-font)))) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
48 (when new-font |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
49 ;; Be careful here: when set-face-attribute is called for the |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
50 ;; :font attribute, Emacs tries to guess the best matching font |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
51 ;; by examining the other face attributes (Bug#2476). |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
52 |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
53 (clear-font-cache) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
54 ;; Set for current frames. Only change font for those that have |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
55 ;; the old font now. If they don't have the old font, the user |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
56 ;; probably changed it. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
57 (dolist (f (frames-on-display-list display-or-frame)) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
58 (if (display-graphic-p f) |
106102
0cdf7c60b414
* font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents:
106097
diff
changeset
|
59 (let* ((frame-font |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
60 (or (font-get (face-attribute 'default :font f |
106750
10b9609fb6b7
Fixing user-spec for fonts instead of using name.
Jan D. <jan.h.d@swipnet.se>
parents:
106352
diff
changeset
|
61 'default) :user-spec) |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
62 (frame-parameter f 'font-parameter))) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
63 (font-to-set |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
64 (if set-font new-font |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
65 ;; else set font again, hinting etc. may have changed. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
66 frame-font))) |
106097
5fa329215a93
xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
106085
diff
changeset
|
67 (if font-to-set |
5fa329215a93
xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
106085
diff
changeset
|
68 (progn |
5fa329215a93
xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
106085
diff
changeset
|
69 (set-frame-parameter f 'font-parameter font-to-set) |
106102
0cdf7c60b414
* font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents:
106097
diff
changeset
|
70 (set-face-attribute 'default f |
106097
5fa329215a93
xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
106085
diff
changeset
|
71 :width 'normal |
5fa329215a93
xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
106085
diff
changeset
|
72 :weight 'normal |
5fa329215a93
xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
106085
diff
changeset
|
73 :slant 'normal |
5fa329215a93
xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents:
106085
diff
changeset
|
74 :font font-to-set)))))) |
106102
0cdf7c60b414
* font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents:
106097
diff
changeset
|
75 |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
76 ;; Set for future frames. |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
77 (set-face-attribute 'default t :font new-font) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
78 (let ((spec (list (list t (face-attr-construct 'default))))) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
79 (progn |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
80 (put 'default 'customized-face spec) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
81 (custom-push-theme 'theme-face 'default 'user 'set spec) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
82 (put 'default 'face-modified nil)))))) |
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
83 |
108024
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
84 (defun dynamic-setting-handle-config-changed-event (event) |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
85 "Handle config-changed-event on the display in EVENT. |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
86 Changes can be |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
87 The monospace font. If `font-use-system-font' is nil, the font |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
88 is not changed. |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
89 Xft parameters, like DPI and hinting. |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
90 The tool bar style." |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
91 (interactive "e") |
108024
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
92 (let ((type (nth 1 event)) |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
93 (display-name (nth 2 event))) |
108024
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
94 (cond ((and (eq type 'monospace-font-name) font-use-system-font) |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
95 (font-setting-change-default-font display-name t)) |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
96 |
108024
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
97 ((eq type 'font-render) |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
98 (font-setting-change-default-font display-name nil)) |
106085
cd4cbab8bb21
Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff
changeset
|
99 |
109749
be18c3b67d66
Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents:
109070
diff
changeset
|
100 ;; This is a bit heavy, ideally we would just clear faces |
be18c3b67d66
Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents:
109070
diff
changeset
|
101 ;; on the affected display, and perhaps only the relevant |
be18c3b67d66
Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents:
109070
diff
changeset
|
102 ;; faces. Oh well. |
be18c3b67d66
Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents:
109070
diff
changeset
|
103 ((eq type 'theme-name) (clear-face-cache)) |
be18c3b67d66
Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents:
109070
diff
changeset
|
104 |
108024
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
105 ((eq type 'tool-bar-style) (force-mode-line-update t))))) |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
106 |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
107 (define-key special-event-map [config-changed-event] |
4d8277a44bb4
Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents:
106815
diff
changeset
|
108 'dynamic-setting-handle-config-changed-event) |
106352 | 109 |
110 ;; arch-tag: 3a57e78f-1cd6-48b6-ab75-98f160dcc017 |