1 /* Functions for handling font and other changes dynamically.
3 Copyright (C) 2009-2014 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 Qmonospace_font_name
, Qfont_name
, Qfont_render
,
56 static Lisp_Object current_tool_bar_style
;
58 /* Store an config changed event in to the event queue. */
61 store_config_changed_event (Lisp_Object arg
, Lisp_Object display_name
)
63 struct input_event event
;
65 event
.kind
= CONFIG_CHANGED_EVENT
;
66 event
.frame_or_window
= display_name
;
68 kbd_buffer_store_event (&event
);
71 /* Return non-zero if DPYINFO is still valid. */
73 dpyinfo_valid (struct x_display_info
*dpyinfo
)
78 struct x_display_info
*d
;
79 for (d
= x_display_list
; !found
&& d
; d
= d
->next
)
80 found
= d
== dpyinfo
&& d
->display
== dpyinfo
->display
;
85 /* Store a monospace font change event if the monospaced font changed. */
87 #if defined HAVE_XFT && (defined HAVE_GSETTINGS || defined HAVE_GCONF)
89 store_monospaced_changed (const char *newfont
)
91 if (current_mono_font
!= NULL
&& strcmp (newfont
, current_mono_font
) == 0)
92 return; /* No change. */
94 dupstring (¤t_mono_font
, newfont
);
96 if (dpyinfo_valid (first_dpyinfo
) && use_system_font
)
98 store_config_changed_event (Qmonospace_font_name
,
99 XCAR (first_dpyinfo
->name_list_element
));
104 /* Store a font name change event if the font name changed. */
108 store_font_name_changed (const char *newfont
)
110 if (current_font
!= NULL
&& strcmp (newfont
, current_font
) == 0)
111 return; /* No change. */
113 dupstring (¤t_font
, newfont
);
115 if (dpyinfo_valid (first_dpyinfo
))
117 store_config_changed_event (Qfont_name
,
118 XCAR (first_dpyinfo
->name_list_element
));
121 #endif /* HAVE_XFT */
123 /* Map TOOL_BAR_STYLE from a string to its corresponding Lisp value.
124 Return Qnil if TOOL_BAR_STYLE is not known. */
127 map_tool_bar_style (const char *tool_bar_style
)
129 Lisp_Object style
= Qnil
;
132 if (strcmp (tool_bar_style
, "both") == 0)
134 else if (strcmp (tool_bar_style
, "both-horiz") == 0)
136 else if (strcmp (tool_bar_style
, "icons") == 0)
138 else if (strcmp (tool_bar_style
, "text") == 0)
145 /* Store a tool bar style change event if the tool bar style changed. */
148 store_tool_bar_style_changed (const char *newstyle
,
149 struct x_display_info
*dpyinfo
)
151 Lisp_Object style
= map_tool_bar_style (newstyle
);
152 if (EQ (current_tool_bar_style
, style
))
153 return; /* No change. */
155 current_tool_bar_style
= style
;
156 if (dpyinfo_valid (dpyinfo
))
157 store_config_changed_event (Qtool_bar_style
,
158 XCAR (dpyinfo
->name_list_element
));
162 #define XSETTINGS_FONT_NAME "Gtk/FontName"
164 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
170 SEEN_LCDFILTER
= 0x08,
171 SEEN_HINTSTYLE
= 0x10,
180 int rgba
, lcdfilter
, hintstyle
;
191 #ifdef HAVE_GSETTINGS
192 #define GSETTINGS_SCHEMA "org.gnome.desktop.interface"
193 #define GSETTINGS_TOOL_BAR_STYLE "toolbar-style"
196 #define GSETTINGS_MONO_FONT "monospace-font-name"
197 #define GSETTINGS_FONT_NAME "font-name"
201 /* The single GSettings instance, or NULL if not connected to GSettings. */
203 static GSettings
*gsettings_client
;
205 /* Callback called when something changed in GSettings. */
208 something_changed_gsettingsCB (GSettings
*settings
,
214 if (strcmp (key
, GSETTINGS_TOOL_BAR_STYLE
) == 0)
216 val
= g_settings_get_value (settings
, GSETTINGS_TOOL_BAR_STYLE
);
219 g_variant_ref_sink (val
);
220 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
222 const gchar
*newstyle
= g_variant_get_string (val
, NULL
);
223 store_tool_bar_style_changed (newstyle
, first_dpyinfo
);
225 g_variant_unref (val
);
229 else if (strcmp (key
, GSETTINGS_MONO_FONT
) == 0)
231 val
= g_settings_get_value (settings
, GSETTINGS_MONO_FONT
);
234 g_variant_ref_sink (val
);
235 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
237 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
238 store_monospaced_changed (newfont
);
240 g_variant_unref (val
);
243 else if (strcmp (key
, GSETTINGS_FONT_NAME
) == 0)
245 val
= g_settings_get_value (settings
, GSETTINGS_FONT_NAME
);
248 g_variant_ref_sink (val
);
249 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
251 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
252 store_font_name_changed (newfont
);
254 g_variant_unref (val
);
257 #endif /* HAVE_XFT */
260 #endif /* HAVE_GSETTINGS */
263 #define GCONF_TOOL_BAR_STYLE "/desktop/gnome/interface/toolbar_style"
265 #define GCONF_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
266 #define GCONF_FONT_NAME "/desktop/gnome/interface/font_name"
269 /* The single GConf instance, or NULL if not connected to GConf. */
271 static GConfClient
*gconf_client
;
273 /* Callback called when something changed in GConf that we care about. */
276 something_changed_gconfCB (GConfClient
*client
,
281 GConfValue
*v
= gconf_entry_get_value (entry
);
282 const char *key
= gconf_entry_get_key (entry
);
284 if (!v
|| v
->type
!= GCONF_VALUE_STRING
|| ! key
) return;
285 if (strcmp (key
, GCONF_TOOL_BAR_STYLE
) == 0)
287 const char *value
= gconf_value_get_string (v
);
288 store_tool_bar_style_changed (value
, first_dpyinfo
);
291 else if (strcmp (key
, GCONF_MONO_FONT
) == 0)
293 const char *value
= gconf_value_get_string (v
);
294 store_monospaced_changed (value
);
296 else if (strcmp (key
, GCONF_FONT_NAME
) == 0)
298 const char *value
= gconf_value_get_string (v
);
299 store_font_name_changed (value
);
301 #endif /* HAVE_XFT */
304 #endif /* HAVE_GCONF */
308 /* Older fontconfig versions don't have FC_LCD_*. */
310 #define FC_LCD_NONE 0
312 #ifndef FC_LCD_DEFAULT
313 #define FC_LCD_DEFAULT 1
315 #ifndef FC_LCD_FILTER
316 #define FC_LCD_FILTER "lcdfilter"
319 #endif /* HAVE_XFT */
321 /* Find the window that contains the XSETTINGS property values. */
324 get_prop_window (struct x_display_info
*dpyinfo
)
326 Display
*dpy
= dpyinfo
->display
;
329 dpyinfo
->xsettings_window
= XGetSelectionOwner (dpy
,
330 dpyinfo
->Xatom_xsettings_sel
);
331 if (dpyinfo
->xsettings_window
!= None
)
332 /* Select events so we can detect if window is deleted or if settings
334 XSelectInput (dpy
, dpyinfo
->xsettings_window
,
335 PropertyChangeMask
|StructureNotifyMask
);
340 #define PAD(nr) (((nr) + 3) & ~3)
342 /* Parse xsettings and extract those that deal with Xft.
343 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
344 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
346 Layout of prop. First is a header:
349 ------------------------------------
355 Then N_SETTINGS records, with header:
358 ------------------------------------
359 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
361 2 CARD16 n == name-length
363 p unused, p=pad_to_even_4(n)
364 4 CARD32 last-change-serial
366 and then the value, For string:
369 ------------------------------------
370 4 CARD32 n = value-length
372 p unused, p=pad_to_even_4(n)
377 ------------------------------------
383 ------------------------------------
389 Returns non-zero if some Xft settings was seen, zero otherwise.
393 parse_settings (unsigned char *prop
,
395 struct xsettings
*settings
)
397 Lisp_Object byteorder
= Fbyteorder ();
398 int my_bo
= XFASTINT (byteorder
) == 'B' ? MSBFirst
: LSBFirst
;
399 int that_bo
= prop
[0];
401 int bytes_parsed
= 0;
402 int settings_seen
= 0;
405 /* First 4 bytes is a serial number, skip that. */
407 if (bytes
< 12) return BadLength
;
408 memcpy (&n_settings
, prop
+8, 4);
409 if (my_bo
!= that_bo
) n_settings
= bswap_32 (n_settings
);
412 memset (settings
, 0, sizeof (*settings
));
414 while (bytes_parsed
+4 < bytes
&& settings_seen
< 7
417 int type
= prop
[bytes_parsed
++];
419 CARD32 vlen
, ival
= 0;
420 char name
[128]; /* The names we are looking for are not this long. */
421 char sval
[128]; /* The values we are looking for are not this long. */
427 ++bytes_parsed
; /* Padding */
429 memcpy (&nlen
, prop
+bytes_parsed
, 2);
431 if (my_bo
!= that_bo
) nlen
= bswap_16 (nlen
);
432 if (bytes_parsed
+nlen
> bytes
) return BadLength
;
433 to_cpy
= nlen
> 127 ? 127 : nlen
;
434 memcpy (name
, prop
+bytes_parsed
, to_cpy
);
437 bytes_parsed
+= nlen
;
438 bytes_parsed
= PAD (bytes_parsed
);
440 bytes_parsed
+= 4; /* Skip serial for this value */
441 if (bytes_parsed
> bytes
) return BadLength
;
445 (nlen
> 6 && strncmp (name
, "Xft/", 4) == 0)
446 || strcmp (XSETTINGS_FONT_NAME
, name
) == 0
449 strcmp (XSETTINGS_TOOL_BAR_STYLE
, name
) == 0;
453 case 0: /* Integer */
454 if (bytes_parsed
+4 > bytes
) return BadLength
;
457 memcpy (&ival
, prop
+bytes_parsed
, 4);
458 if (my_bo
!= that_bo
) ival
= bswap_32 (ival
);
464 if (bytes_parsed
+4 > bytes
) return BadLength
;
465 memcpy (&vlen
, prop
+bytes_parsed
, 4);
467 if (my_bo
!= that_bo
) vlen
= bswap_32 (vlen
);
470 to_cpy
= vlen
> 127 ? 127 : vlen
;
471 memcpy (sval
, prop
+bytes_parsed
, to_cpy
);
474 bytes_parsed
+= vlen
;
475 bytes_parsed
= PAD (bytes_parsed
);
478 case 2: /* RGB value */
479 /* No need to parse this */
480 if (bytes_parsed
+8 > bytes
) return BadLength
;
481 bytes_parsed
+= 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
484 default: /* Parse Error */
491 if (strcmp (name
, XSETTINGS_TOOL_BAR_STYLE
) == 0)
493 dupstring (&settings
->tb_style
, sval
);
494 settings
->seen
|= SEEN_TB_STYLE
;
497 else if (strcmp (name
, XSETTINGS_FONT_NAME
) == 0)
499 dupstring (&settings
->font
, sval
);
500 settings
->seen
|= SEEN_FONT
;
502 else if (strcmp (name
, "Xft/Antialias") == 0)
504 settings
->seen
|= SEEN_AA
;
505 settings
->aa
= ival
!= 0;
507 else if (strcmp (name
, "Xft/Hinting") == 0)
509 settings
->seen
|= SEEN_HINTING
;
510 settings
->hinting
= ival
!= 0;
512 # ifdef FC_HINT_STYLE
513 else if (strcmp (name
, "Xft/HintStyle") == 0)
515 settings
->seen
|= SEEN_HINTSTYLE
;
516 if (strcmp (sval
, "hintnone") == 0)
517 settings
->hintstyle
= FC_HINT_NONE
;
518 else if (strcmp (sval
, "hintslight") == 0)
519 settings
->hintstyle
= FC_HINT_SLIGHT
;
520 else if (strcmp (sval
, "hintmedium") == 0)
521 settings
->hintstyle
= FC_HINT_MEDIUM
;
522 else if (strcmp (sval
, "hintfull") == 0)
523 settings
->hintstyle
= FC_HINT_FULL
;
525 settings
->seen
&= ~SEEN_HINTSTYLE
;
528 else if (strcmp (name
, "Xft/RGBA") == 0)
530 settings
->seen
|= SEEN_RGBA
;
531 if (strcmp (sval
, "none") == 0)
532 settings
->rgba
= FC_RGBA_NONE
;
533 else if (strcmp (sval
, "rgb") == 0)
534 settings
->rgba
= FC_RGBA_RGB
;
535 else if (strcmp (sval
, "bgr") == 0)
536 settings
->rgba
= FC_RGBA_BGR
;
537 else if (strcmp (sval
, "vrgb") == 0)
538 settings
->rgba
= FC_RGBA_VRGB
;
539 else if (strcmp (sval
, "vbgr") == 0)
540 settings
->rgba
= FC_RGBA_VBGR
;
542 settings
->seen
&= ~SEEN_RGBA
;
544 else if (strcmp (name
, "Xft/DPI") == 0)
546 settings
->seen
|= SEEN_DPI
;
547 settings
->dpi
= (double)ival
/1024.0;
549 else if (strcmp (name
, "Xft/lcdfilter") == 0)
551 settings
->seen
|= SEEN_LCDFILTER
;
552 if (strcmp (sval
, "none") == 0)
553 settings
->lcdfilter
= FC_LCD_NONE
;
554 else if (strcmp (sval
, "lcddefault") == 0)
555 settings
->lcdfilter
= FC_LCD_DEFAULT
;
557 settings
->seen
&= ~SEEN_LCDFILTER
;
559 #endif /* HAVE_XFT */
563 return settings_seen
;
566 /* Read settings from the XSettings property window on display for DPYINFO.
567 Store settings read in SETTINGS.
568 Return non-zero if successful, zero if not. */
571 read_settings (struct x_display_info
*dpyinfo
, struct xsettings
*settings
)
575 unsigned long nitems
, bytes_after
;
576 unsigned char *prop
= NULL
;
577 Display
*dpy
= dpyinfo
->display
;
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 rc
= parse_settings (prop
, nitems
, settings
);
599 /* Apply Xft settings in SETTINGS to the Xft library.
600 If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */
603 apply_xft_settings (struct x_display_info
*dpyinfo
,
605 struct xsettings
*settings
)
609 struct xsettings oldsettings
;
612 memset (&oldsettings
, 0, sizeof (oldsettings
));
613 pat
= FcPatternCreate ();
614 XftDefaultSubstitute (dpyinfo
->display
,
615 XScreenNumberOfScreen (dpyinfo
->screen
),
617 FcPatternGetBool (pat
, FC_ANTIALIAS
, 0, &oldsettings
.aa
);
618 FcPatternGetBool (pat
, FC_HINTING
, 0, &oldsettings
.hinting
);
620 FcPatternGetInteger (pat
, FC_HINT_STYLE
, 0, &oldsettings
.hintstyle
);
622 FcPatternGetInteger (pat
, FC_LCD_FILTER
, 0, &oldsettings
.lcdfilter
);
623 FcPatternGetInteger (pat
, FC_RGBA
, 0, &oldsettings
.rgba
);
624 FcPatternGetDouble (pat
, FC_DPI
, 0, &oldsettings
.dpi
);
626 if ((settings
->seen
& SEEN_AA
) != 0 && oldsettings
.aa
!= settings
->aa
)
628 FcPatternDel (pat
, FC_ANTIALIAS
);
629 FcPatternAddBool (pat
, FC_ANTIALIAS
, settings
->aa
);
631 oldsettings
.aa
= settings
->aa
;
634 if ((settings
->seen
& SEEN_HINTING
) != 0
635 && oldsettings
.hinting
!= settings
->hinting
)
637 FcPatternDel (pat
, FC_HINTING
);
638 FcPatternAddBool (pat
, FC_HINTING
, settings
->hinting
);
640 oldsettings
.hinting
= settings
->hinting
;
642 if ((settings
->seen
& SEEN_RGBA
) != 0 && oldsettings
.rgba
!= settings
->rgba
)
644 FcPatternDel (pat
, FC_RGBA
);
645 FcPatternAddInteger (pat
, FC_RGBA
, settings
->rgba
);
646 oldsettings
.rgba
= settings
->rgba
;
650 /* Older fontconfig versions don't have FC_LCD_FILTER. */
651 if ((settings
->seen
& SEEN_LCDFILTER
) != 0
652 && oldsettings
.lcdfilter
!= settings
->lcdfilter
)
654 FcPatternDel (pat
, FC_LCD_FILTER
);
655 FcPatternAddInteger (pat
, FC_LCD_FILTER
, settings
->lcdfilter
);
657 oldsettings
.lcdfilter
= settings
->lcdfilter
;
661 if ((settings
->seen
& SEEN_HINTSTYLE
) != 0
662 && oldsettings
.hintstyle
!= settings
->hintstyle
)
664 FcPatternDel (pat
, FC_HINT_STYLE
);
665 FcPatternAddInteger (pat
, FC_HINT_STYLE
, settings
->hintstyle
);
667 oldsettings
.hintstyle
= settings
->hintstyle
;
671 if ((settings
->seen
& SEEN_DPI
) != 0 && oldsettings
.dpi
!= settings
->dpi
672 && settings
->dpi
> 0)
674 FcPatternDel (pat
, FC_DPI
);
675 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
677 oldsettings
.dpi
= settings
->dpi
;
679 /* Changing the DPI on this display affects all frames on it.
680 Check FRAME_RES_X and FRAME_RES_Y in frame.h to see how. */
681 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
686 static char const format
[] =
687 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
688 "Hintstyle: %d, DPI: %f";
692 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
694 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
696 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
699 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
701 XftDefaultSet (dpyinfo
->display
, pat
);
703 store_config_changed_event (Qfont_render
,
704 XCAR (dpyinfo
->name_list_element
));
706 = make_formatted_string (buf
, format
,
707 oldsettings
.aa
, oldsettings
.hinting
,
708 oldsettings
.rgba
, oldsettings
.lcdfilter
,
709 oldsettings
.hintstyle
, oldsettings
.dpi
);
713 FcPatternDestroy (pat
);
714 #endif /* HAVE_XFT */
717 /* Read XSettings from the display for DPYINFO.
718 If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */
721 read_and_apply_settings (struct x_display_info
*dpyinfo
, int send_event_p
)
723 struct xsettings settings
;
725 if (!read_settings (dpyinfo
, &settings
))
728 apply_xft_settings (dpyinfo
, True
, &settings
);
729 if (settings
.seen
& SEEN_TB_STYLE
)
732 store_tool_bar_style_changed (settings
.tb_style
, dpyinfo
);
734 current_tool_bar_style
= map_tool_bar_style (settings
.tb_style
);
735 xfree (settings
.tb_style
);
738 if (settings
.seen
& SEEN_FONT
)
741 store_font_name_changed (settings
.font
);
743 dupstring (¤t_font
, settings
.font
);
744 xfree (settings
.font
);
749 /* Check if EVENT for the display in DPYINFO is XSettings related. */
752 xft_settings_event (struct x_display_info
*dpyinfo
, const XEvent
*event
)
754 bool check_window_p
= 0, apply_settings_p
= 0;
759 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
764 if (event
->xclient
.message_type
== dpyinfo
->Xatom_xsettings_mgr
765 && event
->xclient
.data
.l
[1] == dpyinfo
->Xatom_xsettings_sel
766 && event
->xclient
.window
== dpyinfo
->root_window
)
771 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
772 && event
->xproperty
.state
== PropertyNewValue
773 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
774 apply_settings_p
= 1;
781 dpyinfo
->xsettings_window
= None
;
782 get_prop_window (dpyinfo
);
783 if (dpyinfo
->xsettings_window
!= None
)
784 apply_settings_p
= 1;
787 if (apply_settings_p
)
788 read_and_apply_settings (dpyinfo
, True
);
791 /* Initialize GSettings and read startup values. */
794 init_gsettings (void)
796 #ifdef HAVE_GSETTINGS
798 int schema_found
= 0;
800 #if ! GLIB_CHECK_VERSION (2, 36, 0)
804 #if GLIB_CHECK_VERSION (2, 32, 0)
806 GSettingsSchema
*sc
= g_settings_schema_source_lookup
807 (g_settings_schema_source_get_default (),
810 schema_found
= sc
!= NULL
;
811 if (sc
) g_settings_schema_unref (sc
);
815 const gchar
*const *schemas
= g_settings_list_schemas ();
816 if (schemas
== NULL
) return;
817 while (! schema_found
&& *schemas
!= NULL
)
818 schema_found
= strcmp (*schemas
++, GSETTINGS_SCHEMA
) == 0;
821 if (!schema_found
) return;
823 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
824 if (!gsettings_client
) return;
825 g_object_ref_sink (G_OBJECT (gsettings_client
));
826 g_signal_connect (G_OBJECT (gsettings_client
), "changed",
827 G_CALLBACK (something_changed_gsettingsCB
), NULL
);
829 val
= g_settings_get_value (gsettings_client
, GSETTINGS_TOOL_BAR_STYLE
);
832 g_variant_ref_sink (val
);
833 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
834 current_tool_bar_style
835 = map_tool_bar_style (g_variant_get_string (val
, NULL
));
836 g_variant_unref (val
);
840 val
= g_settings_get_value (gsettings_client
, GSETTINGS_MONO_FONT
);
843 g_variant_ref_sink (val
);
844 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
845 dupstring (¤t_mono_font
, g_variant_get_string (val
, NULL
));
846 g_variant_unref (val
);
849 val
= g_settings_get_value (gsettings_client
, GSETTINGS_FONT_NAME
);
852 g_variant_ref_sink (val
);
853 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
854 dupstring (¤t_font
, g_variant_get_string (val
, NULL
));
855 g_variant_unref (val
);
857 #endif /* HAVE_XFT */
859 #endif /* HAVE_GSETTINGS */
862 /* Init GConf and read startup values. */
867 #if defined (HAVE_GCONF)
870 #if ! GLIB_CHECK_VERSION (2, 36, 0)
874 gconf_client
= gconf_client_get_default ();
875 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
876 gconf_client_add_dir (gconf_client
,
877 GCONF_TOOL_BAR_STYLE
,
878 GCONF_CLIENT_PRELOAD_ONELEVEL
,
880 gconf_client_notify_add (gconf_client
,
881 GCONF_TOOL_BAR_STYLE
,
882 something_changed_gconfCB
,
885 s
= gconf_client_get_string (gconf_client
, GCONF_TOOL_BAR_STYLE
, NULL
);
888 current_tool_bar_style
= map_tool_bar_style (s
);
893 s
= gconf_client_get_string (gconf_client
, GCONF_MONO_FONT
, NULL
);
896 dupstring (¤t_mono_font
, s
);
899 s
= gconf_client_get_string (gconf_client
, GCONF_FONT_NAME
, NULL
);
902 dupstring (¤t_font
, s
);
905 gconf_client_add_dir (gconf_client
,
907 GCONF_CLIENT_PRELOAD_ONELEVEL
,
909 gconf_client_notify_add (gconf_client
,
911 something_changed_gconfCB
,
913 gconf_client_add_dir (gconf_client
,
915 GCONF_CLIENT_PRELOAD_ONELEVEL
,
917 gconf_client_notify_add (gconf_client
,
919 something_changed_gconfCB
,
921 #endif /* HAVE_XFT */
922 #endif /* HAVE_GCONF */
925 /* Init Xsettings and read startup values. */
928 init_xsettings (struct x_display_info
*dpyinfo
)
930 Display
*dpy
= dpyinfo
->display
;
934 /* Select events so we can detect client messages sent when selection
936 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
938 get_prop_window (dpyinfo
);
939 if (dpyinfo
->xsettings_window
!= None
)
940 read_and_apply_settings (dpyinfo
, False
);
946 xsettings_initialize (struct x_display_info
*dpyinfo
)
948 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
950 init_xsettings (dpyinfo
);
954 /* Return the system monospaced font.
955 May be NULL if not known. */
958 xsettings_get_system_font (void)
960 return current_mono_font
;
964 /* Return the system font.
965 May be NULL if not known. */
968 xsettings_get_system_normal_font (void)
974 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
975 Sfont_get_system_normal_font
,
977 doc
: /* Get the system default application font. */)
980 return current_font
? build_string (current_font
) : Qnil
;
983 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
985 doc
: /* Get the system default fixed width font. */)
988 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
991 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
992 Stool_bar_get_system_style
, 0, 0, 0,
993 doc
: /* Get the system tool bar style.
994 If no system tool bar style is known, return `tool-bar-style' if set to a
995 known style. Otherwise return image. */)
998 if (EQ (Vtool_bar_style
, Qimage
)
999 || EQ (Vtool_bar_style
, Qtext
)
1000 || EQ (Vtool_bar_style
, Qboth
)
1001 || EQ (Vtool_bar_style
, Qboth_horiz
)
1002 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
1003 return Vtool_bar_style
;
1004 if (!NILP (current_tool_bar_style
))
1005 return current_tool_bar_style
;
1010 syms_of_xsettings (void)
1012 current_mono_font
= NULL
;
1013 current_font
= NULL
;
1014 first_dpyinfo
= NULL
;
1015 #ifdef HAVE_GSETTINGS
1016 gsettings_client
= NULL
;
1019 gconf_client
= NULL
;
1022 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
1023 DEFSYM (Qfont_name
, "font-name");
1024 DEFSYM (Qfont_render
, "font-render");
1025 defsubr (&Sfont_get_system_font
);
1026 defsubr (&Sfont_get_system_normal_font
);
1028 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
1029 doc
: /* Non-nil means to apply the system defined font dynamically.
1030 When this is non-nil and the system defined fixed width font changes, we
1031 update frames dynamically.
1032 If this variable is nil, Emacs ignores system font changes. */);
1033 use_system_font
= 0;
1035 DEFVAR_LISP ("xft-settings", Vxft_settings
,
1036 doc
: /* Font settings applied to Xft. */);
1037 Vxft_settings
= empty_unibyte_string
;
1040 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
1041 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
1042 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
1046 current_tool_bar_style
= Qnil
;
1047 DEFSYM (Qtool_bar_style
, "tool-bar-style");
1048 defsubr (&Stool_bar_get_system_style
);
1050 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);