1 /* Functions for handling font and other changes dynamically.
3 Copyright (C) 2009-2015 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30 #include "xsettings.h"
33 #include "blockinput.h"
34 #include "termhooks.h"
36 #include <X11/Xproto.h>
39 #include <glib-object.h>
44 #include <gconf/gconf-client.h>
48 #include <X11/Xft/Xft.h>
51 static char *current_mono_font
;
52 static char *current_font
;
53 static struct x_display_info
*first_dpyinfo
;
54 static Lisp_Object current_tool_bar_style
;
56 /* Store an config changed event in to the event queue. */
59 store_config_changed_event (Lisp_Object arg
, Lisp_Object display_name
)
61 struct input_event event
;
63 event
.kind
= CONFIG_CHANGED_EVENT
;
64 event
.frame_or_window
= display_name
;
66 kbd_buffer_store_event (&event
);
69 /* Return true if DPYINFO is still valid. */
71 dpyinfo_valid (struct x_display_info
*dpyinfo
)
76 struct x_display_info
*d
;
77 for (d
= x_display_list
; !found
&& d
; d
= d
->next
)
78 found
= d
== dpyinfo
&& d
->display
== dpyinfo
->display
;
83 /* Store a monospace font change event if the monospaced font changed. */
85 #if defined HAVE_XFT && (defined HAVE_GSETTINGS || defined HAVE_GCONF)
87 store_monospaced_changed (const char *newfont
)
89 if (current_mono_font
!= NULL
&& strcmp (newfont
, current_mono_font
) == 0)
90 return; /* No change. */
92 dupstring (¤t_mono_font
, newfont
);
94 if (dpyinfo_valid (first_dpyinfo
) && use_system_font
)
96 store_config_changed_event (Qmonospace_font_name
,
97 XCAR (first_dpyinfo
->name_list_element
));
102 /* Store a font name change event if the font name changed. */
106 store_font_name_changed (const char *newfont
)
108 if (current_font
!= NULL
&& strcmp (newfont
, current_font
) == 0)
109 return; /* No change. */
111 dupstring (¤t_font
, newfont
);
113 if (dpyinfo_valid (first_dpyinfo
))
115 store_config_changed_event (Qfont_name
,
116 XCAR (first_dpyinfo
->name_list_element
));
119 #endif /* HAVE_XFT */
121 /* Map TOOL_BAR_STYLE from a string to its corresponding Lisp value.
122 Return Qnil if TOOL_BAR_STYLE is not known. */
125 map_tool_bar_style (const char *tool_bar_style
)
127 Lisp_Object style
= Qnil
;
130 if (strcmp (tool_bar_style
, "both") == 0)
132 else if (strcmp (tool_bar_style
, "both-horiz") == 0)
134 else if (strcmp (tool_bar_style
, "icons") == 0)
136 else if (strcmp (tool_bar_style
, "text") == 0)
143 /* Store a tool bar style change event if the tool bar style changed. */
146 store_tool_bar_style_changed (const char *newstyle
,
147 struct x_display_info
*dpyinfo
)
149 Lisp_Object style
= map_tool_bar_style (newstyle
);
150 if (EQ (current_tool_bar_style
, style
))
151 return; /* No change. */
153 current_tool_bar_style
= style
;
154 if (dpyinfo_valid (dpyinfo
))
155 store_config_changed_event (Qtool_bar_style
,
156 XCAR (dpyinfo
->name_list_element
));
160 #define XSETTINGS_FONT_NAME "Gtk/FontName"
162 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
168 SEEN_LCDFILTER
= 0x08,
169 SEEN_HINTSTYLE
= 0x10,
178 int rgba
, lcdfilter
, hintstyle
;
189 #ifdef HAVE_GSETTINGS
190 #define GSETTINGS_SCHEMA "org.gnome.desktop.interface"
191 #define GSETTINGS_TOOL_BAR_STYLE "toolbar-style"
194 #define GSETTINGS_MONO_FONT "monospace-font-name"
195 #define GSETTINGS_FONT_NAME "font-name"
199 /* The single GSettings instance, or NULL if not connected to GSettings. */
201 static GSettings
*gsettings_client
;
203 /* Callback called when something changed in GSettings. */
206 something_changed_gsettingsCB (GSettings
*settings
,
212 if (strcmp (key
, GSETTINGS_TOOL_BAR_STYLE
) == 0)
214 val
= g_settings_get_value (settings
, GSETTINGS_TOOL_BAR_STYLE
);
217 g_variant_ref_sink (val
);
218 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
220 const gchar
*newstyle
= g_variant_get_string (val
, NULL
);
221 store_tool_bar_style_changed (newstyle
, first_dpyinfo
);
223 g_variant_unref (val
);
227 else if (strcmp (key
, GSETTINGS_MONO_FONT
) == 0)
229 val
= g_settings_get_value (settings
, GSETTINGS_MONO_FONT
);
232 g_variant_ref_sink (val
);
233 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
235 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
236 store_monospaced_changed (newfont
);
238 g_variant_unref (val
);
241 else if (strcmp (key
, GSETTINGS_FONT_NAME
) == 0)
243 val
= g_settings_get_value (settings
, GSETTINGS_FONT_NAME
);
246 g_variant_ref_sink (val
);
247 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
249 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
250 store_font_name_changed (newfont
);
252 g_variant_unref (val
);
255 #endif /* HAVE_XFT */
258 #endif /* HAVE_GSETTINGS */
261 #define GCONF_TOOL_BAR_STYLE "/desktop/gnome/interface/toolbar_style"
263 #define GCONF_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
264 #define GCONF_FONT_NAME "/desktop/gnome/interface/font_name"
267 /* The single GConf instance, or NULL if not connected to GConf. */
269 static GConfClient
*gconf_client
;
271 /* Callback called when something changed in GConf that we care about. */
274 something_changed_gconfCB (GConfClient
*client
,
279 GConfValue
*v
= gconf_entry_get_value (entry
);
280 const char *key
= gconf_entry_get_key (entry
);
282 if (!v
|| v
->type
!= GCONF_VALUE_STRING
|| ! key
) return;
283 if (strcmp (key
, GCONF_TOOL_BAR_STYLE
) == 0)
285 const char *value
= gconf_value_get_string (v
);
286 store_tool_bar_style_changed (value
, first_dpyinfo
);
289 else if (strcmp (key
, GCONF_MONO_FONT
) == 0)
291 const char *value
= gconf_value_get_string (v
);
292 store_monospaced_changed (value
);
294 else if (strcmp (key
, GCONF_FONT_NAME
) == 0)
296 const char *value
= gconf_value_get_string (v
);
297 store_font_name_changed (value
);
299 #endif /* HAVE_XFT */
302 #endif /* HAVE_GCONF */
306 /* Older fontconfig versions don't have FC_LCD_*. */
308 #define FC_LCD_NONE 0
310 #ifndef FC_LCD_DEFAULT
311 #define FC_LCD_DEFAULT 1
313 #ifndef FC_LCD_FILTER
314 #define FC_LCD_FILTER "lcdfilter"
317 #endif /* HAVE_XFT */
319 /* Find the window that contains the XSETTINGS property values. */
322 get_prop_window (struct x_display_info
*dpyinfo
)
324 Display
*dpy
= dpyinfo
->display
;
327 dpyinfo
->xsettings_window
= XGetSelectionOwner (dpy
,
328 dpyinfo
->Xatom_xsettings_sel
);
329 if (dpyinfo
->xsettings_window
!= None
)
330 /* Select events so we can detect if window is deleted or if settings
332 XSelectInput (dpy
, dpyinfo
->xsettings_window
,
333 PropertyChangeMask
|StructureNotifyMask
);
338 #define PAD(nr) (((nr) + 3) & ~3)
340 /* Parse xsettings and extract those that deal with Xft.
341 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
342 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
344 Layout of prop. First is a header:
347 ------------------------------------
353 Then N_SETTINGS records, with header:
356 ------------------------------------
357 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
359 2 CARD16 n == name-length
361 p unused, p=pad_to_even_4(n)
362 4 CARD32 last-change-serial
364 and then the value, For string:
367 ------------------------------------
368 4 CARD32 n = value-length
370 p unused, p=pad_to_even_4(n)
375 ------------------------------------
381 ------------------------------------
387 Returns non-zero if some Xft settings was seen, zero otherwise.
391 parse_settings (unsigned char *prop
,
393 struct xsettings
*settings
)
395 Lisp_Object byteorder
= Fbyteorder ();
396 int my_bo
= XFASTINT (byteorder
) == 'B' ? MSBFirst
: LSBFirst
;
397 int that_bo
= prop
[0];
399 int bytes_parsed
= 0;
400 int settings_seen
= 0;
403 /* First 4 bytes is a serial number, skip that. */
405 if (bytes
< 12) return settings_seen
;
406 memcpy (&n_settings
, prop
+8, 4);
407 if (my_bo
!= that_bo
) n_settings
= bswap_32 (n_settings
);
410 memset (settings
, 0, sizeof (*settings
));
412 while (bytes_parsed
+4 < bytes
&& settings_seen
< 7
415 int type
= prop
[bytes_parsed
++];
417 CARD32 vlen
, ival
= 0;
418 char name
[128]; /* The names we are looking for are not this long. */
419 char sval
[128]; /* The values we are looking for are not this long. */
425 ++bytes_parsed
; /* Padding */
427 memcpy (&nlen
, prop
+bytes_parsed
, 2);
429 if (my_bo
!= that_bo
) nlen
= bswap_16 (nlen
);
430 if (bytes_parsed
+ nlen
> bytes
) return settings_seen
;
431 to_cpy
= min (nlen
, sizeof name
- 1);
432 memcpy (name
, prop
+bytes_parsed
, to_cpy
);
435 bytes_parsed
+= nlen
;
436 bytes_parsed
= PAD (bytes_parsed
);
438 bytes_parsed
+= 4; /* Skip serial for this value */
439 if (bytes_parsed
> bytes
) return settings_seen
;
441 want_this
= strcmp (XSETTINGS_TOOL_BAR_STYLE
, name
) == 0;
443 if ((nlen
> 6 && memcmp (name
, "Xft/", 4) == 0)
444 || strcmp (XSETTINGS_FONT_NAME
, name
) == 0)
450 case 0: /* Integer */
451 if (bytes_parsed
+ 4 > bytes
) return settings_seen
;
454 memcpy (&ival
, prop
+bytes_parsed
, 4);
455 if (my_bo
!= that_bo
) ival
= bswap_32 (ival
);
461 if (bytes_parsed
+ 4 > bytes
) return settings_seen
;
462 memcpy (&vlen
, prop
+bytes_parsed
, 4);
464 if (my_bo
!= that_bo
) vlen
= bswap_32 (vlen
);
467 to_cpy
= min (vlen
, sizeof sval
- 1);
468 memcpy (sval
, prop
+bytes_parsed
, to_cpy
);
471 bytes_parsed
+= vlen
;
472 bytes_parsed
= PAD (bytes_parsed
);
475 case 2: /* RGB value */
476 /* No need to parse this */
477 if (bytes_parsed
+ 8 > bytes
) return settings_seen
;
478 bytes_parsed
+= 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
481 default: /* Parse Error */
482 return settings_seen
;
487 if (strcmp (name
, XSETTINGS_TOOL_BAR_STYLE
) == 0)
489 dupstring (&settings
->tb_style
, sval
);
490 settings
->seen
|= SEEN_TB_STYLE
;
493 else if (strcmp (name
, XSETTINGS_FONT_NAME
) == 0)
495 dupstring (&settings
->font
, sval
);
496 settings
->seen
|= SEEN_FONT
;
498 else if (strcmp (name
, "Xft/Antialias") == 0)
500 settings
->seen
|= SEEN_AA
;
501 settings
->aa
= ival
!= 0;
503 else if (strcmp (name
, "Xft/Hinting") == 0)
505 settings
->seen
|= SEEN_HINTING
;
506 settings
->hinting
= ival
!= 0;
508 # ifdef FC_HINT_STYLE
509 else if (strcmp (name
, "Xft/HintStyle") == 0)
511 settings
->seen
|= SEEN_HINTSTYLE
;
512 if (strcmp (sval
, "hintnone") == 0)
513 settings
->hintstyle
= FC_HINT_NONE
;
514 else if (strcmp (sval
, "hintslight") == 0)
515 settings
->hintstyle
= FC_HINT_SLIGHT
;
516 else if (strcmp (sval
, "hintmedium") == 0)
517 settings
->hintstyle
= FC_HINT_MEDIUM
;
518 else if (strcmp (sval
, "hintfull") == 0)
519 settings
->hintstyle
= FC_HINT_FULL
;
521 settings
->seen
&= ~SEEN_HINTSTYLE
;
524 else if (strcmp (name
, "Xft/RGBA") == 0)
526 settings
->seen
|= SEEN_RGBA
;
527 if (strcmp (sval
, "none") == 0)
528 settings
->rgba
= FC_RGBA_NONE
;
529 else if (strcmp (sval
, "rgb") == 0)
530 settings
->rgba
= FC_RGBA_RGB
;
531 else if (strcmp (sval
, "bgr") == 0)
532 settings
->rgba
= FC_RGBA_BGR
;
533 else if (strcmp (sval
, "vrgb") == 0)
534 settings
->rgba
= FC_RGBA_VRGB
;
535 else if (strcmp (sval
, "vbgr") == 0)
536 settings
->rgba
= FC_RGBA_VBGR
;
538 settings
->seen
&= ~SEEN_RGBA
;
540 else if (strcmp (name
, "Xft/DPI") == 0 && ival
!= (CARD32
) -1)
542 settings
->seen
|= SEEN_DPI
;
543 settings
->dpi
= ival
/ 1024.0;
545 else if (strcmp (name
, "Xft/lcdfilter") == 0)
547 settings
->seen
|= SEEN_LCDFILTER
;
548 if (strcmp (sval
, "none") == 0)
549 settings
->lcdfilter
= FC_LCD_NONE
;
550 else if (strcmp (sval
, "lcddefault") == 0)
551 settings
->lcdfilter
= FC_LCD_DEFAULT
;
553 settings
->seen
&= ~SEEN_LCDFILTER
;
555 #endif /* HAVE_XFT */
558 settings_seen
+= want_this
;
562 return settings_seen
;
565 /* Read settings from the XSettings property window on display for DPYINFO.
566 Store settings read in SETTINGS.
567 Return true iff successful. */
570 read_settings (struct x_display_info
*dpyinfo
, struct xsettings
*settings
)
574 unsigned long nitems
, bytes_after
;
575 unsigned char *prop
= NULL
;
576 Display
*dpy
= dpyinfo
->display
;
578 bool got_settings
= false;
580 x_catch_errors (dpy
);
581 rc
= XGetWindowProperty (dpy
,
582 dpyinfo
->xsettings_window
,
583 dpyinfo
->Xatom_xsettings_prop
,
584 0, LONG_MAX
, False
, AnyPropertyType
,
585 &act_type
, &act_form
, &nitems
, &bytes_after
,
588 if (rc
== Success
&& prop
!= NULL
&& act_form
== 8 && nitems
> 0
589 && act_type
== dpyinfo
->Xatom_xsettings_prop
)
590 got_settings
= parse_settings (prop
, nitems
, settings
) != 0;
599 /* Apply Xft settings in SETTINGS to the Xft library.
600 Store a Lisp event that Xft settings changed. */
603 apply_xft_settings (struct x_display_info
*dpyinfo
,
604 struct xsettings
*settings
)
608 struct xsettings oldsettings
;
609 bool changed
= false;
611 memset (&oldsettings
, 0, sizeof (oldsettings
));
612 pat
= FcPatternCreate ();
613 XftDefaultSubstitute (dpyinfo
->display
,
614 XScreenNumberOfScreen (dpyinfo
->screen
),
616 FcPatternGetBool (pat
, FC_ANTIALIAS
, 0, &oldsettings
.aa
);
617 FcPatternGetBool (pat
, FC_HINTING
, 0, &oldsettings
.hinting
);
619 FcPatternGetInteger (pat
, FC_HINT_STYLE
, 0, &oldsettings
.hintstyle
);
621 FcPatternGetInteger (pat
, FC_LCD_FILTER
, 0, &oldsettings
.lcdfilter
);
622 FcPatternGetInteger (pat
, FC_RGBA
, 0, &oldsettings
.rgba
);
623 FcPatternGetDouble (pat
, FC_DPI
, 0, &oldsettings
.dpi
);
625 if ((settings
->seen
& SEEN_AA
) != 0 && oldsettings
.aa
!= settings
->aa
)
627 FcPatternDel (pat
, FC_ANTIALIAS
);
628 FcPatternAddBool (pat
, FC_ANTIALIAS
, settings
->aa
);
630 oldsettings
.aa
= settings
->aa
;
633 if ((settings
->seen
& SEEN_HINTING
) != 0
634 && oldsettings
.hinting
!= settings
->hinting
)
636 FcPatternDel (pat
, FC_HINTING
);
637 FcPatternAddBool (pat
, FC_HINTING
, settings
->hinting
);
639 oldsettings
.hinting
= settings
->hinting
;
641 if ((settings
->seen
& SEEN_RGBA
) != 0 && oldsettings
.rgba
!= settings
->rgba
)
643 FcPatternDel (pat
, FC_RGBA
);
644 FcPatternAddInteger (pat
, FC_RGBA
, settings
->rgba
);
645 oldsettings
.rgba
= settings
->rgba
;
649 /* Older fontconfig versions don't have FC_LCD_FILTER. */
650 if ((settings
->seen
& SEEN_LCDFILTER
) != 0
651 && oldsettings
.lcdfilter
!= settings
->lcdfilter
)
653 FcPatternDel (pat
, FC_LCD_FILTER
);
654 FcPatternAddInteger (pat
, FC_LCD_FILTER
, settings
->lcdfilter
);
656 oldsettings
.lcdfilter
= settings
->lcdfilter
;
660 if ((settings
->seen
& SEEN_HINTSTYLE
) != 0
661 && oldsettings
.hintstyle
!= settings
->hintstyle
)
663 FcPatternDel (pat
, FC_HINT_STYLE
);
664 FcPatternAddInteger (pat
, FC_HINT_STYLE
, settings
->hintstyle
);
666 oldsettings
.hintstyle
= settings
->hintstyle
;
670 if ((settings
->seen
& SEEN_DPI
) != 0 && oldsettings
.dpi
!= settings
->dpi
671 && settings
->dpi
> 0)
673 FcPatternDel (pat
, FC_DPI
);
674 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
676 oldsettings
.dpi
= settings
->dpi
;
678 /* Changing the DPI on this display affects all frames on it.
679 Check FRAME_RES_X and FRAME_RES_Y in frame.h to see how. */
680 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
685 static char const format
[] =
686 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
687 "Hintstyle: %d, DPI: %f";
691 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
693 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
695 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
698 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
700 XftDefaultSet (dpyinfo
->display
, pat
);
701 store_config_changed_event (Qfont_render
,
702 XCAR (dpyinfo
->name_list_element
));
704 = make_formatted_string (buf
, format
,
705 oldsettings
.aa
, oldsettings
.hinting
,
706 oldsettings
.rgba
, oldsettings
.lcdfilter
,
707 oldsettings
.hintstyle
, oldsettings
.dpi
);
711 FcPatternDestroy (pat
);
712 #endif /* HAVE_XFT */
715 /* Read XSettings from the display for DPYINFO.
716 If SEND_EVENT_P store a Lisp event settings that changed. */
719 read_and_apply_settings (struct x_display_info
*dpyinfo
, bool send_event_p
)
721 struct xsettings settings
;
723 if (!read_settings (dpyinfo
, &settings
))
726 apply_xft_settings (dpyinfo
, &settings
);
727 if (settings
.seen
& SEEN_TB_STYLE
)
730 store_tool_bar_style_changed (settings
.tb_style
, dpyinfo
);
732 current_tool_bar_style
= map_tool_bar_style (settings
.tb_style
);
733 xfree (settings
.tb_style
);
736 if (settings
.seen
& SEEN_FONT
)
739 store_font_name_changed (settings
.font
);
741 dupstring (¤t_font
, settings
.font
);
742 xfree (settings
.font
);
747 /* Check if EVENT for the display in DPYINFO is XSettings related. */
750 xft_settings_event (struct x_display_info
*dpyinfo
, const XEvent
*event
)
752 bool check_window_p
= false, apply_settings_p
= false;
757 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
758 check_window_p
= true;
762 if (event
->xclient
.message_type
== dpyinfo
->Xatom_xsettings_mgr
763 && event
->xclient
.data
.l
[1] == dpyinfo
->Xatom_xsettings_sel
764 && event
->xclient
.window
== dpyinfo
->root_window
)
765 check_window_p
= true;
769 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
770 && event
->xproperty
.state
== PropertyNewValue
771 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
772 apply_settings_p
= true;
779 dpyinfo
->xsettings_window
= None
;
780 get_prop_window (dpyinfo
);
781 if (dpyinfo
->xsettings_window
!= None
)
782 apply_settings_p
= true;
785 if (apply_settings_p
)
786 read_and_apply_settings (dpyinfo
, true);
789 /* Initialize GSettings and read startup values. */
792 init_gsettings (void)
794 #ifdef HAVE_GSETTINGS
796 bool schema_found
= false;
798 #if ! GLIB_CHECK_VERSION (2, 36, 0)
802 #if GLIB_CHECK_VERSION (2, 32, 0)
804 GSettingsSchema
*sc
= g_settings_schema_source_lookup
805 (g_settings_schema_source_get_default (),
808 schema_found
= sc
!= NULL
;
809 if (sc
) g_settings_schema_unref (sc
);
813 const gchar
*const *schemas
= g_settings_list_schemas ();
814 if (schemas
== NULL
) return;
815 while (! schema_found
&& *schemas
!= NULL
)
816 schema_found
= strcmp (*schemas
++, GSETTINGS_SCHEMA
) == 0;
819 if (!schema_found
) return;
821 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
822 if (!gsettings_client
) return;
823 g_object_ref_sink (G_OBJECT (gsettings_client
));
824 g_signal_connect (G_OBJECT (gsettings_client
), "changed",
825 G_CALLBACK (something_changed_gsettingsCB
), NULL
);
827 val
= g_settings_get_value (gsettings_client
, GSETTINGS_TOOL_BAR_STYLE
);
830 g_variant_ref_sink (val
);
831 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
832 current_tool_bar_style
833 = map_tool_bar_style (g_variant_get_string (val
, NULL
));
834 g_variant_unref (val
);
838 val
= g_settings_get_value (gsettings_client
, GSETTINGS_MONO_FONT
);
841 g_variant_ref_sink (val
);
842 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
843 dupstring (¤t_mono_font
, g_variant_get_string (val
, NULL
));
844 g_variant_unref (val
);
847 val
= g_settings_get_value (gsettings_client
, GSETTINGS_FONT_NAME
);
850 g_variant_ref_sink (val
);
851 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
852 dupstring (¤t_font
, g_variant_get_string (val
, NULL
));
853 g_variant_unref (val
);
855 #endif /* HAVE_XFT */
857 #endif /* HAVE_GSETTINGS */
860 /* Init GConf and read startup values. */
865 #if defined (HAVE_GCONF)
868 #if ! GLIB_CHECK_VERSION (2, 36, 0)
872 gconf_client
= gconf_client_get_default ();
873 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
874 gconf_client_add_dir (gconf_client
,
875 GCONF_TOOL_BAR_STYLE
,
876 GCONF_CLIENT_PRELOAD_ONELEVEL
,
878 gconf_client_notify_add (gconf_client
,
879 GCONF_TOOL_BAR_STYLE
,
880 something_changed_gconfCB
,
883 s
= gconf_client_get_string (gconf_client
, GCONF_TOOL_BAR_STYLE
, NULL
);
886 current_tool_bar_style
= map_tool_bar_style (s
);
891 s
= gconf_client_get_string (gconf_client
, GCONF_MONO_FONT
, NULL
);
894 dupstring (¤t_mono_font
, s
);
897 s
= gconf_client_get_string (gconf_client
, GCONF_FONT_NAME
, NULL
);
900 dupstring (¤t_font
, s
);
903 gconf_client_add_dir (gconf_client
,
905 GCONF_CLIENT_PRELOAD_ONELEVEL
,
907 gconf_client_notify_add (gconf_client
,
909 something_changed_gconfCB
,
911 gconf_client_add_dir (gconf_client
,
913 GCONF_CLIENT_PRELOAD_ONELEVEL
,
915 gconf_client_notify_add (gconf_client
,
917 something_changed_gconfCB
,
919 #endif /* HAVE_XFT */
920 #endif /* HAVE_GCONF */
923 /* Init Xsettings and read startup values. */
926 init_xsettings (struct x_display_info
*dpyinfo
)
928 Display
*dpy
= dpyinfo
->display
;
932 /* Select events so we can detect client messages sent when selection
934 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
936 get_prop_window (dpyinfo
);
937 if (dpyinfo
->xsettings_window
!= None
)
938 read_and_apply_settings (dpyinfo
, false);
944 xsettings_initialize (struct x_display_info
*dpyinfo
)
946 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
948 init_xsettings (dpyinfo
);
952 /* Return the system monospaced font.
953 May be NULL if not known. */
956 xsettings_get_system_font (void)
958 return current_mono_font
;
962 /* Return the system font.
963 May be NULL if not known. */
966 xsettings_get_system_normal_font (void)
972 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
973 Sfont_get_system_normal_font
,
975 doc
: /* Get the system default application font. */)
978 return current_font
? build_string (current_font
) : Qnil
;
981 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
983 doc
: /* Get the system default fixed width font. */)
986 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
989 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
990 Stool_bar_get_system_style
, 0, 0, 0,
991 doc
: /* Get the system tool bar style.
992 If no system tool bar style is known, return `tool-bar-style' if set to a
993 known style. Otherwise return image. */)
996 if (EQ (Vtool_bar_style
, Qimage
)
997 || EQ (Vtool_bar_style
, Qtext
)
998 || EQ (Vtool_bar_style
, Qboth
)
999 || EQ (Vtool_bar_style
, Qboth_horiz
)
1000 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
1001 return Vtool_bar_style
;
1002 if (!NILP (current_tool_bar_style
))
1003 return current_tool_bar_style
;
1008 syms_of_xsettings (void)
1010 current_mono_font
= NULL
;
1011 current_font
= NULL
;
1012 first_dpyinfo
= NULL
;
1013 #ifdef HAVE_GSETTINGS
1014 gsettings_client
= NULL
;
1017 gconf_client
= NULL
;
1020 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
1021 DEFSYM (Qfont_name
, "font-name");
1022 DEFSYM (Qfont_render
, "font-render");
1023 defsubr (&Sfont_get_system_font
);
1024 defsubr (&Sfont_get_system_normal_font
);
1026 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
1027 doc
: /* Non-nil means to apply the system defined font dynamically.
1028 When this is non-nil and the system defined fixed width font changes, we
1029 update frames dynamically.
1030 If this variable is nil, Emacs ignores system font changes. */);
1031 use_system_font
= false;
1033 DEFVAR_LISP ("xft-settings", Vxft_settings
,
1034 doc
: /* Font settings applied to Xft. */);
1035 Vxft_settings
= empty_unibyte_string
;
1038 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
1039 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
1040 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
1044 current_tool_bar_style
= Qnil
;
1045 DEFSYM (Qtool_bar_style
, "tool-bar-style");
1046 defsubr (&Stool_bar_get_system_style
);
1048 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);