1 /* Functions for handling font and other changes dynamically.
3 Copyright (C) 2009-2011 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/>. */
28 #include "xsettings.h"
31 #include "blockinput.h"
32 #include "termhooks.h"
35 #include <X11/Xproto.h>
38 #include <glib-object.h>
43 #include <gconf/gconf-client.h>
47 #include <X11/Xft/Xft.h>
50 static char *current_mono_font
;
51 static char *current_font
;
52 static struct x_display_info
*first_dpyinfo
;
53 static Lisp_Object Qmonospace_font_name
, Qfont_name
, Qfont_render
,
55 static Lisp_Object current_tool_bar_style
;
57 /* Store an config changed event in to the event queue. */
60 store_config_changed_event (Lisp_Object arg
, Lisp_Object display_name
)
62 struct input_event event
;
64 event
.kind
= CONFIG_CHANGED_EVENT
;
65 event
.frame_or_window
= display_name
;
67 kbd_buffer_store_event (&event
);
70 /* Return non-zero if DPYINFO is still valid. */
72 dpyinfo_valid (struct x_display_info
*dpyinfo
)
77 struct x_display_info
*d
;
78 for (d
= x_display_list
; !found
&& d
; d
= d
->next
)
79 found
= d
== dpyinfo
&& d
->display
== dpyinfo
->display
;
84 /* Store a monospace font change event if the monospaced font changed. */
88 store_monospaced_changed (const char *newfont
)
90 if (current_mono_font
!= NULL
&& strcmp (newfont
, current_mono_font
) == 0)
91 return; /* No change. */
93 xfree (current_mono_font
);
94 current_mono_font
= xstrdup (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
));
103 /* 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 xfree (current_font
);
112 current_font
= xstrdup (newfont
);
114 if (dpyinfo_valid (first_dpyinfo
))
116 store_config_changed_event (Qfont_name
,
117 XCAR (first_dpyinfo
->name_list_element
));
120 #endif /* HAVE_XFT */
122 /* Map TOOL_BAR_STYLE from a string to its correspinding Lisp value.
123 Return Qnil if TOOL_BAR_STYLE is not known. */
126 map_tool_bar_style (const char *tool_bar_style
)
128 Lisp_Object style
= Qnil
;
131 if (strcmp (tool_bar_style
, "both") == 0)
133 else if (strcmp (tool_bar_style
, "both-horiz") == 0)
135 else if (strcmp (tool_bar_style
, "icons") == 0)
137 else if (strcmp (tool_bar_style
, "text") == 0)
144 /* Store a tool bar style change event if the tool bar style changed. */
147 store_tool_bar_style_changed (const char *newstyle
,
148 struct x_display_info
*dpyinfo
)
150 Lisp_Object style
= map_tool_bar_style (newstyle
);
151 if (EQ (current_tool_bar_style
, style
))
152 return; /* No change. */
154 current_tool_bar_style
= style
;
155 if (dpyinfo_valid (dpyinfo
))
156 store_config_changed_event (Qtool_bar_style
,
157 XCAR (dpyinfo
->name_list_element
));
161 #define XSETTINGS_FONT_NAME "Gtk/FontName"
162 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
168 SEEN_LCDFILTER
= 0x08,
169 SEEN_HINTSTYLE
= 0x10,
172 SEEN_TB_STYLE
= 0x80,
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 SWAP32(nr) (((nr) << 24) | (((nr) << 8) & 0xff0000) \
339 | (((nr) >> 8) & 0xff00) | ((nr) >> 24))
340 #define SWAP16(nr) (((nr) << 8) | ((nr) >> 8))
341 #define PAD(nr) (((nr) + 3) & ~3)
343 /* Parse xsettings and extract those that deal with Xft.
344 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
345 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
347 Layout of prop. First is a header:
350 ------------------------------------
356 Then N_SETTINGS records, with header:
359 ------------------------------------
360 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
362 2 CARD16 n == name-length
364 p unused, p=pad_to_even_4(n)
365 4 CARD32 last-change-serial
367 and then the value, For string:
370 ------------------------------------
371 4 CARD32 n = value-length
373 p unused, p=pad_to_even_4(n)
378 ------------------------------------
384 ------------------------------------
390 Returns non-zero if some Xft settings was seen, zero otherwise.
394 parse_settings (unsigned char *prop
,
395 long unsigned int bytes
,
396 struct xsettings
*settings
)
398 Lisp_Object byteorder
= Fbyteorder ();
399 int my_bo
= XFASTINT (byteorder
) == 'B' ? MSBFirst
: LSBFirst
;
400 int that_bo
= prop
[0];
402 int bytes_parsed
= 0;
403 int settings_seen
= 0;
406 /* First 4 bytes is a serial number, skip that. */
408 if (bytes
< 12) return BadLength
;
409 memcpy (&n_settings
, prop
+8, 4);
410 if (my_bo
!= that_bo
) n_settings
= SWAP32 (n_settings
);
413 memset (settings
, 0, sizeof (*settings
));
415 while (bytes_parsed
+4 < bytes
&& settings_seen
< 7
418 int type
= prop
[bytes_parsed
++];
420 CARD32 vlen
, ival
= 0;
421 char name
[128]; /* The names we are looking for are not this long. */
422 char sval
[128]; /* The values we are looking for are not this long. */
428 ++bytes_parsed
; /* Padding */
430 memcpy (&nlen
, prop
+bytes_parsed
, 2);
432 if (my_bo
!= that_bo
) nlen
= SWAP16 (nlen
);
433 if (bytes_parsed
+nlen
> bytes
) return BadLength
;
434 to_cpy
= nlen
> 127 ? 127 : nlen
;
435 memcpy (name
, prop
+bytes_parsed
, to_cpy
);
438 bytes_parsed
+= nlen
;
439 bytes_parsed
= PAD (bytes_parsed
);
441 bytes_parsed
+= 4; /* Skip serial for this value */
442 if (bytes_parsed
> bytes
) return BadLength
;
446 (nlen
> 6 && strncmp (name
, "Xft/", 4) == 0)
447 || strcmp (XSETTINGS_FONT_NAME
, name
) == 0
450 strcmp (XSETTINGS_TOOL_BAR_STYLE
, name
) == 0;
454 case 0: /* Integer */
455 if (bytes_parsed
+4 > bytes
) return BadLength
;
458 memcpy (&ival
, prop
+bytes_parsed
, 4);
459 if (my_bo
!= that_bo
) ival
= SWAP32 (ival
);
465 if (bytes_parsed
+4 > bytes
) return BadLength
;
466 memcpy (&vlen
, prop
+bytes_parsed
, 4);
468 if (my_bo
!= that_bo
) vlen
= SWAP32 (vlen
);
471 to_cpy
= vlen
> 127 ? 127 : vlen
;
472 memcpy (sval
, prop
+bytes_parsed
, to_cpy
);
475 bytes_parsed
+= vlen
;
476 bytes_parsed
= PAD (bytes_parsed
);
479 case 2: /* RGB value */
480 /* No need to parse this */
481 if (bytes_parsed
+8 > bytes
) return BadLength
;
482 bytes_parsed
+= 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
485 default: /* Parse Error */
492 if (strcmp (name
, XSETTINGS_TOOL_BAR_STYLE
) == 0)
494 settings
->tb_style
= xstrdup (sval
);
495 settings
->seen
|= SEEN_TB_STYLE
;
498 else if (strcmp (name
, XSETTINGS_FONT_NAME
) == 0)
500 settings
->font
= xstrdup (sval
);
501 settings
->seen
|= SEEN_FONT
;
503 else if (strcmp (name
, "Xft/Antialias") == 0)
505 settings
->seen
|= SEEN_AA
;
506 settings
->aa
= ival
!= 0;
508 else if (strcmp (name
, "Xft/Hinting") == 0)
510 settings
->seen
|= SEEN_HINTING
;
511 settings
->hinting
= ival
!= 0;
513 # ifdef FC_HINT_STYLE
514 else if (strcmp (name
, "Xft/HintStyle") == 0)
516 settings
->seen
|= SEEN_HINTSTYLE
;
517 if (strcmp (sval
, "hintnone") == 0)
518 settings
->hintstyle
= FC_HINT_NONE
;
519 else if (strcmp (sval
, "hintslight") == 0)
520 settings
->hintstyle
= FC_HINT_SLIGHT
;
521 else if (strcmp (sval
, "hintmedium") == 0)
522 settings
->hintstyle
= FC_HINT_MEDIUM
;
523 else if (strcmp (sval
, "hintfull") == 0)
524 settings
->hintstyle
= FC_HINT_FULL
;
526 settings
->seen
&= ~SEEN_HINTSTYLE
;
529 else if (strcmp (name
, "Xft/RGBA") == 0)
531 settings
->seen
|= SEEN_RGBA
;
532 if (strcmp (sval
, "none") == 0)
533 settings
->rgba
= FC_RGBA_NONE
;
534 else if (strcmp (sval
, "rgb") == 0)
535 settings
->rgba
= FC_RGBA_RGB
;
536 else if (strcmp (sval
, "bgr") == 0)
537 settings
->rgba
= FC_RGBA_BGR
;
538 else if (strcmp (sval
, "vrgb") == 0)
539 settings
->rgba
= FC_RGBA_VRGB
;
540 else if (strcmp (sval
, "vbgr") == 0)
541 settings
->rgba
= FC_RGBA_VBGR
;
543 settings
->seen
&= ~SEEN_RGBA
;
545 else if (strcmp (name
, "Xft/DPI") == 0)
547 settings
->seen
|= SEEN_DPI
;
548 settings
->dpi
= (double)ival
/1024.0;
550 else if (strcmp (name
, "Xft/lcdfilter") == 0)
552 settings
->seen
|= SEEN_LCDFILTER
;
553 if (strcmp (sval
, "none") == 0)
554 settings
->lcdfilter
= FC_LCD_NONE
;
555 else if (strcmp (sval
, "lcddefault") == 0)
556 settings
->lcdfilter
= FC_LCD_DEFAULT
;
558 settings
->seen
&= ~SEEN_LCDFILTER
;
560 #endif /* HAVE_XFT */
564 return settings_seen
;
567 /* Read settings from the XSettings property window on display for DPYINFO.
568 Store settings read in SETTINGS.
569 Return non-zero if successful, zero if not. */
572 read_settings (struct x_display_info
*dpyinfo
, struct xsettings
*settings
)
576 unsigned long nitems
, bytes_after
;
577 unsigned char *prop
= NULL
;
578 Display
*dpy
= dpyinfo
->display
;
581 x_catch_errors (dpy
);
582 rc
= XGetWindowProperty (dpy
,
583 dpyinfo
->xsettings_window
,
584 dpyinfo
->Xatom_xsettings_prop
,
585 0, LONG_MAX
, False
, AnyPropertyType
,
586 &act_type
, &act_form
, &nitems
, &bytes_after
,
589 if (rc
== Success
&& prop
!= NULL
&& act_form
== 8 && nitems
> 0
590 && act_type
== dpyinfo
->Xatom_xsettings_prop
)
591 rc
= parse_settings (prop
, nitems
, settings
);
600 /* Apply Xft settings in SETTINGS to the Xft library.
601 If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */
604 apply_xft_settings (struct x_display_info
*dpyinfo
,
606 struct xsettings
*settings
)
610 struct xsettings oldsettings
;
613 memset (&oldsettings
, 0, sizeof (oldsettings
));
614 pat
= FcPatternCreate ();
615 XftDefaultSubstitute (dpyinfo
->display
,
616 XScreenNumberOfScreen (dpyinfo
->screen
),
618 FcPatternGetBool (pat
, FC_ANTIALIAS
, 0, &oldsettings
.aa
);
619 FcPatternGetBool (pat
, FC_HINTING
, 0, &oldsettings
.hinting
);
621 FcPatternGetInteger (pat
, FC_HINT_STYLE
, 0, &oldsettings
.hintstyle
);
623 FcPatternGetInteger (pat
, FC_LCD_FILTER
, 0, &oldsettings
.lcdfilter
);
624 FcPatternGetInteger (pat
, FC_RGBA
, 0, &oldsettings
.rgba
);
625 FcPatternGetDouble (pat
, FC_DPI
, 0, &oldsettings
.dpi
);
627 if ((settings
->seen
& SEEN_AA
) != 0 && oldsettings
.aa
!= settings
->aa
)
629 FcPatternDel (pat
, FC_ANTIALIAS
);
630 FcPatternAddBool (pat
, FC_ANTIALIAS
, settings
->aa
);
632 oldsettings
.aa
= settings
->aa
;
635 if ((settings
->seen
& SEEN_HINTING
) != 0
636 && oldsettings
.hinting
!= settings
->hinting
)
638 FcPatternDel (pat
, FC_HINTING
);
639 FcPatternAddBool (pat
, FC_HINTING
, settings
->hinting
);
641 oldsettings
.hinting
= settings
->hinting
;
643 if ((settings
->seen
& SEEN_RGBA
) != 0 && oldsettings
.rgba
!= settings
->rgba
)
645 FcPatternDel (pat
, FC_RGBA
);
646 FcPatternAddInteger (pat
, FC_RGBA
, settings
->rgba
);
647 oldsettings
.rgba
= settings
->rgba
;
651 /* Older fontconfig versions don't have FC_LCD_FILTER. */
652 if ((settings
->seen
& SEEN_LCDFILTER
) != 0
653 && oldsettings
.lcdfilter
!= settings
->lcdfilter
)
655 FcPatternDel (pat
, FC_LCD_FILTER
);
656 FcPatternAddInteger (pat
, FC_LCD_FILTER
, settings
->lcdfilter
);
658 oldsettings
.lcdfilter
= settings
->lcdfilter
;
662 if ((settings
->seen
& SEEN_HINTSTYLE
) != 0
663 && oldsettings
.hintstyle
!= settings
->hintstyle
)
665 FcPatternDel (pat
, FC_HINT_STYLE
);
666 FcPatternAddInteger (pat
, FC_HINT_STYLE
, settings
->hintstyle
);
668 oldsettings
.hintstyle
= settings
->hintstyle
;
672 if ((settings
->seen
& SEEN_DPI
) != 0 && oldsettings
.dpi
!= settings
->dpi
673 && settings
->dpi
> 0)
675 Lisp_Object frame
, tail
;
677 FcPatternDel (pat
, FC_DPI
);
678 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
680 oldsettings
.dpi
= settings
->dpi
;
682 /* Change the DPI on this display and all frames on the display. */
683 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
684 FOR_EACH_FRAME (tail
, frame
)
685 if (FRAME_X_P (XFRAME (frame
))
686 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
687 XFRAME (frame
)->resy
= XFRAME (frame
)->resx
= settings
->dpi
;
692 static char const format
[] =
693 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
694 "Hintstyle: %d, DPI: %lf";
698 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
700 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
702 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
705 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
707 XftDefaultSet (dpyinfo
->display
, pat
);
709 store_config_changed_event (Qfont_render
,
710 XCAR (dpyinfo
->name_list_element
));
711 sprintf (buf
, format
, oldsettings
.aa
, oldsettings
.hinting
,
712 oldsettings
.rgba
, oldsettings
.lcdfilter
,
713 oldsettings
.hintstyle
, oldsettings
.dpi
);
714 Vxft_settings
= build_string (buf
);
717 FcPatternDestroy (pat
);
718 #endif /* HAVE_XFT */
721 /* Read XSettings from the display for DPYINFO.
722 If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */
725 read_and_apply_settings (struct x_display_info
*dpyinfo
, int send_event_p
)
727 struct xsettings settings
;
729 if (!read_settings (dpyinfo
, &settings
))
732 apply_xft_settings (dpyinfo
, True
, &settings
);
733 if (settings
.seen
& SEEN_TB_STYLE
)
736 store_tool_bar_style_changed (settings
.tb_style
, dpyinfo
);
738 current_tool_bar_style
= map_tool_bar_style (settings
.tb_style
);
739 xfree (settings
.tb_style
);
742 if (settings
.seen
& SEEN_FONT
)
745 store_font_name_changed (settings
.font
);
748 xfree (current_font
);
749 current_font
= xstrdup (settings
.font
);
751 xfree (settings
.font
);
756 /* Check if EVENT for the display in DPYINFO is XSettings related. */
759 xft_settings_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
761 int check_window_p
= 0;
762 int apply_settings
= 0;
767 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
772 if (event
->xclient
.message_type
== dpyinfo
->Xatom_xsettings_mgr
773 && event
->xclient
.data
.l
[1] == dpyinfo
->Xatom_xsettings_sel
774 && event
->xclient
.window
== dpyinfo
->root_window
)
779 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
780 && event
->xproperty
.state
== PropertyNewValue
781 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
789 dpyinfo
->xsettings_window
= None
;
790 get_prop_window (dpyinfo
);
791 if (dpyinfo
->xsettings_window
!= None
)
796 read_and_apply_settings (dpyinfo
, True
);
799 /* Initialize GSettings and read startup values. */
802 init_gsettings (void)
804 #ifdef HAVE_GSETTINGS
806 const gchar
*const *schemas
;
807 int schema_found
= 0;
809 #ifdef HAVE_G_TYPE_INIT
813 schemas
= g_settings_list_schemas();
814 if (schemas
== NULL
) return;
815 while (! schema_found
&& *schemas
!= NULL
)
816 schema_found
= strcmp (*schemas
++, GSETTINGS_SCHEMA
) == 0;
817 if (!schema_found
) return;
819 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
820 if (!gsettings_client
) return;
821 g_object_ref_sink (G_OBJECT (gsettings_client
));
822 g_signal_connect (G_OBJECT (gsettings_client
), "changed",
823 G_CALLBACK (something_changed_gsettingsCB
), NULL
);
825 val
= g_settings_get_value (gsettings_client
, GSETTINGS_TOOL_BAR_STYLE
);
828 g_variant_ref_sink (val
);
829 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
830 current_tool_bar_style
831 = map_tool_bar_style (g_variant_get_string (val
, NULL
));
832 g_variant_unref (val
);
836 val
= g_settings_get_value (gsettings_client
, GSETTINGS_MONO_FONT
);
839 g_variant_ref_sink (val
);
840 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
841 current_mono_font
= xstrdup (g_variant_get_string (val
, NULL
));
842 g_variant_unref (val
);
845 val
= g_settings_get_value (gsettings_client
, GSETTINGS_FONT_NAME
);
848 g_variant_ref_sink (val
);
849 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
850 current_font
= xstrdup (g_variant_get_string (val
, NULL
));
851 g_variant_unref (val
);
853 #endif /* HAVE_XFT */
855 #endif /* HAVE_GSETTINGS */
858 /* Init GConf and read startup values. */
863 #if defined (HAVE_GCONF)
866 #ifdef HAVE_G_TYPE_INIT
870 gconf_client
= gconf_client_get_default ();
871 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
872 gconf_client_add_dir (gconf_client
,
873 GCONF_TOOL_BAR_STYLE
,
874 GCONF_CLIENT_PRELOAD_ONELEVEL
,
876 gconf_client_notify_add (gconf_client
,
877 GCONF_TOOL_BAR_STYLE
,
878 something_changed_gconfCB
,
881 s
= gconf_client_get_string (gconf_client
, GCONF_TOOL_BAR_STYLE
, NULL
);
884 current_tool_bar_style
= map_tool_bar_style (s
);
889 s
= gconf_client_get_string (gconf_client
, GCONF_MONO_FONT
, NULL
);
892 current_mono_font
= xstrdup (s
);
895 s
= gconf_client_get_string (gconf_client
, GCONF_FONT_NAME
, NULL
);
898 current_font
= xstrdup (s
);
901 gconf_client_add_dir (gconf_client
,
903 GCONF_CLIENT_PRELOAD_ONELEVEL
,
905 gconf_client_notify_add (gconf_client
,
907 something_changed_gconfCB
,
909 gconf_client_add_dir (gconf_client
,
911 GCONF_CLIENT_PRELOAD_ONELEVEL
,
913 gconf_client_notify_add (gconf_client
,
915 something_changed_gconfCB
,
917 #endif /* HAVE_XFT */
918 #endif /* HAVE_GCONF */
921 /* Init Xsettings and read startup values. */
924 init_xsettings (struct x_display_info
*dpyinfo
)
926 Display
*dpy
= dpyinfo
->display
;
930 /* Select events so we can detect client messages sent when selection
932 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
934 get_prop_window (dpyinfo
);
935 if (dpyinfo
->xsettings_window
!= None
)
936 read_and_apply_settings (dpyinfo
, False
);
942 xsettings_initialize (struct x_display_info
*dpyinfo
)
944 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
946 init_xsettings (dpyinfo
);
950 /* Return the system monospaced font.
951 May be NULL if not known. */
954 xsettings_get_system_font (void)
956 return current_mono_font
;
960 /* Return the system font.
961 May be NULL if not known. */
964 xsettings_get_system_normal_font (void)
970 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
971 Sfont_get_system_normal_font
,
973 doc
: /* Get the system default application font. */)
976 return current_font
? build_string (current_font
) : Qnil
;
979 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
981 doc
: /* Get the system default fixed width font. */)
984 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
987 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
988 Stool_bar_get_system_style
, 0, 0, 0,
989 doc
: /* Get the system tool bar style.
990 If no system tool bar style is known, return `tool-bar-style' if set to a
991 known style. Otherwise return image. */)
994 if (EQ (Vtool_bar_style
, Qimage
)
995 || EQ (Vtool_bar_style
, Qtext
)
996 || EQ (Vtool_bar_style
, Qboth
)
997 || EQ (Vtool_bar_style
, Qboth_horiz
)
998 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
999 return Vtool_bar_style
;
1000 if (!NILP (current_tool_bar_style
))
1001 return current_tool_bar_style
;
1006 syms_of_xsettings (void)
1008 current_mono_font
= NULL
;
1009 current_font
= NULL
;
1010 first_dpyinfo
= NULL
;
1011 #ifdef HAVE_GSETTINGS
1012 gsettings_client
= NULL
;
1015 gconf_client
= NULL
;
1018 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
1019 DEFSYM (Qfont_name
, "font-name");
1020 DEFSYM (Qfont_render
, "font-render");
1021 defsubr (&Sfont_get_system_font
);
1022 defsubr (&Sfont_get_system_normal_font
);
1024 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
1025 doc
: /* *Non-nil means to apply the system defined font dynamically.
1026 When this is non-nil and the system defined fixed width font changes, we
1027 update frames dynamically.
1028 If this variable is nil, Emacs ignores system font changes. */);
1029 use_system_font
= 0;
1031 DEFVAR_LISP ("xft-settings", Vxft_settings
,
1032 doc
: /* Font settings applied to Xft. */);
1033 Vxft_settings
= make_string ("", 0);
1036 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
1037 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
1038 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
1042 current_tool_bar_style
= Qnil
;
1043 DEFSYM (Qtool_bar_style
, "tool-bar-style");
1044 defsubr (&Stool_bar_get_system_style
);
1046 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);