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. */
86 #if defined HAVE_XFT && (defined HAVE_GSETTINGS || defined HAVE_GCONF)
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
));
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 xfree (current_font
);
114 current_font
= xstrdup (newfont
);
116 if (dpyinfo_valid (first_dpyinfo
))
118 store_config_changed_event (Qfont_name
,
119 XCAR (first_dpyinfo
->name_list_element
));
122 #endif /* HAVE_XFT */
124 /* Map TOOL_BAR_STYLE from a string to its corresponding Lisp value.
125 Return Qnil if TOOL_BAR_STYLE is not known. */
128 map_tool_bar_style (const char *tool_bar_style
)
130 Lisp_Object style
= Qnil
;
133 if (strcmp (tool_bar_style
, "both") == 0)
135 else if (strcmp (tool_bar_style
, "both-horiz") == 0)
137 else if (strcmp (tool_bar_style
, "icons") == 0)
139 else if (strcmp (tool_bar_style
, "text") == 0)
146 /* Store a tool bar style change event if the tool bar style changed. */
149 store_tool_bar_style_changed (const char *newstyle
,
150 struct x_display_info
*dpyinfo
)
152 Lisp_Object style
= map_tool_bar_style (newstyle
);
153 if (EQ (current_tool_bar_style
, style
))
154 return; /* No change. */
156 current_tool_bar_style
= style
;
157 if (dpyinfo_valid (dpyinfo
))
158 store_config_changed_event (Qtool_bar_style
,
159 XCAR (dpyinfo
->name_list_element
));
163 #define XSETTINGS_FONT_NAME "Gtk/FontName"
164 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
170 SEEN_LCDFILTER
= 0x08,
171 SEEN_HINTSTYLE
= 0x10,
174 SEEN_TB_STYLE
= 0x80,
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 SWAP32(nr) (((nr) << 24) | (((nr) << 8) & 0xff0000) \
341 | (((nr) >> 8) & 0xff00) | ((nr) >> 24))
342 #define SWAP16(nr) (((nr) << 8) | ((nr) >> 8))
343 #define PAD(nr) (((nr) + 3) & ~3)
345 /* Parse xsettings and extract those that deal with Xft.
346 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
347 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
349 Layout of prop. First is a header:
352 ------------------------------------
358 Then N_SETTINGS records, with header:
361 ------------------------------------
362 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
364 2 CARD16 n == name-length
366 p unused, p=pad_to_even_4(n)
367 4 CARD32 last-change-serial
369 and then the value, For string:
372 ------------------------------------
373 4 CARD32 n = value-length
375 p unused, p=pad_to_even_4(n)
380 ------------------------------------
386 ------------------------------------
392 Returns non-zero if some Xft settings was seen, zero otherwise.
396 parse_settings (unsigned char *prop
,
397 long unsigned int bytes
,
398 struct xsettings
*settings
)
400 Lisp_Object byteorder
= Fbyteorder ();
401 int my_bo
= XFASTINT (byteorder
) == 'B' ? MSBFirst
: LSBFirst
;
402 int that_bo
= prop
[0];
404 int bytes_parsed
= 0;
405 int settings_seen
= 0;
408 /* First 4 bytes is a serial number, skip that. */
410 if (bytes
< 12) return BadLength
;
411 memcpy (&n_settings
, prop
+8, 4);
412 if (my_bo
!= that_bo
) n_settings
= SWAP32 (n_settings
);
415 memset (settings
, 0, sizeof (*settings
));
417 while (bytes_parsed
+4 < bytes
&& settings_seen
< 7
420 int type
= prop
[bytes_parsed
++];
422 CARD32 vlen
, ival
= 0;
423 char name
[128]; /* The names we are looking for are not this long. */
424 char sval
[128]; /* The values we are looking for are not this long. */
430 ++bytes_parsed
; /* Padding */
432 memcpy (&nlen
, prop
+bytes_parsed
, 2);
434 if (my_bo
!= that_bo
) nlen
= SWAP16 (nlen
);
435 if (bytes_parsed
+nlen
> bytes
) return BadLength
;
436 to_cpy
= nlen
> 127 ? 127 : nlen
;
437 memcpy (name
, prop
+bytes_parsed
, to_cpy
);
440 bytes_parsed
+= nlen
;
441 bytes_parsed
= PAD (bytes_parsed
);
443 bytes_parsed
+= 4; /* Skip serial for this value */
444 if (bytes_parsed
> bytes
) return BadLength
;
448 (nlen
> 6 && strncmp (name
, "Xft/", 4) == 0)
449 || strcmp (XSETTINGS_FONT_NAME
, name
) == 0
452 strcmp (XSETTINGS_TOOL_BAR_STYLE
, name
) == 0;
456 case 0: /* Integer */
457 if (bytes_parsed
+4 > bytes
) return BadLength
;
460 memcpy (&ival
, prop
+bytes_parsed
, 4);
461 if (my_bo
!= that_bo
) ival
= SWAP32 (ival
);
467 if (bytes_parsed
+4 > bytes
) return BadLength
;
468 memcpy (&vlen
, prop
+bytes_parsed
, 4);
470 if (my_bo
!= that_bo
) vlen
= SWAP32 (vlen
);
473 to_cpy
= vlen
> 127 ? 127 : vlen
;
474 memcpy (sval
, prop
+bytes_parsed
, to_cpy
);
477 bytes_parsed
+= vlen
;
478 bytes_parsed
= PAD (bytes_parsed
);
481 case 2: /* RGB value */
482 /* No need to parse this */
483 if (bytes_parsed
+8 > bytes
) return BadLength
;
484 bytes_parsed
+= 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
487 default: /* Parse Error */
494 if (strcmp (name
, XSETTINGS_TOOL_BAR_STYLE
) == 0)
496 settings
->tb_style
= xstrdup (sval
);
497 settings
->seen
|= SEEN_TB_STYLE
;
500 else if (strcmp (name
, XSETTINGS_FONT_NAME
) == 0)
502 settings
->font
= xstrdup (sval
);
503 settings
->seen
|= SEEN_FONT
;
505 else if (strcmp (name
, "Xft/Antialias") == 0)
507 settings
->seen
|= SEEN_AA
;
508 settings
->aa
= ival
!= 0;
510 else if (strcmp (name
, "Xft/Hinting") == 0)
512 settings
->seen
|= SEEN_HINTING
;
513 settings
->hinting
= ival
!= 0;
515 # ifdef FC_HINT_STYLE
516 else if (strcmp (name
, "Xft/HintStyle") == 0)
518 settings
->seen
|= SEEN_HINTSTYLE
;
519 if (strcmp (sval
, "hintnone") == 0)
520 settings
->hintstyle
= FC_HINT_NONE
;
521 else if (strcmp (sval
, "hintslight") == 0)
522 settings
->hintstyle
= FC_HINT_SLIGHT
;
523 else if (strcmp (sval
, "hintmedium") == 0)
524 settings
->hintstyle
= FC_HINT_MEDIUM
;
525 else if (strcmp (sval
, "hintfull") == 0)
526 settings
->hintstyle
= FC_HINT_FULL
;
528 settings
->seen
&= ~SEEN_HINTSTYLE
;
531 else if (strcmp (name
, "Xft/RGBA") == 0)
533 settings
->seen
|= SEEN_RGBA
;
534 if (strcmp (sval
, "none") == 0)
535 settings
->rgba
= FC_RGBA_NONE
;
536 else if (strcmp (sval
, "rgb") == 0)
537 settings
->rgba
= FC_RGBA_RGB
;
538 else if (strcmp (sval
, "bgr") == 0)
539 settings
->rgba
= FC_RGBA_BGR
;
540 else if (strcmp (sval
, "vrgb") == 0)
541 settings
->rgba
= FC_RGBA_VRGB
;
542 else if (strcmp (sval
, "vbgr") == 0)
543 settings
->rgba
= FC_RGBA_VBGR
;
545 settings
->seen
&= ~SEEN_RGBA
;
547 else if (strcmp (name
, "Xft/DPI") == 0)
549 settings
->seen
|= SEEN_DPI
;
550 settings
->dpi
= (double)ival
/1024.0;
552 else if (strcmp (name
, "Xft/lcdfilter") == 0)
554 settings
->seen
|= SEEN_LCDFILTER
;
555 if (strcmp (sval
, "none") == 0)
556 settings
->lcdfilter
= FC_LCD_NONE
;
557 else if (strcmp (sval
, "lcddefault") == 0)
558 settings
->lcdfilter
= FC_LCD_DEFAULT
;
560 settings
->seen
&= ~SEEN_LCDFILTER
;
562 #endif /* HAVE_XFT */
566 return settings_seen
;
569 /* Read settings from the XSettings property window on display for DPYINFO.
570 Store settings read in SETTINGS.
571 Return non-zero if successful, zero if not. */
574 read_settings (struct x_display_info
*dpyinfo
, struct xsettings
*settings
)
578 unsigned long nitems
, bytes_after
;
579 unsigned char *prop
= NULL
;
580 Display
*dpy
= dpyinfo
->display
;
583 x_catch_errors (dpy
);
584 rc
= XGetWindowProperty (dpy
,
585 dpyinfo
->xsettings_window
,
586 dpyinfo
->Xatom_xsettings_prop
,
587 0, LONG_MAX
, False
, AnyPropertyType
,
588 &act_type
, &act_form
, &nitems
, &bytes_after
,
591 if (rc
== Success
&& prop
!= NULL
&& act_form
== 8 && nitems
> 0
592 && act_type
== dpyinfo
->Xatom_xsettings_prop
)
593 rc
= parse_settings (prop
, nitems
, settings
);
602 /* Apply Xft settings in SETTINGS to the Xft library.
603 If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */
606 apply_xft_settings (struct x_display_info
*dpyinfo
,
608 struct xsettings
*settings
)
612 struct xsettings oldsettings
;
615 memset (&oldsettings
, 0, sizeof (oldsettings
));
616 pat
= FcPatternCreate ();
617 XftDefaultSubstitute (dpyinfo
->display
,
618 XScreenNumberOfScreen (dpyinfo
->screen
),
620 FcPatternGetBool (pat
, FC_ANTIALIAS
, 0, &oldsettings
.aa
);
621 FcPatternGetBool (pat
, FC_HINTING
, 0, &oldsettings
.hinting
);
623 FcPatternGetInteger (pat
, FC_HINT_STYLE
, 0, &oldsettings
.hintstyle
);
625 FcPatternGetInteger (pat
, FC_LCD_FILTER
, 0, &oldsettings
.lcdfilter
);
626 FcPatternGetInteger (pat
, FC_RGBA
, 0, &oldsettings
.rgba
);
627 FcPatternGetDouble (pat
, FC_DPI
, 0, &oldsettings
.dpi
);
629 if ((settings
->seen
& SEEN_AA
) != 0 && oldsettings
.aa
!= settings
->aa
)
631 FcPatternDel (pat
, FC_ANTIALIAS
);
632 FcPatternAddBool (pat
, FC_ANTIALIAS
, settings
->aa
);
634 oldsettings
.aa
= settings
->aa
;
637 if ((settings
->seen
& SEEN_HINTING
) != 0
638 && oldsettings
.hinting
!= settings
->hinting
)
640 FcPatternDel (pat
, FC_HINTING
);
641 FcPatternAddBool (pat
, FC_HINTING
, settings
->hinting
);
643 oldsettings
.hinting
= settings
->hinting
;
645 if ((settings
->seen
& SEEN_RGBA
) != 0 && oldsettings
.rgba
!= settings
->rgba
)
647 FcPatternDel (pat
, FC_RGBA
);
648 FcPatternAddInteger (pat
, FC_RGBA
, settings
->rgba
);
649 oldsettings
.rgba
= settings
->rgba
;
653 /* Older fontconfig versions don't have FC_LCD_FILTER. */
654 if ((settings
->seen
& SEEN_LCDFILTER
) != 0
655 && oldsettings
.lcdfilter
!= settings
->lcdfilter
)
657 FcPatternDel (pat
, FC_LCD_FILTER
);
658 FcPatternAddInteger (pat
, FC_LCD_FILTER
, settings
->lcdfilter
);
660 oldsettings
.lcdfilter
= settings
->lcdfilter
;
664 if ((settings
->seen
& SEEN_HINTSTYLE
) != 0
665 && oldsettings
.hintstyle
!= settings
->hintstyle
)
667 FcPatternDel (pat
, FC_HINT_STYLE
);
668 FcPatternAddInteger (pat
, FC_HINT_STYLE
, settings
->hintstyle
);
670 oldsettings
.hintstyle
= settings
->hintstyle
;
674 if ((settings
->seen
& SEEN_DPI
) != 0 && oldsettings
.dpi
!= settings
->dpi
675 && settings
->dpi
> 0)
677 Lisp_Object frame
, tail
;
679 FcPatternDel (pat
, FC_DPI
);
680 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
682 oldsettings
.dpi
= settings
->dpi
;
684 /* Change the DPI on this display and all frames on the display. */
685 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
686 FOR_EACH_FRAME (tail
, frame
)
687 if (FRAME_X_P (XFRAME (frame
))
688 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
689 XFRAME (frame
)->resy
= XFRAME (frame
)->resx
= settings
->dpi
;
694 static char const format
[] =
695 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
696 "Hintstyle: %d, DPI: %lf";
700 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
702 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
704 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
707 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
709 XftDefaultSet (dpyinfo
->display
, pat
);
711 store_config_changed_event (Qfont_render
,
712 XCAR (dpyinfo
->name_list_element
));
713 sprintf (buf
, format
, oldsettings
.aa
, oldsettings
.hinting
,
714 oldsettings
.rgba
, oldsettings
.lcdfilter
,
715 oldsettings
.hintstyle
, oldsettings
.dpi
);
716 Vxft_settings
= build_string (buf
);
719 FcPatternDestroy (pat
);
720 #endif /* HAVE_XFT */
723 /* Read XSettings from the display for DPYINFO.
724 If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */
727 read_and_apply_settings (struct x_display_info
*dpyinfo
, int send_event_p
)
729 struct xsettings settings
;
731 if (!read_settings (dpyinfo
, &settings
))
734 apply_xft_settings (dpyinfo
, True
, &settings
);
735 if (settings
.seen
& SEEN_TB_STYLE
)
738 store_tool_bar_style_changed (settings
.tb_style
, dpyinfo
);
740 current_tool_bar_style
= map_tool_bar_style (settings
.tb_style
);
741 xfree (settings
.tb_style
);
744 if (settings
.seen
& SEEN_FONT
)
747 store_font_name_changed (settings
.font
);
750 xfree (current_font
);
751 current_font
= xstrdup (settings
.font
);
753 xfree (settings
.font
);
758 /* Check if EVENT for the display in DPYINFO is XSettings related. */
761 xft_settings_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
763 int check_window_p
= 0;
764 int apply_settings
= 0;
769 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
774 if (event
->xclient
.message_type
== dpyinfo
->Xatom_xsettings_mgr
775 && event
->xclient
.data
.l
[1] == dpyinfo
->Xatom_xsettings_sel
776 && event
->xclient
.window
== dpyinfo
->root_window
)
781 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
782 && event
->xproperty
.state
== PropertyNewValue
783 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
791 dpyinfo
->xsettings_window
= None
;
792 get_prop_window (dpyinfo
);
793 if (dpyinfo
->xsettings_window
!= None
)
798 read_and_apply_settings (dpyinfo
, True
);
801 /* Initialize GSettings and read startup values. */
804 init_gsettings (void)
806 #ifdef HAVE_GSETTINGS
808 const gchar
*const *schemas
;
809 int schema_found
= 0;
811 #ifdef HAVE_G_TYPE_INIT
815 schemas
= g_settings_list_schemas ();
816 if (schemas
== NULL
) return;
817 while (! schema_found
&& *schemas
!= NULL
)
818 schema_found
= strcmp (*schemas
++, GSETTINGS_SCHEMA
) == 0;
819 if (!schema_found
) return;
821 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
822 if (!gsettings_client
) return;
823 g_object_ref_sink (G_OBJECT (gsettings_client
));
824 g_signal_connect (G_OBJECT (gsettings_client
), "changed",
825 G_CALLBACK (something_changed_gsettingsCB
), NULL
);
827 val
= g_settings_get_value (gsettings_client
, GSETTINGS_TOOL_BAR_STYLE
);
830 g_variant_ref_sink (val
);
831 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
832 current_tool_bar_style
833 = map_tool_bar_style (g_variant_get_string (val
, NULL
));
834 g_variant_unref (val
);
838 val
= g_settings_get_value (gsettings_client
, GSETTINGS_MONO_FONT
);
841 g_variant_ref_sink (val
);
842 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
843 current_mono_font
= xstrdup (g_variant_get_string (val
, NULL
));
844 g_variant_unref (val
);
847 val
= g_settings_get_value (gsettings_client
, GSETTINGS_FONT_NAME
);
850 g_variant_ref_sink (val
);
851 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
852 current_font
= xstrdup (g_variant_get_string (val
, NULL
));
853 g_variant_unref (val
);
855 #endif /* HAVE_XFT */
857 #endif /* HAVE_GSETTINGS */
860 /* Init GConf and read startup values. */
865 #if defined (HAVE_GCONF)
868 #ifdef HAVE_G_TYPE_INIT
872 gconf_client
= gconf_client_get_default ();
873 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
874 gconf_client_add_dir (gconf_client
,
875 GCONF_TOOL_BAR_STYLE
,
876 GCONF_CLIENT_PRELOAD_ONELEVEL
,
878 gconf_client_notify_add (gconf_client
,
879 GCONF_TOOL_BAR_STYLE
,
880 something_changed_gconfCB
,
883 s
= gconf_client_get_string (gconf_client
, GCONF_TOOL_BAR_STYLE
, NULL
);
886 current_tool_bar_style
= map_tool_bar_style (s
);
891 s
= gconf_client_get_string (gconf_client
, GCONF_MONO_FONT
, NULL
);
894 current_mono_font
= xstrdup (s
);
897 s
= gconf_client_get_string (gconf_client
, GCONF_FONT_NAME
, NULL
);
900 current_font
= xstrdup (s
);
903 gconf_client_add_dir (gconf_client
,
905 GCONF_CLIENT_PRELOAD_ONELEVEL
,
907 gconf_client_notify_add (gconf_client
,
909 something_changed_gconfCB
,
911 gconf_client_add_dir (gconf_client
,
913 GCONF_CLIENT_PRELOAD_ONELEVEL
,
915 gconf_client_notify_add (gconf_client
,
917 something_changed_gconfCB
,
919 #endif /* HAVE_XFT */
920 #endif /* HAVE_GCONF */
923 /* Init Xsettings and read startup values. */
926 init_xsettings (struct x_display_info
*dpyinfo
)
928 Display
*dpy
= dpyinfo
->display
;
932 /* Select events so we can detect client messages sent when selection
934 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
936 get_prop_window (dpyinfo
);
937 if (dpyinfo
->xsettings_window
!= None
)
938 read_and_apply_settings (dpyinfo
, False
);
944 xsettings_initialize (struct x_display_info
*dpyinfo
)
946 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
948 init_xsettings (dpyinfo
);
952 /* Return the system monospaced font.
953 May be NULL if not known. */
956 xsettings_get_system_font (void)
958 return current_mono_font
;
962 /* Return the system font.
963 May be NULL if not known. */
966 xsettings_get_system_normal_font (void)
972 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
973 Sfont_get_system_normal_font
,
975 doc
: /* Get the system default application font. */)
978 return current_font
? build_string (current_font
) : Qnil
;
981 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
983 doc
: /* Get the system default fixed width font. */)
986 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
989 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
990 Stool_bar_get_system_style
, 0, 0, 0,
991 doc
: /* Get the system tool bar style.
992 If no system tool bar style is known, return `tool-bar-style' if set to a
993 known style. Otherwise return image. */)
996 if (EQ (Vtool_bar_style
, Qimage
)
997 || EQ (Vtool_bar_style
, Qtext
)
998 || EQ (Vtool_bar_style
, Qboth
)
999 || EQ (Vtool_bar_style
, Qboth_horiz
)
1000 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
1001 return Vtool_bar_style
;
1002 if (!NILP (current_tool_bar_style
))
1003 return current_tool_bar_style
;
1008 syms_of_xsettings (void)
1010 current_mono_font
= NULL
;
1011 current_font
= NULL
;
1012 first_dpyinfo
= NULL
;
1013 #ifdef HAVE_GSETTINGS
1014 gsettings_client
= NULL
;
1017 gconf_client
= NULL
;
1020 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
1021 DEFSYM (Qfont_name
, "font-name");
1022 DEFSYM (Qfont_render
, "font-render");
1023 defsubr (&Sfont_get_system_font
);
1024 defsubr (&Sfont_get_system_normal_font
);
1026 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
1027 doc
: /* *Non-nil means to apply the system defined font dynamically.
1028 When this is non-nil and the system defined fixed width font changes, we
1029 update frames dynamically.
1030 If this variable is nil, Emacs ignores system font changes. */);
1031 use_system_font
= 0;
1033 DEFVAR_LISP ("xft-settings", Vxft_settings
,
1034 doc
: /* Font settings applied to Xft. */);
1035 Vxft_settings
= make_string ("", 0);
1038 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
1039 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
1040 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
1044 current_tool_bar_style
= Qnil
;
1045 DEFSYM (Qtool_bar_style
, "tool-bar-style");
1046 defsubr (&Stool_bar_get_system_style
);
1048 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);