Mercurial > emacs
comparison lisp/font-setting.el @ 106085:cd4cbab8bb21
Handle system default font and changing font parameters.
* xterm.h (struct x_display_info): Add atoms and Window for xsettings.
* xterm.c (handle_one_xevent): Call xft_settings_event for
ClientMessage, PropertyNotify and DestroyNotify.
(x_term_init): If we have XFT, get DPI from Xft.dpi.
Call xsettings_initialize.
* xftfont.c (xftfont_fix_match): New function.
(xftfont_open): Call XftDefaultSubstitute before XftFontMatch.
Call xftfont_fix_match after XftFontMatch.
* xfont.c (xfont_driver): Initialize all members.
* xfns.c (x_default_font_parameter): Try font from Ffont_get_system_font.
Do not get font from x_default_parameter if we got one from
Ffont_get_system_font.
(Fx_select_font): Get the defaut font name from :name of FRAME_FONT (f).
* w32font.c (w32font_driver): Initialize all members.
* termhooks.h (enum event_kind): CONFIG_CHANGED_EVENT is new.
* lisp.h: Declare syms_of_xsettings.
* keyboard.c (kbd_buffer_get_event, make_lispy_event): Handle
CONFIG_CHANGED_EVENT.
* ftfont.c (ftfont_filter_properties): New function.
* frame.c (x_set_font): Remove unused variable lval.
* font.h (struct font_driver): filter_properties is new.
* font.c (font_put_extra): Don't return if val is nil, it means
boolean option is off.
(font_parse_fcname): Collect all extra properties in extra_props
and call filter_properties for all drivers with extra_props and
font as parameter.
(font_open_entity): Do not use cache, it does not pick up new fontconfig
settings like hinting.
(font_load_for_lface): If spec had a name in it, store it in entity.
* emacs.c (main): Call syms_of_xsettings
* config.in: HAVE_GCONF is new.
* Makefile.in (GCONF_CFLAGS, GCONF_LIBS): New variables for HAVE_GCONF.
xsettings.o is new.
* menu-bar.el: Put "Use system font" in Option-menu.
* loadup.el: If feature system-font-setting or font-render-setting is
there, load font-setting.
* Makefile.in (ELCFILES): font-settings.el is new.
* font-setting.el: New file.
* NEWS: Mention dynamic font changes (font-use-system-font).
* configure.in: New option: --with(out)-gconf.
Set HAVE_GCONF if we find gconf.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Tue, 17 Nov 2009 08:21:23 +0000 |
parents | |
children | 5fa329215a93 |
comparison
equal
deleted
inserted
replaced
106084:f03048d6d95a | 106085:cd4cbab8bb21 |
---|---|
1 ;;; xsettings.el --- Support dynamic font changes | |
2 | |
3 ;; Copyright (C) 2009 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Jan Djärv <jan.h.d@swipnet.se> | |
6 ;; Maintainer: FSF | |
7 ;; Keywords: font, system-font | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation, either version 3 of the License, or | |
14 ;; (at your option) any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;; This file provides the lisp part of the GConf and XSetting code in | |
27 ;; xsetting.c. But it is nothing that prevents it from being used by | |
28 ;; other configuration schemes. | |
29 | |
30 ;;; Code: | |
31 | |
32 ;;; Customizable variables | |
33 | |
34 (defun font-setting-set-system-font (symbol value) | |
35 (set-default symbol value) | |
36 (if (symbol-value symbol) | |
37 (let ((f (selected-frame))) | |
38 (if (display-graphic-p f) | |
39 (font-setting-change-default-font f t))))) | |
40 | |
41 (defcustom font-use-system-font nil | |
42 "If non-nil, use the system monospaced font" | |
43 :version "23.2" | |
44 :type 'boolean | |
45 :group 'font-selection | |
46 :set 'font-setting-set-system-font) | |
47 | |
48 (declare-function font-get-system-font "xsettings.c" ()) | |
49 | |
50 (defun font-setting-change-default-font (display-or-frame set-font) | |
51 "Change font and/or font settings for frames on display DISPLAY-OR-FRAME. | |
52 If DISPLAY-OR-FRAME is a frame, the display is the one for that frame. | |
53 | |
54 If set-font is non-nil, change the font for frames. Otherwise re-apply the | |
55 current form for the frame (i.e. hinting or somesuch changed)." | |
56 | |
57 (let ((new-font (and (fboundp 'font-get-system-font) | |
58 (font-get-system-font)))) | |
59 (when new-font | |
60 ;; Be careful here: when set-face-attribute is called for the | |
61 ;; :font attribute, Emacs tries to guess the best matching font | |
62 ;; by examining the other face attributes (Bug#2476). | |
63 | |
64 (clear-font-cache) | |
65 ;; Set for current frames. Only change font for those that have | |
66 ;; the old font now. If they don't have the old font, the user | |
67 ;; probably changed it. | |
68 (dolist (f (frames-on-display-list display-or-frame)) | |
69 (if (display-graphic-p f) | |
70 (let* ((frame-font | |
71 (or (font-get (face-attribute 'default :font f | |
72 'default) :name) | |
73 (frame-parameter f 'font-parameter))) | |
74 (font-to-set | |
75 (if set-font new-font | |
76 ;; else set font again, hinting etc. may have changed. | |
77 frame-font))) | |
78 (progn | |
79 (set-frame-parameter f 'font-parameter font-to-set) | |
80 (set-face-attribute 'default f | |
81 :width 'normal | |
82 :weight 'normal | |
83 :slant 'normal | |
84 :font font-to-set))))) | |
85 | |
86 ;; Set for future frames. | |
87 (set-face-attribute 'default t :font new-font) | |
88 (let ((spec (list (list t (face-attr-construct 'default))))) | |
89 (progn | |
90 (put 'default 'customized-face spec) | |
91 (custom-push-theme 'theme-face 'default 'user 'set spec) | |
92 (put 'default 'face-modified nil)))))) | |
93 | |
94 (defun font-setting-handle-config-changed-event (event) | |
95 "Handle config-changed-event to change fonts on the display in EVENT. | |
96 If `font-use-system-font' is nil, the font is not changed." | |
97 (interactive "e") | |
98 (let ((type (nth 1 event)) ;; font-name or font-render | |
99 (display-name (nth 2 event))) | |
100 (if (or (not (eq type 'font-name)) | |
101 font-use-system-font) | |
102 (font-setting-change-default-font display-name | |
103 (eq type 'font-name))))) | |
104 | |
105 (if (or (featurep 'system-font-setting) (featurep 'font-render-setting)) | |
106 (define-key special-event-map [config-changed-event] | |
107 'font-setting-handle-config-changed-event)) | |
108 | |
109 (provide 'font-setting) |