1 /* Functions for handling font and other changes dynamically.
3 Copyright (C) 2009-2018 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 (at
10 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 <https://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
672 /* The following conjunct avoids setting `changed' to true when
673 old and new dpi settings do not differ "substantially".
674 Otherwise, the dynamic-setting Elisp code may process all sorts
675 of unrelated settings that override users' font customizations,
676 among others. Compare:
678 https://lists.gnu.org/r/emacs-devel/2016-05/msg00557.html
679 https://lists.gnu.org/r/bug-gnu-emacs/2016-12/msg00820.html
681 As soon as the dynamic-settings code has been tested and
682 verified, this Emacs 25.2 workaround should be removed. */
683 && ((oldsettings
.dpi
>= settings
->dpi
684 && (oldsettings
.dpi
- settings
->dpi
) > 2)
685 || ((settings
->dpi
> oldsettings
.dpi
)
686 && (settings
->dpi
- oldsettings
.dpi
) > 2)))
688 FcPatternDel (pat
, FC_DPI
);
689 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
691 oldsettings
.dpi
= settings
->dpi
;
693 /* Changing the DPI on this display affects all frames on it.
694 Check FRAME_RES_X and FRAME_RES_Y in frame.h to see how. */
695 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
700 static char const format
[] =
701 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
702 "Hintstyle: %d, DPI: %f";
706 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
708 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
710 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
713 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
715 XftDefaultSet (dpyinfo
->display
, pat
);
716 store_config_changed_event (Qfont_render
,
717 XCAR (dpyinfo
->name_list_element
));
719 = make_formatted_string (buf
, format
,
720 oldsettings
.aa
, oldsettings
.hinting
,
721 oldsettings
.rgba
, oldsettings
.lcdfilter
,
722 oldsettings
.hintstyle
, oldsettings
.dpi
);
726 FcPatternDestroy (pat
);
727 #endif /* HAVE_XFT */
730 /* Read XSettings from the display for DPYINFO.
731 If SEND_EVENT_P store a Lisp event settings that changed. */
734 read_and_apply_settings (struct x_display_info
*dpyinfo
, bool send_event_p
)
736 struct xsettings settings
;
738 if (!read_settings (dpyinfo
, &settings
))
741 apply_xft_settings (dpyinfo
, &settings
);
742 if (settings
.seen
& SEEN_TB_STYLE
)
745 store_tool_bar_style_changed (settings
.tb_style
, dpyinfo
);
747 current_tool_bar_style
= map_tool_bar_style (settings
.tb_style
);
748 xfree (settings
.tb_style
);
751 if (settings
.seen
& SEEN_FONT
)
754 store_font_name_changed (settings
.font
);
756 dupstring (¤t_font
, settings
.font
);
757 xfree (settings
.font
);
762 /* Check if EVENT for the display in DPYINFO is XSettings related. */
765 xft_settings_event (struct x_display_info
*dpyinfo
, const XEvent
*event
)
767 bool check_window_p
= false, apply_settings_p
= false;
772 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
773 check_window_p
= true;
777 if (event
->xclient
.message_type
== dpyinfo
->Xatom_xsettings_mgr
778 && event
->xclient
.data
.l
[1] == dpyinfo
->Xatom_xsettings_sel
779 && event
->xclient
.window
== dpyinfo
->root_window
)
780 check_window_p
= true;
784 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
785 && event
->xproperty
.state
== PropertyNewValue
786 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
787 apply_settings_p
= true;
794 dpyinfo
->xsettings_window
= None
;
795 get_prop_window (dpyinfo
);
796 if (dpyinfo
->xsettings_window
!= None
)
797 apply_settings_p
= true;
800 if (apply_settings_p
)
801 read_and_apply_settings (dpyinfo
, true);
804 /* Initialize GSettings and read startup values. */
807 init_gsettings (void)
809 #ifdef HAVE_GSETTINGS
811 bool schema_found
= false;
813 #if ! GLIB_CHECK_VERSION (2, 36, 0)
817 #if GLIB_CHECK_VERSION (2, 32, 0)
819 GSettingsSchema
*sc
= g_settings_schema_source_lookup
820 (g_settings_schema_source_get_default (),
823 schema_found
= sc
!= NULL
;
824 if (sc
) g_settings_schema_unref (sc
);
828 const gchar
*const *schemas
= g_settings_list_schemas ();
829 if (schemas
== NULL
) return;
830 while (! schema_found
&& *schemas
!= NULL
)
831 schema_found
= strcmp (*schemas
++, GSETTINGS_SCHEMA
) == 0;
834 if (!schema_found
) return;
836 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
837 if (!gsettings_client
) return;
838 g_object_ref_sink (G_OBJECT (gsettings_client
));
839 g_signal_connect (G_OBJECT (gsettings_client
), "changed",
840 G_CALLBACK (something_changed_gsettingsCB
), NULL
);
842 val
= g_settings_get_value (gsettings_client
, GSETTINGS_TOOL_BAR_STYLE
);
845 g_variant_ref_sink (val
);
846 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
847 current_tool_bar_style
848 = map_tool_bar_style (g_variant_get_string (val
, NULL
));
849 g_variant_unref (val
);
853 val
= g_settings_get_value (gsettings_client
, GSETTINGS_MONO_FONT
);
856 g_variant_ref_sink (val
);
857 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
858 dupstring (¤t_mono_font
, g_variant_get_string (val
, NULL
));
859 g_variant_unref (val
);
862 val
= g_settings_get_value (gsettings_client
, GSETTINGS_FONT_NAME
);
865 g_variant_ref_sink (val
);
866 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
867 dupstring (¤t_font
, g_variant_get_string (val
, NULL
));
868 g_variant_unref (val
);
870 #endif /* HAVE_XFT */
872 #endif /* HAVE_GSETTINGS */
875 /* Init GConf and read startup values. */
880 #if defined (HAVE_GCONF)
883 #if ! GLIB_CHECK_VERSION (2, 36, 0)
887 gconf_client
= gconf_client_get_default ();
888 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
889 gconf_client_add_dir (gconf_client
,
890 GCONF_TOOL_BAR_STYLE
,
891 GCONF_CLIENT_PRELOAD_ONELEVEL
,
893 gconf_client_notify_add (gconf_client
,
894 GCONF_TOOL_BAR_STYLE
,
895 something_changed_gconfCB
,
898 s
= gconf_client_get_string (gconf_client
, GCONF_TOOL_BAR_STYLE
, NULL
);
901 current_tool_bar_style
= map_tool_bar_style (s
);
906 s
= gconf_client_get_string (gconf_client
, GCONF_MONO_FONT
, NULL
);
909 dupstring (¤t_mono_font
, s
);
912 s
= gconf_client_get_string (gconf_client
, GCONF_FONT_NAME
, NULL
);
915 dupstring (¤t_font
, s
);
918 gconf_client_add_dir (gconf_client
,
920 GCONF_CLIENT_PRELOAD_ONELEVEL
,
922 gconf_client_notify_add (gconf_client
,
924 something_changed_gconfCB
,
926 gconf_client_add_dir (gconf_client
,
928 GCONF_CLIENT_PRELOAD_ONELEVEL
,
930 gconf_client_notify_add (gconf_client
,
932 something_changed_gconfCB
,
934 #endif /* HAVE_XFT */
935 #endif /* HAVE_GCONF */
938 /* Init Xsettings and read startup values. */
941 init_xsettings (struct x_display_info
*dpyinfo
)
943 Display
*dpy
= dpyinfo
->display
;
947 /* Select events so we can detect client messages sent when selection
949 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
951 get_prop_window (dpyinfo
);
952 if (dpyinfo
->xsettings_window
!= None
)
953 read_and_apply_settings (dpyinfo
, false);
959 xsettings_initialize (struct x_display_info
*dpyinfo
)
961 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
963 init_xsettings (dpyinfo
);
967 /* Return the system monospaced font.
968 May be NULL if not known. */
971 xsettings_get_system_font (void)
973 return current_mono_font
;
977 /* Return the system font.
978 May be NULL if not known. */
981 xsettings_get_system_normal_font (void)
987 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
988 Sfont_get_system_normal_font
,
990 doc
: /* Get the system default application font. */)
993 return current_font
? build_string (current_font
) : Qnil
;
996 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
998 doc
: /* Get the system default fixed width font. */)
1001 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
1004 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
1005 Stool_bar_get_system_style
, 0, 0, 0,
1006 doc
: /* Get the system tool bar style.
1007 If no system tool bar style is known, return `tool-bar-style' if set to a
1008 known style. Otherwise return image. */)
1011 if (EQ (Vtool_bar_style
, Qimage
)
1012 || EQ (Vtool_bar_style
, Qtext
)
1013 || EQ (Vtool_bar_style
, Qboth
)
1014 || EQ (Vtool_bar_style
, Qboth_horiz
)
1015 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
1016 return Vtool_bar_style
;
1017 if (!NILP (current_tool_bar_style
))
1018 return current_tool_bar_style
;
1023 syms_of_xsettings (void)
1025 current_mono_font
= NULL
;
1026 current_font
= NULL
;
1027 first_dpyinfo
= NULL
;
1028 #ifdef HAVE_GSETTINGS
1029 gsettings_client
= NULL
;
1032 gconf_client
= NULL
;
1035 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
1036 DEFSYM (Qfont_name
, "font-name");
1037 DEFSYM (Qfont_render
, "font-render");
1038 defsubr (&Sfont_get_system_font
);
1039 defsubr (&Sfont_get_system_normal_font
);
1041 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
1042 doc
: /* Non-nil means to apply the system defined font dynamically.
1043 When this is non-nil and the system defined fixed width font changes, we
1044 update frames dynamically.
1045 If this variable is nil, Emacs ignores system font changes. */);
1046 use_system_font
= false;
1048 DEFVAR_LISP ("xft-settings", Vxft_settings
,
1049 doc
: /* Font settings applied to Xft. */);
1050 Vxft_settings
= empty_unibyte_string
;
1053 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
1054 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
1055 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
1059 current_tool_bar_style
= Qnil
;
1060 DEFSYM (Qtool_bar_style
, "tool-bar-style");
1061 defsubr (&Stool_bar_get_system_style
);
1063 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);