1 /* Functions for handling font and other changes dynamically.
3 Copyright (C) 2009-2012 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"
165 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
171 SEEN_LCDFILTER
= 0x08,
172 SEEN_HINTSTYLE
= 0x10,
175 SEEN_TB_STYLE
= 0x80,
181 int rgba
, lcdfilter
, hintstyle
;
192 #ifdef HAVE_GSETTINGS
193 #define GSETTINGS_SCHEMA "org.gnome.desktop.interface"
194 #define GSETTINGS_TOOL_BAR_STYLE "toolbar-style"
197 #define GSETTINGS_MONO_FONT "monospace-font-name"
198 #define GSETTINGS_FONT_NAME "font-name"
202 /* The single GSettings instance, or NULL if not connected to GSettings. */
204 static GSettings
*gsettings_client
;
206 /* Callback called when something changed in GSettings. */
209 something_changed_gsettingsCB (GSettings
*settings
,
215 if (strcmp (key
, GSETTINGS_TOOL_BAR_STYLE
) == 0)
217 val
= g_settings_get_value (settings
, GSETTINGS_TOOL_BAR_STYLE
);
220 g_variant_ref_sink (val
);
221 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
223 const gchar
*newstyle
= g_variant_get_string (val
, NULL
);
224 store_tool_bar_style_changed (newstyle
, first_dpyinfo
);
226 g_variant_unref (val
);
230 else if (strcmp (key
, GSETTINGS_MONO_FONT
) == 0)
232 val
= g_settings_get_value (settings
, GSETTINGS_MONO_FONT
);
235 g_variant_ref_sink (val
);
236 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
238 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
239 store_monospaced_changed (newfont
);
241 g_variant_unref (val
);
244 else if (strcmp (key
, GSETTINGS_FONT_NAME
) == 0)
246 val
= g_settings_get_value (settings
, GSETTINGS_FONT_NAME
);
249 g_variant_ref_sink (val
);
250 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
252 const gchar
*newfont
= g_variant_get_string (val
, NULL
);
253 store_font_name_changed (newfont
);
255 g_variant_unref (val
);
258 #endif /* HAVE_XFT */
261 #endif /* HAVE_GSETTINGS */
264 #define GCONF_TOOL_BAR_STYLE "/desktop/gnome/interface/toolbar_style"
266 #define GCONF_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
267 #define GCONF_FONT_NAME "/desktop/gnome/interface/font_name"
270 /* The single GConf instance, or NULL if not connected to GConf. */
272 static GConfClient
*gconf_client
;
274 /* Callback called when something changed in GConf that we care about. */
277 something_changed_gconfCB (GConfClient
*client
,
282 GConfValue
*v
= gconf_entry_get_value (entry
);
283 const char *key
= gconf_entry_get_key (entry
);
285 if (!v
|| v
->type
!= GCONF_VALUE_STRING
|| ! key
) return;
286 if (strcmp (key
, GCONF_TOOL_BAR_STYLE
) == 0)
288 const char *value
= gconf_value_get_string (v
);
289 store_tool_bar_style_changed (value
, first_dpyinfo
);
292 else if (strcmp (key
, GCONF_MONO_FONT
) == 0)
294 const char *value
= gconf_value_get_string (v
);
295 store_monospaced_changed (value
);
297 else if (strcmp (key
, GCONF_FONT_NAME
) == 0)
299 const char *value
= gconf_value_get_string (v
);
300 store_font_name_changed (value
);
302 #endif /* HAVE_XFT */
305 #endif /* HAVE_GCONF */
309 /* Older fontconfig versions don't have FC_LCD_*. */
311 #define FC_LCD_NONE 0
313 #ifndef FC_LCD_DEFAULT
314 #define FC_LCD_DEFAULT 1
316 #ifndef FC_LCD_FILTER
317 #define FC_LCD_FILTER "lcdfilter"
320 #endif /* HAVE_XFT */
322 /* Find the window that contains the XSETTINGS property values. */
325 get_prop_window (struct x_display_info
*dpyinfo
)
327 Display
*dpy
= dpyinfo
->display
;
330 dpyinfo
->xsettings_window
= XGetSelectionOwner (dpy
,
331 dpyinfo
->Xatom_xsettings_sel
);
332 if (dpyinfo
->xsettings_window
!= None
)
333 /* Select events so we can detect if window is deleted or if settings
335 XSelectInput (dpy
, dpyinfo
->xsettings_window
,
336 PropertyChangeMask
|StructureNotifyMask
);
341 #define SWAP32(nr) (((nr) << 24) | (((nr) << 8) & 0xff0000) \
342 | (((nr) >> 8) & 0xff00) | ((nr) >> 24))
343 #define SWAP16(nr) (((nr) << 8) | ((nr) >> 8))
344 #define PAD(nr) (((nr) + 3) & ~3)
346 /* Parse xsettings and extract those that deal with Xft.
347 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
348 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
350 Layout of prop. First is a header:
353 ------------------------------------
359 Then N_SETTINGS records, with header:
362 ------------------------------------
363 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
365 2 CARD16 n == name-length
367 p unused, p=pad_to_even_4(n)
368 4 CARD32 last-change-serial
370 and then the value, For string:
373 ------------------------------------
374 4 CARD32 n = value-length
376 p unused, p=pad_to_even_4(n)
381 ------------------------------------
387 ------------------------------------
393 Returns non-zero if some Xft settings was seen, zero otherwise.
397 parse_settings (unsigned char *prop
,
398 long unsigned int bytes
,
399 struct xsettings
*settings
)
401 Lisp_Object byteorder
= Fbyteorder ();
402 int my_bo
= XFASTINT (byteorder
) == 'B' ? MSBFirst
: LSBFirst
;
403 int that_bo
= prop
[0];
405 int bytes_parsed
= 0;
406 int settings_seen
= 0;
409 /* First 4 bytes is a serial number, skip that. */
411 if (bytes
< 12) return BadLength
;
412 memcpy (&n_settings
, prop
+8, 4);
413 if (my_bo
!= that_bo
) n_settings
= SWAP32 (n_settings
);
416 memset (settings
, 0, sizeof (*settings
));
418 while (bytes_parsed
+4 < bytes
&& settings_seen
< 7
421 int type
= prop
[bytes_parsed
++];
423 CARD32 vlen
, ival
= 0;
424 char name
[128]; /* The names we are looking for are not this long. */
425 char sval
[128]; /* The values we are looking for are not this long. */
431 ++bytes_parsed
; /* Padding */
433 memcpy (&nlen
, prop
+bytes_parsed
, 2);
435 if (my_bo
!= that_bo
) nlen
= SWAP16 (nlen
);
436 if (bytes_parsed
+nlen
> bytes
) return BadLength
;
437 to_cpy
= nlen
> 127 ? 127 : nlen
;
438 memcpy (name
, prop
+bytes_parsed
, to_cpy
);
441 bytes_parsed
+= nlen
;
442 bytes_parsed
= PAD (bytes_parsed
);
444 bytes_parsed
+= 4; /* Skip serial for this value */
445 if (bytes_parsed
> bytes
) return BadLength
;
449 (nlen
> 6 && strncmp (name
, "Xft/", 4) == 0)
450 || strcmp (XSETTINGS_FONT_NAME
, name
) == 0
453 strcmp (XSETTINGS_TOOL_BAR_STYLE
, name
) == 0;
457 case 0: /* Integer */
458 if (bytes_parsed
+4 > bytes
) return BadLength
;
461 memcpy (&ival
, prop
+bytes_parsed
, 4);
462 if (my_bo
!= that_bo
) ival
= SWAP32 (ival
);
468 if (bytes_parsed
+4 > bytes
) return BadLength
;
469 memcpy (&vlen
, prop
+bytes_parsed
, 4);
471 if (my_bo
!= that_bo
) vlen
= SWAP32 (vlen
);
474 to_cpy
= vlen
> 127 ? 127 : vlen
;
475 memcpy (sval
, prop
+bytes_parsed
, to_cpy
);
478 bytes_parsed
+= vlen
;
479 bytes_parsed
= PAD (bytes_parsed
);
482 case 2: /* RGB value */
483 /* No need to parse this */
484 if (bytes_parsed
+8 > bytes
) return BadLength
;
485 bytes_parsed
+= 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
488 default: /* Parse Error */
495 if (strcmp (name
, XSETTINGS_TOOL_BAR_STYLE
) == 0)
497 settings
->tb_style
= xstrdup (sval
);
498 settings
->seen
|= SEEN_TB_STYLE
;
501 else if (strcmp (name
, XSETTINGS_FONT_NAME
) == 0)
503 settings
->font
= xstrdup (sval
);
504 settings
->seen
|= SEEN_FONT
;
506 else if (strcmp (name
, "Xft/Antialias") == 0)
508 settings
->seen
|= SEEN_AA
;
509 settings
->aa
= ival
!= 0;
511 else if (strcmp (name
, "Xft/Hinting") == 0)
513 settings
->seen
|= SEEN_HINTING
;
514 settings
->hinting
= ival
!= 0;
516 # ifdef FC_HINT_STYLE
517 else if (strcmp (name
, "Xft/HintStyle") == 0)
519 settings
->seen
|= SEEN_HINTSTYLE
;
520 if (strcmp (sval
, "hintnone") == 0)
521 settings
->hintstyle
= FC_HINT_NONE
;
522 else if (strcmp (sval
, "hintslight") == 0)
523 settings
->hintstyle
= FC_HINT_SLIGHT
;
524 else if (strcmp (sval
, "hintmedium") == 0)
525 settings
->hintstyle
= FC_HINT_MEDIUM
;
526 else if (strcmp (sval
, "hintfull") == 0)
527 settings
->hintstyle
= FC_HINT_FULL
;
529 settings
->seen
&= ~SEEN_HINTSTYLE
;
532 else if (strcmp (name
, "Xft/RGBA") == 0)
534 settings
->seen
|= SEEN_RGBA
;
535 if (strcmp (sval
, "none") == 0)
536 settings
->rgba
= FC_RGBA_NONE
;
537 else if (strcmp (sval
, "rgb") == 0)
538 settings
->rgba
= FC_RGBA_RGB
;
539 else if (strcmp (sval
, "bgr") == 0)
540 settings
->rgba
= FC_RGBA_BGR
;
541 else if (strcmp (sval
, "vrgb") == 0)
542 settings
->rgba
= FC_RGBA_VRGB
;
543 else if (strcmp (sval
, "vbgr") == 0)
544 settings
->rgba
= FC_RGBA_VBGR
;
546 settings
->seen
&= ~SEEN_RGBA
;
548 else if (strcmp (name
, "Xft/DPI") == 0)
550 settings
->seen
|= SEEN_DPI
;
551 settings
->dpi
= (double)ival
/1024.0;
553 else if (strcmp (name
, "Xft/lcdfilter") == 0)
555 settings
->seen
|= SEEN_LCDFILTER
;
556 if (strcmp (sval
, "none") == 0)
557 settings
->lcdfilter
= FC_LCD_NONE
;
558 else if (strcmp (sval
, "lcddefault") == 0)
559 settings
->lcdfilter
= FC_LCD_DEFAULT
;
561 settings
->seen
&= ~SEEN_LCDFILTER
;
563 #endif /* HAVE_XFT */
567 return settings_seen
;
570 /* Read settings from the XSettings property window on display for DPYINFO.
571 Store settings read in SETTINGS.
572 Return non-zero if successful, zero if not. */
575 read_settings (struct x_display_info
*dpyinfo
, struct xsettings
*settings
)
579 unsigned long nitems
, bytes_after
;
580 unsigned char *prop
= NULL
;
581 Display
*dpy
= dpyinfo
->display
;
584 x_catch_errors (dpy
);
585 rc
= XGetWindowProperty (dpy
,
586 dpyinfo
->xsettings_window
,
587 dpyinfo
->Xatom_xsettings_prop
,
588 0, LONG_MAX
, False
, AnyPropertyType
,
589 &act_type
, &act_form
, &nitems
, &bytes_after
,
592 if (rc
== Success
&& prop
!= NULL
&& act_form
== 8 && nitems
> 0
593 && act_type
== dpyinfo
->Xatom_xsettings_prop
)
594 rc
= parse_settings (prop
, nitems
, settings
);
603 /* Apply Xft settings in SETTINGS to the Xft library.
604 If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */
607 apply_xft_settings (struct x_display_info
*dpyinfo
,
609 struct xsettings
*settings
)
613 struct xsettings oldsettings
;
616 memset (&oldsettings
, 0, sizeof (oldsettings
));
617 pat
= FcPatternCreate ();
618 XftDefaultSubstitute (dpyinfo
->display
,
619 XScreenNumberOfScreen (dpyinfo
->screen
),
621 FcPatternGetBool (pat
, FC_ANTIALIAS
, 0, &oldsettings
.aa
);
622 FcPatternGetBool (pat
, FC_HINTING
, 0, &oldsettings
.hinting
);
624 FcPatternGetInteger (pat
, FC_HINT_STYLE
, 0, &oldsettings
.hintstyle
);
626 FcPatternGetInteger (pat
, FC_LCD_FILTER
, 0, &oldsettings
.lcdfilter
);
627 FcPatternGetInteger (pat
, FC_RGBA
, 0, &oldsettings
.rgba
);
628 FcPatternGetDouble (pat
, FC_DPI
, 0, &oldsettings
.dpi
);
630 if ((settings
->seen
& SEEN_AA
) != 0 && oldsettings
.aa
!= settings
->aa
)
632 FcPatternDel (pat
, FC_ANTIALIAS
);
633 FcPatternAddBool (pat
, FC_ANTIALIAS
, settings
->aa
);
635 oldsettings
.aa
= settings
->aa
;
638 if ((settings
->seen
& SEEN_HINTING
) != 0
639 && oldsettings
.hinting
!= settings
->hinting
)
641 FcPatternDel (pat
, FC_HINTING
);
642 FcPatternAddBool (pat
, FC_HINTING
, settings
->hinting
);
644 oldsettings
.hinting
= settings
->hinting
;
646 if ((settings
->seen
& SEEN_RGBA
) != 0 && oldsettings
.rgba
!= settings
->rgba
)
648 FcPatternDel (pat
, FC_RGBA
);
649 FcPatternAddInteger (pat
, FC_RGBA
, settings
->rgba
);
650 oldsettings
.rgba
= settings
->rgba
;
654 /* Older fontconfig versions don't have FC_LCD_FILTER. */
655 if ((settings
->seen
& SEEN_LCDFILTER
) != 0
656 && oldsettings
.lcdfilter
!= settings
->lcdfilter
)
658 FcPatternDel (pat
, FC_LCD_FILTER
);
659 FcPatternAddInteger (pat
, FC_LCD_FILTER
, settings
->lcdfilter
);
661 oldsettings
.lcdfilter
= settings
->lcdfilter
;
665 if ((settings
->seen
& SEEN_HINTSTYLE
) != 0
666 && oldsettings
.hintstyle
!= settings
->hintstyle
)
668 FcPatternDel (pat
, FC_HINT_STYLE
);
669 FcPatternAddInteger (pat
, FC_HINT_STYLE
, settings
->hintstyle
);
671 oldsettings
.hintstyle
= settings
->hintstyle
;
675 if ((settings
->seen
& SEEN_DPI
) != 0 && oldsettings
.dpi
!= settings
->dpi
676 && settings
->dpi
> 0)
678 Lisp_Object frame
, tail
;
680 FcPatternDel (pat
, FC_DPI
);
681 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
683 oldsettings
.dpi
= settings
->dpi
;
685 /* Change the DPI on this display and all frames on the display. */
686 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
687 FOR_EACH_FRAME (tail
, frame
)
688 if (FRAME_X_P (XFRAME (frame
))
689 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
690 XFRAME (frame
)->resy
= XFRAME (frame
)->resx
= settings
->dpi
;
695 static char const format
[] =
696 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
697 "Hintstyle: %d, DPI: %lf";
701 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
703 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
705 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
708 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
710 XftDefaultSet (dpyinfo
->display
, pat
);
712 store_config_changed_event (Qfont_render
,
713 XCAR (dpyinfo
->name_list_element
));
715 = make_formatted_string (buf
, format
,
716 oldsettings
.aa
, oldsettings
.hinting
,
717 oldsettings
.rgba
, oldsettings
.lcdfilter
,
718 oldsettings
.hintstyle
, oldsettings
.dpi
);
722 FcPatternDestroy (pat
);
723 #endif /* HAVE_XFT */
726 /* Read XSettings from the display for DPYINFO.
727 If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */
730 read_and_apply_settings (struct x_display_info
*dpyinfo
, int send_event_p
)
732 struct xsettings settings
;
734 if (!read_settings (dpyinfo
, &settings
))
737 apply_xft_settings (dpyinfo
, True
, &settings
);
738 if (settings
.seen
& SEEN_TB_STYLE
)
741 store_tool_bar_style_changed (settings
.tb_style
, dpyinfo
);
743 current_tool_bar_style
= map_tool_bar_style (settings
.tb_style
);
744 xfree (settings
.tb_style
);
747 if (settings
.seen
& SEEN_FONT
)
750 store_font_name_changed (settings
.font
);
753 xfree (current_font
);
754 current_font
= xstrdup (settings
.font
);
756 xfree (settings
.font
);
761 /* Check if EVENT for the display in DPYINFO is XSettings related. */
764 xft_settings_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
766 int check_window_p
= 0;
767 int apply_settings
= 0;
772 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
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
)
784 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
785 && event
->xproperty
.state
== PropertyNewValue
786 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
794 dpyinfo
->xsettings_window
= None
;
795 get_prop_window (dpyinfo
);
796 if (dpyinfo
->xsettings_window
!= None
)
801 read_and_apply_settings (dpyinfo
, True
);
804 /* Initialize GSettings and read startup values. */
807 init_gsettings (void)
809 #ifdef HAVE_GSETTINGS
811 const gchar
*const *schemas
;
812 int schema_found
= 0;
814 #ifdef HAVE_G_TYPE_INIT
818 schemas
= g_settings_list_schemas ();
819 if (schemas
== NULL
) return;
820 while (! schema_found
&& *schemas
!= NULL
)
821 schema_found
= strcmp (*schemas
++, GSETTINGS_SCHEMA
) == 0;
822 if (!schema_found
) return;
824 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
825 if (!gsettings_client
) return;
826 g_object_ref_sink (G_OBJECT (gsettings_client
));
827 g_signal_connect (G_OBJECT (gsettings_client
), "changed",
828 G_CALLBACK (something_changed_gsettingsCB
), NULL
);
830 val
= g_settings_get_value (gsettings_client
, GSETTINGS_TOOL_BAR_STYLE
);
833 g_variant_ref_sink (val
);
834 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
835 current_tool_bar_style
836 = map_tool_bar_style (g_variant_get_string (val
, NULL
));
837 g_variant_unref (val
);
841 val
= g_settings_get_value (gsettings_client
, GSETTINGS_MONO_FONT
);
844 g_variant_ref_sink (val
);
845 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
846 current_mono_font
= xstrdup (g_variant_get_string (val
, NULL
));
847 g_variant_unref (val
);
850 val
= g_settings_get_value (gsettings_client
, GSETTINGS_FONT_NAME
);
853 g_variant_ref_sink (val
);
854 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
855 current_font
= xstrdup (g_variant_get_string (val
, NULL
));
856 g_variant_unref (val
);
858 #endif /* HAVE_XFT */
860 #endif /* HAVE_GSETTINGS */
863 /* Init GConf and read startup values. */
868 #if defined (HAVE_GCONF)
871 #ifdef HAVE_G_TYPE_INIT
875 gconf_client
= gconf_client_get_default ();
876 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
877 gconf_client_add_dir (gconf_client
,
878 GCONF_TOOL_BAR_STYLE
,
879 GCONF_CLIENT_PRELOAD_ONELEVEL
,
881 gconf_client_notify_add (gconf_client
,
882 GCONF_TOOL_BAR_STYLE
,
883 something_changed_gconfCB
,
886 s
= gconf_client_get_string (gconf_client
, GCONF_TOOL_BAR_STYLE
, NULL
);
889 current_tool_bar_style
= map_tool_bar_style (s
);
894 s
= gconf_client_get_string (gconf_client
, GCONF_MONO_FONT
, NULL
);
897 current_mono_font
= xstrdup (s
);
900 s
= gconf_client_get_string (gconf_client
, GCONF_FONT_NAME
, NULL
);
903 current_font
= xstrdup (s
);
906 gconf_client_add_dir (gconf_client
,
908 GCONF_CLIENT_PRELOAD_ONELEVEL
,
910 gconf_client_notify_add (gconf_client
,
912 something_changed_gconfCB
,
914 gconf_client_add_dir (gconf_client
,
916 GCONF_CLIENT_PRELOAD_ONELEVEL
,
918 gconf_client_notify_add (gconf_client
,
920 something_changed_gconfCB
,
922 #endif /* HAVE_XFT */
923 #endif /* HAVE_GCONF */
926 /* Init Xsettings and read startup values. */
929 init_xsettings (struct x_display_info
*dpyinfo
)
931 Display
*dpy
= dpyinfo
->display
;
935 /* Select events so we can detect client messages sent when selection
937 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
939 get_prop_window (dpyinfo
);
940 if (dpyinfo
->xsettings_window
!= None
)
941 read_and_apply_settings (dpyinfo
, False
);
947 xsettings_initialize (struct x_display_info
*dpyinfo
)
949 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
951 init_xsettings (dpyinfo
);
955 /* Return the system monospaced font.
956 May be NULL if not known. */
959 xsettings_get_system_font (void)
961 return current_mono_font
;
965 /* Return the system font.
966 May be NULL if not known. */
969 xsettings_get_system_normal_font (void)
975 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
976 Sfont_get_system_normal_font
,
978 doc
: /* Get the system default application font. */)
981 return current_font
? build_string (current_font
) : Qnil
;
984 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
986 doc
: /* Get the system default fixed width font. */)
989 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
992 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
993 Stool_bar_get_system_style
, 0, 0, 0,
994 doc
: /* Get the system tool bar style.
995 If no system tool bar style is known, return `tool-bar-style' if set to a
996 known style. Otherwise return image. */)
999 if (EQ (Vtool_bar_style
, Qimage
)
1000 || EQ (Vtool_bar_style
, Qtext
)
1001 || EQ (Vtool_bar_style
, Qboth
)
1002 || EQ (Vtool_bar_style
, Qboth_horiz
)
1003 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
1004 return Vtool_bar_style
;
1005 if (!NILP (current_tool_bar_style
))
1006 return current_tool_bar_style
;
1011 syms_of_xsettings (void)
1013 current_mono_font
= NULL
;
1014 current_font
= NULL
;
1015 first_dpyinfo
= NULL
;
1016 #ifdef HAVE_GSETTINGS
1017 gsettings_client
= NULL
;
1020 gconf_client
= NULL
;
1023 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
1024 DEFSYM (Qfont_name
, "font-name");
1025 DEFSYM (Qfont_render
, "font-render");
1026 defsubr (&Sfont_get_system_font
);
1027 defsubr (&Sfont_get_system_normal_font
);
1029 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
1030 doc
: /* Non-nil means to apply the system defined font dynamically.
1031 When this is non-nil and the system defined fixed width font changes, we
1032 update frames dynamically.
1033 If this variable is nil, Emacs ignores system font changes. */);
1034 use_system_font
= 0;
1036 DEFVAR_LISP ("xft-settings", Vxft_settings
,
1037 doc
: /* Font settings applied to Xft. */);
1038 Vxft_settings
= empty_unibyte_string
;
1041 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
1042 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
1043 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
1047 current_tool_bar_style
= Qnil
;
1048 DEFSYM (Qtool_bar_style
, "tool-bar-style");
1049 defsubr (&Stool_bar_get_system_style
);
1051 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);