1 /* Functions for handling font and other changes dynamically.
3 Copyright (C) 2009-2013 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 xfree (current_mono_font
);
95 current_mono_font
= xstrdup (newfont
);
97 if (dpyinfo_valid (first_dpyinfo
) && use_system_font
)
99 store_config_changed_event (Qmonospace_font_name
,
100 XCAR (first_dpyinfo
->name_list_element
));
105 /* Store a font name change event if the font name changed. */
109 store_font_name_changed (const char *newfont
)
111 if (current_font
!= NULL
&& strcmp (newfont
, current_font
) == 0)
112 return; /* No change. */
114 xfree (current_font
);
115 current_font
= xstrdup (newfont
);
117 if (dpyinfo_valid (first_dpyinfo
))
119 store_config_changed_event (Qfont_name
,
120 XCAR (first_dpyinfo
->name_list_element
));
123 #endif /* HAVE_XFT */
125 /* Map TOOL_BAR_STYLE from a string to its corresponding Lisp value.
126 Return Qnil if TOOL_BAR_STYLE is not known. */
129 map_tool_bar_style (const char *tool_bar_style
)
131 Lisp_Object style
= Qnil
;
134 if (strcmp (tool_bar_style
, "both") == 0)
136 else if (strcmp (tool_bar_style
, "both-horiz") == 0)
138 else if (strcmp (tool_bar_style
, "icons") == 0)
140 else if (strcmp (tool_bar_style
, "text") == 0)
147 /* Store a tool bar style change event if the tool bar style changed. */
150 store_tool_bar_style_changed (const char *newstyle
,
151 struct x_display_info
*dpyinfo
)
153 Lisp_Object style
= map_tool_bar_style (newstyle
);
154 if (EQ (current_tool_bar_style
, style
))
155 return; /* No change. */
157 current_tool_bar_style
= style
;
158 if (dpyinfo_valid (dpyinfo
))
159 store_config_changed_event (Qtool_bar_style
,
160 XCAR (dpyinfo
->name_list_element
));
164 #define XSETTINGS_FONT_NAME "Gtk/FontName"
166 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
172 SEEN_LCDFILTER
= 0x08,
173 SEEN_HINTSTYLE
= 0x10,
182 int rgba
, lcdfilter
, hintstyle
;
193 #ifdef HAVE_GSETTINGS
194 #define GSETTINGS_SCHEMA "org.gnome.desktop.interface"
195 #define GSETTINGS_TOOL_BAR_STYLE "toolbar-style"
198 #define GSETTINGS_MONO_FONT "monospace-font-name"
199 #define GSETTINGS_FONT_NAME "font-name"
203 /* The single GSettings instance, or NULL if not connected to GSettings. */
205 static GSettings
*gsettings_client
;
207 /* Callback called when something changed in GSettings. */
210 something_changed_gsettingsCB (GSettings
*settings
,
216 if (strcmp (key
, GSETTINGS_TOOL_BAR_STYLE
) == 0)
218 val
= g_settings_get_value (settings
, GSETTINGS_TOOL_BAR_STYLE
);
221 g_variant_ref_sink (val
);
222 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
224 const gchar
*newstyle
= g_variant_get_string (val
, NULL
);
225 store_tool_bar_style_changed (newstyle
, first_dpyinfo
);
227 g_variant_unref (val
);
231 else if (strcmp (key
, GSETTINGS_MONO_FONT
) == 0)
233 val
= g_settings_get_value (settings
, GSETTINGS_MONO_FONT
);
236 g_variant_ref_sink (val
);
237 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
239 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
240 store_monospaced_changed (newfont
);
242 g_variant_unref (val
);
245 else if (strcmp (key
, GSETTINGS_FONT_NAME
) == 0)
247 val
= g_settings_get_value (settings
, GSETTINGS_FONT_NAME
);
250 g_variant_ref_sink (val
);
251 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
253 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
254 store_font_name_changed (newfont
);
256 g_variant_unref (val
);
259 #endif /* HAVE_XFT */
262 #endif /* HAVE_GSETTINGS */
265 #define GCONF_TOOL_BAR_STYLE "/desktop/gnome/interface/toolbar_style"
267 #define GCONF_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
268 #define GCONF_FONT_NAME "/desktop/gnome/interface/font_name"
271 /* The single GConf instance, or NULL if not connected to GConf. */
273 static GConfClient
*gconf_client
;
275 /* Callback called when something changed in GConf that we care about. */
278 something_changed_gconfCB (GConfClient
*client
,
283 GConfValue
*v
= gconf_entry_get_value (entry
);
284 const char *key
= gconf_entry_get_key (entry
);
286 if (!v
|| v
->type
!= GCONF_VALUE_STRING
|| ! key
) return;
287 if (strcmp (key
, GCONF_TOOL_BAR_STYLE
) == 0)
289 const char *value
= gconf_value_get_string (v
);
290 store_tool_bar_style_changed (value
, first_dpyinfo
);
293 else if (strcmp (key
, GCONF_MONO_FONT
) == 0)
295 const char *value
= gconf_value_get_string (v
);
296 store_monospaced_changed (value
);
298 else if (strcmp (key
, GCONF_FONT_NAME
) == 0)
300 const char *value
= gconf_value_get_string (v
);
301 store_font_name_changed (value
);
303 #endif /* HAVE_XFT */
306 #endif /* HAVE_GCONF */
310 /* Older fontconfig versions don't have FC_LCD_*. */
312 #define FC_LCD_NONE 0
314 #ifndef FC_LCD_DEFAULT
315 #define FC_LCD_DEFAULT 1
317 #ifndef FC_LCD_FILTER
318 #define FC_LCD_FILTER "lcdfilter"
321 #endif /* HAVE_XFT */
323 /* Find the window that contains the XSETTINGS property values. */
326 get_prop_window (struct x_display_info
*dpyinfo
)
328 Display
*dpy
= dpyinfo
->display
;
331 dpyinfo
->xsettings_window
= XGetSelectionOwner (dpy
,
332 dpyinfo
->Xatom_xsettings_sel
);
333 if (dpyinfo
->xsettings_window
!= None
)
334 /* Select events so we can detect if window is deleted or if settings
336 XSelectInput (dpy
, dpyinfo
->xsettings_window
,
337 PropertyChangeMask
|StructureNotifyMask
);
342 #define PAD(nr) (((nr) + 3) & ~3)
344 /* Parse xsettings and extract those that deal with Xft.
345 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
346 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
348 Layout of prop. First is a header:
351 ------------------------------------
357 Then N_SETTINGS records, with header:
360 ------------------------------------
361 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
363 2 CARD16 n == name-length
365 p unused, p=pad_to_even_4(n)
366 4 CARD32 last-change-serial
368 and then the value, For string:
371 ------------------------------------
372 4 CARD32 n = value-length
374 p unused, p=pad_to_even_4(n)
379 ------------------------------------
385 ------------------------------------
391 Returns non-zero if some Xft settings was seen, zero otherwise.
395 parse_settings (unsigned char *prop
,
396 long unsigned int bytes
,
397 struct xsettings
*settings
)
399 Lisp_Object byteorder
= Fbyteorder ();
400 int my_bo
= XFASTINT (byteorder
) == 'B' ? MSBFirst
: LSBFirst
;
401 int that_bo
= prop
[0];
403 int bytes_parsed
= 0;
404 int settings_seen
= 0;
407 /* First 4 bytes is a serial number, skip that. */
409 if (bytes
< 12) return BadLength
;
410 memcpy (&n_settings
, prop
+8, 4);
411 if (my_bo
!= that_bo
) n_settings
= bswap_32 (n_settings
);
414 memset (settings
, 0, sizeof (*settings
));
416 while (bytes_parsed
+4 < bytes
&& settings_seen
< 7
419 int type
= prop
[bytes_parsed
++];
421 CARD32 vlen
, ival
= 0;
422 char name
[128]; /* The names we are looking for are not this long. */
423 char sval
[128]; /* The values we are looking for are not this long. */
429 ++bytes_parsed
; /* Padding */
431 memcpy (&nlen
, prop
+bytes_parsed
, 2);
433 if (my_bo
!= that_bo
) nlen
= bswap_16 (nlen
);
434 if (bytes_parsed
+nlen
> bytes
) return BadLength
;
435 to_cpy
= nlen
> 127 ? 127 : nlen
;
436 memcpy (name
, prop
+bytes_parsed
, to_cpy
);
439 bytes_parsed
+= nlen
;
440 bytes_parsed
= PAD (bytes_parsed
);
442 bytes_parsed
+= 4; /* Skip serial for this value */
443 if (bytes_parsed
> bytes
) return BadLength
;
447 (nlen
> 6 && strncmp (name
, "Xft/", 4) == 0)
448 || strcmp (XSETTINGS_FONT_NAME
, name
) == 0
451 strcmp (XSETTINGS_TOOL_BAR_STYLE
, name
) == 0;
455 case 0: /* Integer */
456 if (bytes_parsed
+4 > bytes
) return BadLength
;
459 memcpy (&ival
, prop
+bytes_parsed
, 4);
460 if (my_bo
!= that_bo
) ival
= bswap_32 (ival
);
466 if (bytes_parsed
+4 > bytes
) return BadLength
;
467 memcpy (&vlen
, prop
+bytes_parsed
, 4);
469 if (my_bo
!= that_bo
) vlen
= bswap_32 (vlen
);
472 to_cpy
= vlen
> 127 ? 127 : vlen
;
473 memcpy (sval
, prop
+bytes_parsed
, to_cpy
);
476 bytes_parsed
+= vlen
;
477 bytes_parsed
= PAD (bytes_parsed
);
480 case 2: /* RGB value */
481 /* No need to parse this */
482 if (bytes_parsed
+8 > bytes
) return BadLength
;
483 bytes_parsed
+= 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
486 default: /* Parse Error */
493 if (strcmp (name
, XSETTINGS_TOOL_BAR_STYLE
) == 0)
495 settings
->tb_style
= xstrdup (sval
);
496 settings
->seen
|= SEEN_TB_STYLE
;
499 else if (strcmp (name
, XSETTINGS_FONT_NAME
) == 0)
501 settings
->font
= xstrdup (sval
);
502 settings
->seen
|= SEEN_FONT
;
504 else if (strcmp (name
, "Xft/Antialias") == 0)
506 settings
->seen
|= SEEN_AA
;
507 settings
->aa
= ival
!= 0;
509 else if (strcmp (name
, "Xft/Hinting") == 0)
511 settings
->seen
|= SEEN_HINTING
;
512 settings
->hinting
= ival
!= 0;
514 # ifdef FC_HINT_STYLE
515 else if (strcmp (name
, "Xft/HintStyle") == 0)
517 settings
->seen
|= SEEN_HINTSTYLE
;
518 if (strcmp (sval
, "hintnone") == 0)
519 settings
->hintstyle
= FC_HINT_NONE
;
520 else if (strcmp (sval
, "hintslight") == 0)
521 settings
->hintstyle
= FC_HINT_SLIGHT
;
522 else if (strcmp (sval
, "hintmedium") == 0)
523 settings
->hintstyle
= FC_HINT_MEDIUM
;
524 else if (strcmp (sval
, "hintfull") == 0)
525 settings
->hintstyle
= FC_HINT_FULL
;
527 settings
->seen
&= ~SEEN_HINTSTYLE
;
530 else if (strcmp (name
, "Xft/RGBA") == 0)
532 settings
->seen
|= SEEN_RGBA
;
533 if (strcmp (sval
, "none") == 0)
534 settings
->rgba
= FC_RGBA_NONE
;
535 else if (strcmp (sval
, "rgb") == 0)
536 settings
->rgba
= FC_RGBA_RGB
;
537 else if (strcmp (sval
, "bgr") == 0)
538 settings
->rgba
= FC_RGBA_BGR
;
539 else if (strcmp (sval
, "vrgb") == 0)
540 settings
->rgba
= FC_RGBA_VRGB
;
541 else if (strcmp (sval
, "vbgr") == 0)
542 settings
->rgba
= FC_RGBA_VBGR
;
544 settings
->seen
&= ~SEEN_RGBA
;
546 else if (strcmp (name
, "Xft/DPI") == 0)
548 settings
->seen
|= SEEN_DPI
;
549 settings
->dpi
= (double)ival
/1024.0;
551 else if (strcmp (name
, "Xft/lcdfilter") == 0)
553 settings
->seen
|= SEEN_LCDFILTER
;
554 if (strcmp (sval
, "none") == 0)
555 settings
->lcdfilter
= FC_LCD_NONE
;
556 else if (strcmp (sval
, "lcddefault") == 0)
557 settings
->lcdfilter
= FC_LCD_DEFAULT
;
559 settings
->seen
&= ~SEEN_LCDFILTER
;
561 #endif /* HAVE_XFT */
565 return settings_seen
;
568 /* Read settings from the XSettings property window on display for DPYINFO.
569 Store settings read in SETTINGS.
570 Return non-zero if successful, zero if not. */
573 read_settings (struct x_display_info
*dpyinfo
, struct xsettings
*settings
)
577 unsigned long nitems
, bytes_after
;
578 unsigned char *prop
= NULL
;
579 Display
*dpy
= dpyinfo
->display
;
582 x_catch_errors (dpy
);
583 rc
= XGetWindowProperty (dpy
,
584 dpyinfo
->xsettings_window
,
585 dpyinfo
->Xatom_xsettings_prop
,
586 0, LONG_MAX
, False
, AnyPropertyType
,
587 &act_type
, &act_form
, &nitems
, &bytes_after
,
590 if (rc
== Success
&& prop
!= NULL
&& act_form
== 8 && nitems
> 0
591 && act_type
== dpyinfo
->Xatom_xsettings_prop
)
592 rc
= parse_settings (prop
, nitems
, settings
);
601 /* Apply Xft settings in SETTINGS to the Xft library.
602 If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */
605 apply_xft_settings (struct x_display_info
*dpyinfo
,
607 struct xsettings
*settings
)
611 struct xsettings oldsettings
;
614 memset (&oldsettings
, 0, sizeof (oldsettings
));
615 pat
= FcPatternCreate ();
616 XftDefaultSubstitute (dpyinfo
->display
,
617 XScreenNumberOfScreen (dpyinfo
->screen
),
619 FcPatternGetBool (pat
, FC_ANTIALIAS
, 0, &oldsettings
.aa
);
620 FcPatternGetBool (pat
, FC_HINTING
, 0, &oldsettings
.hinting
);
622 FcPatternGetInteger (pat
, FC_HINT_STYLE
, 0, &oldsettings
.hintstyle
);
624 FcPatternGetInteger (pat
, FC_LCD_FILTER
, 0, &oldsettings
.lcdfilter
);
625 FcPatternGetInteger (pat
, FC_RGBA
, 0, &oldsettings
.rgba
);
626 FcPatternGetDouble (pat
, FC_DPI
, 0, &oldsettings
.dpi
);
628 if ((settings
->seen
& SEEN_AA
) != 0 && oldsettings
.aa
!= settings
->aa
)
630 FcPatternDel (pat
, FC_ANTIALIAS
);
631 FcPatternAddBool (pat
, FC_ANTIALIAS
, settings
->aa
);
633 oldsettings
.aa
= settings
->aa
;
636 if ((settings
->seen
& SEEN_HINTING
) != 0
637 && oldsettings
.hinting
!= settings
->hinting
)
639 FcPatternDel (pat
, FC_HINTING
);
640 FcPatternAddBool (pat
, FC_HINTING
, settings
->hinting
);
642 oldsettings
.hinting
= settings
->hinting
;
644 if ((settings
->seen
& SEEN_RGBA
) != 0 && oldsettings
.rgba
!= settings
->rgba
)
646 FcPatternDel (pat
, FC_RGBA
);
647 FcPatternAddInteger (pat
, FC_RGBA
, settings
->rgba
);
648 oldsettings
.rgba
= settings
->rgba
;
652 /* Older fontconfig versions don't have FC_LCD_FILTER. */
653 if ((settings
->seen
& SEEN_LCDFILTER
) != 0
654 && oldsettings
.lcdfilter
!= settings
->lcdfilter
)
656 FcPatternDel (pat
, FC_LCD_FILTER
);
657 FcPatternAddInteger (pat
, FC_LCD_FILTER
, settings
->lcdfilter
);
659 oldsettings
.lcdfilter
= settings
->lcdfilter
;
663 if ((settings
->seen
& SEEN_HINTSTYLE
) != 0
664 && oldsettings
.hintstyle
!= settings
->hintstyle
)
666 FcPatternDel (pat
, FC_HINT_STYLE
);
667 FcPatternAddInteger (pat
, FC_HINT_STYLE
, settings
->hintstyle
);
669 oldsettings
.hintstyle
= settings
->hintstyle
;
673 if ((settings
->seen
& SEEN_DPI
) != 0 && oldsettings
.dpi
!= settings
->dpi
674 && settings
->dpi
> 0)
676 FcPatternDel (pat
, FC_DPI
);
677 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
679 oldsettings
.dpi
= settings
->dpi
;
681 /* Changing the DPI on this display affects all frames on it.
682 Check FRAME_RES_X and FRAME_RES_Y in frame.h to see how. */
683 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
688 static char const format
[] =
689 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
690 "Hintstyle: %d, DPI: %f";
694 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
696 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
698 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
701 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
703 XftDefaultSet (dpyinfo
->display
, pat
);
705 store_config_changed_event (Qfont_render
,
706 XCAR (dpyinfo
->name_list_element
));
708 = make_formatted_string (buf
, format
,
709 oldsettings
.aa
, oldsettings
.hinting
,
710 oldsettings
.rgba
, oldsettings
.lcdfilter
,
711 oldsettings
.hintstyle
, oldsettings
.dpi
);
715 FcPatternDestroy (pat
);
716 #endif /* HAVE_XFT */
719 /* Read XSettings from the display for DPYINFO.
720 If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */
723 read_and_apply_settings (struct x_display_info
*dpyinfo
, int send_event_p
)
725 struct xsettings settings
;
727 if (!read_settings (dpyinfo
, &settings
))
730 apply_xft_settings (dpyinfo
, True
, &settings
);
731 if (settings
.seen
& SEEN_TB_STYLE
)
734 store_tool_bar_style_changed (settings
.tb_style
, dpyinfo
);
736 current_tool_bar_style
= map_tool_bar_style (settings
.tb_style
);
737 xfree (settings
.tb_style
);
740 if (settings
.seen
& SEEN_FONT
)
743 store_font_name_changed (settings
.font
);
746 xfree (current_font
);
747 current_font
= xstrdup (settings
.font
);
749 xfree (settings
.font
);
754 /* Check if EVENT for the display in DPYINFO is XSettings related. */
757 xft_settings_event (struct x_display_info
*dpyinfo
, const XEvent
*event
)
759 bool check_window_p
= 0, apply_settings_p
= 0;
764 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
769 if (event
->xclient
.message_type
== dpyinfo
->Xatom_xsettings_mgr
770 && event
->xclient
.data
.l
[1] == dpyinfo
->Xatom_xsettings_sel
771 && event
->xclient
.window
== dpyinfo
->root_window
)
776 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
777 && event
->xproperty
.state
== PropertyNewValue
778 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
779 apply_settings_p
= 1;
786 dpyinfo
->xsettings_window
= None
;
787 get_prop_window (dpyinfo
);
788 if (dpyinfo
->xsettings_window
!= None
)
789 apply_settings_p
= 1;
792 if (apply_settings_p
)
793 read_and_apply_settings (dpyinfo
, True
);
796 /* Initialize GSettings and read startup values. */
799 init_gsettings (void)
801 #ifdef HAVE_GSETTINGS
803 const gchar
*const *schemas
;
804 int schema_found
= 0;
806 #if ! GLIB_CHECK_VERSION (2, 36, 0)
810 schemas
= g_settings_list_schemas ();
811 if (schemas
== NULL
) return;
812 while (! schema_found
&& *schemas
!= NULL
)
813 schema_found
= strcmp (*schemas
++, GSETTINGS_SCHEMA
) == 0;
814 if (!schema_found
) return;
816 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
817 if (!gsettings_client
) return;
818 g_object_ref_sink (G_OBJECT (gsettings_client
));
819 g_signal_connect (G_OBJECT (gsettings_client
), "changed",
820 G_CALLBACK (something_changed_gsettingsCB
), NULL
);
822 val
= g_settings_get_value (gsettings_client
, GSETTINGS_TOOL_BAR_STYLE
);
825 g_variant_ref_sink (val
);
826 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
827 current_tool_bar_style
828 = map_tool_bar_style (g_variant_get_string (val
, NULL
));
829 g_variant_unref (val
);
833 val
= g_settings_get_value (gsettings_client
, GSETTINGS_MONO_FONT
);
836 g_variant_ref_sink (val
);
837 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
838 current_mono_font
= xstrdup (g_variant_get_string (val
, NULL
));
839 g_variant_unref (val
);
842 val
= g_settings_get_value (gsettings_client
, GSETTINGS_FONT_NAME
);
845 g_variant_ref_sink (val
);
846 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
847 current_font
= xstrdup (g_variant_get_string (val
, NULL
));
848 g_variant_unref (val
);
850 #endif /* HAVE_XFT */
852 #endif /* HAVE_GSETTINGS */
855 /* Init GConf and read startup values. */
860 #if defined (HAVE_GCONF)
863 #if ! GLIB_CHECK_VERSION (2, 36, 0)
867 gconf_client
= gconf_client_get_default ();
868 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
869 gconf_client_add_dir (gconf_client
,
870 GCONF_TOOL_BAR_STYLE
,
871 GCONF_CLIENT_PRELOAD_ONELEVEL
,
873 gconf_client_notify_add (gconf_client
,
874 GCONF_TOOL_BAR_STYLE
,
875 something_changed_gconfCB
,
878 s
= gconf_client_get_string (gconf_client
, GCONF_TOOL_BAR_STYLE
, NULL
);
881 current_tool_bar_style
= map_tool_bar_style (s
);
886 s
= gconf_client_get_string (gconf_client
, GCONF_MONO_FONT
, NULL
);
889 current_mono_font
= xstrdup (s
);
892 s
= gconf_client_get_string (gconf_client
, GCONF_FONT_NAME
, NULL
);
895 current_font
= xstrdup (s
);
898 gconf_client_add_dir (gconf_client
,
900 GCONF_CLIENT_PRELOAD_ONELEVEL
,
902 gconf_client_notify_add (gconf_client
,
904 something_changed_gconfCB
,
906 gconf_client_add_dir (gconf_client
,
908 GCONF_CLIENT_PRELOAD_ONELEVEL
,
910 gconf_client_notify_add (gconf_client
,
912 something_changed_gconfCB
,
914 #endif /* HAVE_XFT */
915 #endif /* HAVE_GCONF */
918 /* Init Xsettings and read startup values. */
921 init_xsettings (struct x_display_info
*dpyinfo
)
923 Display
*dpy
= dpyinfo
->display
;
927 /* Select events so we can detect client messages sent when selection
929 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
931 get_prop_window (dpyinfo
);
932 if (dpyinfo
->xsettings_window
!= None
)
933 read_and_apply_settings (dpyinfo
, False
);
939 xsettings_initialize (struct x_display_info
*dpyinfo
)
941 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
943 init_xsettings (dpyinfo
);
947 /* Return the system monospaced font.
948 May be NULL if not known. */
951 xsettings_get_system_font (void)
953 return current_mono_font
;
957 /* Return the system font.
958 May be NULL if not known. */
961 xsettings_get_system_normal_font (void)
967 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
968 Sfont_get_system_normal_font
,
970 doc
: /* Get the system default application font. */)
973 return current_font
? build_string (current_font
) : Qnil
;
976 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
978 doc
: /* Get the system default fixed width font. */)
981 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
984 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
985 Stool_bar_get_system_style
, 0, 0, 0,
986 doc
: /* Get the system tool bar style.
987 If no system tool bar style is known, return `tool-bar-style' if set to a
988 known style. Otherwise return image. */)
991 if (EQ (Vtool_bar_style
, Qimage
)
992 || EQ (Vtool_bar_style
, Qtext
)
993 || EQ (Vtool_bar_style
, Qboth
)
994 || EQ (Vtool_bar_style
, Qboth_horiz
)
995 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
996 return Vtool_bar_style
;
997 if (!NILP (current_tool_bar_style
))
998 return current_tool_bar_style
;
1003 syms_of_xsettings (void)
1005 current_mono_font
= NULL
;
1006 current_font
= NULL
;
1007 first_dpyinfo
= NULL
;
1008 #ifdef HAVE_GSETTINGS
1009 gsettings_client
= NULL
;
1012 gconf_client
= NULL
;
1015 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
1016 DEFSYM (Qfont_name
, "font-name");
1017 DEFSYM (Qfont_render
, "font-render");
1018 defsubr (&Sfont_get_system_font
);
1019 defsubr (&Sfont_get_system_normal_font
);
1021 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
1022 doc
: /* Non-nil means to apply the system defined font dynamically.
1023 When this is non-nil and the system defined fixed width font changes, we
1024 update frames dynamically.
1025 If this variable is nil, Emacs ignores system font changes. */);
1026 use_system_font
= 0;
1028 DEFVAR_LISP ("xft-settings", Vxft_settings
,
1029 doc
: /* Font settings applied to Xft. */);
1030 Vxft_settings
= empty_unibyte_string
;
1033 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
1034 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
1035 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
1039 current_tool_bar_style
= Qnil
;
1040 DEFSYM (Qtool_bar_style
, "tool-bar-style");
1041 defsubr (&Stool_bar_get_system_style
);
1043 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);