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>
42 #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
;
58 store_config_changed_event (Lisp_Object arg
, Lisp_Object display_name
)
60 struct input_event event
;
62 event
.kind
= CONFIG_CHANGED_EVENT
;
63 event
.frame_or_window
= display_name
;
65 kbd_buffer_store_event (&event
);
69 store_monospaced_changed (void)
71 if (first_dpyinfo
!= NULL
)
73 /* Check if display still open */
74 struct x_display_info
*dpyinfo
;
76 for (dpyinfo
= x_display_list
; !found
&& dpyinfo
; dpyinfo
= dpyinfo
->next
)
77 found
= dpyinfo
== first_dpyinfo
;
79 if (found
&& use_system_font
)
80 store_config_changed_event (Qmonospace_font_name
,
81 XCAR (first_dpyinfo
->name_list_element
));
88 #define EMACS_TYPE_SETTINGS (emacs_settings_get_type ())
89 #define EMACS_SETTINGS(obj) \
90 (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMACS_TYPE_SETTINGS, EmacsSettings))
91 #define EMACS_IS_SETTINGS(obj) \
92 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMACS_TYPE_SETTINGS))
93 #define EMACS_SETTINGS_CLASS(klass) \
94 (G_TYPE_CHECK_CLASS_CAST ((klass), EMACS_TYPE_SETTINGS, EmacsSettingsClass))
95 #define EMACS_IS_SETTINGS_CLASS(klass) \
96 (G_TYPE_CHECK_CLASS_TYPE ((klass), EMACS_TYPE_SETTINGS))
97 #define EMACS_SETTINGS_GET_CLASS(obj) \
98 (G_TYPE_INSTANCE_GET_CLASS ((obj), EMACS_TYPE_SETTINGS, EmacsSettingsClass))
100 typedef struct _EmacsSettings EmacsSettings
;
101 typedef struct _EmacsSettingsClass EmacsSettingsClass
;
103 struct _EmacsSettings
105 GObject parent_instance
;
108 struct _EmacsSettingsClass
110 GObjectClass parent_class
;
113 /* will create emacs_settings_get_type and set emacs_settings_parent_class */
114 G_DEFINE_TYPE (EmacsSettings
, emacs_settings
, G_TYPE_OBJECT
);
117 emacs_settings_constructor (GType gtype
,
119 GObjectConstructParam
*properties
)
123 /* Always chain up to the parent constructor */
124 obj
= G_OBJECT_CLASS (emacs_settings_parent_class
)
125 ->constructor (gtype
, n_properties
, properties
);
127 /* update the object state depending on constructor properties */
132 enum { PROP_MONO
= 1, PROP_FONT
};
135 emacs_settings_get_property (GObject
*object
,
143 g_value_set_string (value
, current_mono_font
);
146 g_value_set_string (value
, current_font
);
152 emacs_settings_set_property (GObject
*object
,
161 xfree (current_mono_font
);
162 newfont
= g_value_get_string (value
);
163 if (current_mono_font
!= NULL
&& strcmp (newfont
, current_mono_font
) == 0)
164 return; /* No change. */
166 current_mono_font
= xstrdup (newfont
);
167 store_monospaced_changed ();
171 xfree (current_font
);
172 current_font
= xstrdup (g_value_get_string (value
));
178 emacs_settings_class_init (EmacsSettingsClass
*klass
)
180 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
182 gobject_class
->constructor
= emacs_settings_constructor
;
183 gobject_class
->set_property
= emacs_settings_set_property
;
184 gobject_class
->get_property
= emacs_settings_get_property
;
186 g_object_class_install_property
189 g_param_spec_string ("monospace-font",
191 "System monospace font",
194 g_object_class_install_property
197 g_param_spec_string ("font",
206 emacs_settings_init (EmacsSettings
*self
)
211 static GSettings
*gsettings_client
;
212 static EmacsSettings
*gsettings_obj
;
216 static GConfClient
*gconf_client
;
221 #define XSETTINGS_FONT_NAME "Gtk/FontName"
222 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
228 SEEN_LCDFILTER
= 0x08,
229 SEEN_HINTSTYLE
= 0x10,
232 SEEN_TB_STYLE
= 0x80,
238 int rgba
, lcdfilter
, hintstyle
;
248 #ifdef HAVE_GSETTINGS
249 #define GSETTINGS_SCHEMA "org.gnome.desktop.interface"
250 #define SYSTEM_MONO_FONT "monospace-font-name"
251 #define SYSTEM_FONT "font-name"
255 #define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
256 #define SYSTEM_FONT "/desktop/gnome/interface/font_name"
258 /* Callback called when something changed in GConf that we care about,
259 that is SYSTEM_MONO_FONT. */
262 something_changedCB (GConfClient
*client
,
267 GConfValue
*v
= gconf_entry_get_value (entry
);
270 if (v
->type
== GCONF_VALUE_STRING
)
272 const char *value
= gconf_value_get_string (v
);
273 if (current_mono_font
!= NULL
&& strcmp (value
, current_mono_font
) == 0)
274 return; /* No change. */
276 xfree (current_mono_font
);
277 current_mono_font
= xstrdup (value
);
278 store_monospaced_changed ();
282 #endif /* HAVE_GCONF */
283 #endif /* ! HAVE_GSETTINGS */
287 /* Older fontconfig versions don't have FC_LCD_*. */
289 #define FC_LCD_NONE 0
291 #ifndef FC_LCD_DEFAULT
292 #define FC_LCD_DEFAULT 1
294 #ifndef FC_LCD_FILTER
295 #define FC_LCD_FILTER "lcdfilter"
298 #endif /* HAVE_XFT */
300 /* Find the window that contains the XSETTINGS property values. */
303 get_prop_window (struct x_display_info
*dpyinfo
)
305 Display
*dpy
= dpyinfo
->display
;
308 dpyinfo
->xsettings_window
= XGetSelectionOwner (dpy
,
309 dpyinfo
->Xatom_xsettings_sel
);
310 if (dpyinfo
->xsettings_window
!= None
)
311 /* Select events so we can detect if window is deleted or if settings
313 XSelectInput (dpy
, dpyinfo
->xsettings_window
,
314 PropertyChangeMask
|StructureNotifyMask
);
319 #define SWAP32(nr) (((nr) << 24) | (((nr) << 8) & 0xff0000) \
320 | (((nr) >> 8) & 0xff00) | ((nr) >> 24))
321 #define SWAP16(nr) (((nr) << 8) | ((nr) >> 8))
322 #define PAD(nr) (((nr) + 3) & ~3)
324 /* Parse xsettings and extract those that deal with Xft.
325 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
326 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
328 Layout of prop. First is a header:
331 ------------------------------------
337 Then N_SETTINGS records, with header:
340 ------------------------------------
341 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
343 2 CARD16 n == name-length
345 p unused, p=pad_to_even_4(n)
346 4 CARD32 last-change-serial
348 and then the value, For string:
351 ------------------------------------
352 4 CARD32 n = value-length
354 p unused, p=pad_to_even_4(n)
359 ------------------------------------
365 ------------------------------------
371 Returns non-zero if some Xft settings was seen, zero otherwise.
375 parse_settings (unsigned char *prop
,
376 long unsigned int bytes
,
377 struct xsettings
*settings
)
379 Lisp_Object byteorder
= Fbyteorder ();
380 int my_bo
= XFASTINT (byteorder
) == 'B' ? MSBFirst
: LSBFirst
;
381 int that_bo
= prop
[0];
383 int bytes_parsed
= 0;
384 int settings_seen
= 0;
387 /* First 4 bytes is a serial number, skip that. */
389 if (bytes
< 12) return BadLength
;
390 memcpy (&n_settings
, prop
+8, 4);
391 if (my_bo
!= that_bo
) n_settings
= SWAP32 (n_settings
);
394 memset (settings
, 0, sizeof (*settings
));
396 while (bytes_parsed
+4 < bytes
&& settings_seen
< 7
399 int type
= prop
[bytes_parsed
++];
401 CARD32 vlen
, ival
= 0;
402 char name
[128]; /* The names we are looking for are not this long. */
403 char sval
[128]; /* The values we are looking for are not this long. */
409 ++bytes_parsed
; /* Padding */
411 memcpy (&nlen
, prop
+bytes_parsed
, 2);
413 if (my_bo
!= that_bo
) nlen
= SWAP16 (nlen
);
414 if (bytes_parsed
+nlen
> bytes
) return BadLength
;
415 to_cpy
= nlen
> 127 ? 127 : nlen
;
416 memcpy (name
, prop
+bytes_parsed
, to_cpy
);
419 bytes_parsed
+= nlen
;
420 bytes_parsed
= PAD (bytes_parsed
);
422 bytes_parsed
+= 4; /* Skip serial for this value */
423 if (bytes_parsed
> bytes
) return BadLength
;
427 (nlen
> 6 && strncmp (name
, "Xft/", 4) == 0)
430 (strcmp (XSETTINGS_FONT_NAME
, name
) == 0)
431 || (strcmp (XSETTINGS_TOOL_BAR_STYLE
, name
) == 0);
435 case 0: /* Integer */
436 if (bytes_parsed
+4 > bytes
) return BadLength
;
439 memcpy (&ival
, prop
+bytes_parsed
, 4);
440 if (my_bo
!= that_bo
) ival
= SWAP32 (ival
);
446 if (bytes_parsed
+4 > bytes
) return BadLength
;
447 memcpy (&vlen
, prop
+bytes_parsed
, 4);
449 if (my_bo
!= that_bo
) vlen
= SWAP32 (vlen
);
452 to_cpy
= vlen
> 127 ? 127 : vlen
;
453 memcpy (sval
, prop
+bytes_parsed
, to_cpy
);
456 bytes_parsed
+= vlen
;
457 bytes_parsed
= PAD (bytes_parsed
);
460 case 2: /* RGB value */
461 /* No need to parse this */
462 if (bytes_parsed
+8 > bytes
) return BadLength
;
463 bytes_parsed
+= 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
466 default: /* Parse Error */
473 if (strcmp (name
, XSETTINGS_FONT_NAME
) == 0)
475 settings
->font
= xstrdup (sval
);
476 settings
->seen
|= SEEN_FONT
;
478 else if (strcmp (name
, XSETTINGS_TOOL_BAR_STYLE
) == 0)
480 settings
->tb_style
= xstrdup (sval
);
481 settings
->seen
|= SEEN_TB_STYLE
;
484 else if (strcmp (name
, "Xft/Antialias") == 0)
486 settings
->seen
|= SEEN_AA
;
487 settings
->aa
= ival
!= 0;
489 else if (strcmp (name
, "Xft/Hinting") == 0)
491 settings
->seen
|= SEEN_HINTING
;
492 settings
->hinting
= ival
!= 0;
494 # ifdef FC_HINT_STYLE
495 else if (strcmp (name
, "Xft/HintStyle") == 0)
497 settings
->seen
|= SEEN_HINTSTYLE
;
498 if (strcmp (sval
, "hintnone") == 0)
499 settings
->hintstyle
= FC_HINT_NONE
;
500 else if (strcmp (sval
, "hintslight") == 0)
501 settings
->hintstyle
= FC_HINT_SLIGHT
;
502 else if (strcmp (sval
, "hintmedium") == 0)
503 settings
->hintstyle
= FC_HINT_MEDIUM
;
504 else if (strcmp (sval
, "hintfull") == 0)
505 settings
->hintstyle
= FC_HINT_FULL
;
507 settings
->seen
&= ~SEEN_HINTSTYLE
;
510 else if (strcmp (name
, "Xft/RGBA") == 0)
512 settings
->seen
|= SEEN_RGBA
;
513 if (strcmp (sval
, "none") == 0)
514 settings
->rgba
= FC_RGBA_NONE
;
515 else if (strcmp (sval
, "rgb") == 0)
516 settings
->rgba
= FC_RGBA_RGB
;
517 else if (strcmp (sval
, "bgr") == 0)
518 settings
->rgba
= FC_RGBA_BGR
;
519 else if (strcmp (sval
, "vrgb") == 0)
520 settings
->rgba
= FC_RGBA_VRGB
;
521 else if (strcmp (sval
, "vbgr") == 0)
522 settings
->rgba
= FC_RGBA_VBGR
;
524 settings
->seen
&= ~SEEN_RGBA
;
526 else if (strcmp (name
, "Xft/DPI") == 0)
528 settings
->seen
|= SEEN_DPI
;
529 settings
->dpi
= (double)ival
/1024.0;
531 else if (strcmp (name
, "Xft/lcdfilter") == 0)
533 settings
->seen
|= SEEN_LCDFILTER
;
534 if (strcmp (sval
, "none") == 0)
535 settings
->lcdfilter
= FC_LCD_NONE
;
536 else if (strcmp (sval
, "lcddefault") == 0)
537 settings
->lcdfilter
= FC_LCD_DEFAULT
;
539 settings
->seen
&= ~SEEN_LCDFILTER
;
541 #endif /* HAVE_XFT */
545 return settings_seen
;
549 read_settings (struct x_display_info
*dpyinfo
, struct xsettings
*settings
)
553 unsigned long nitems
, bytes_after
;
554 unsigned char *prop
= NULL
;
555 Display
*dpy
= dpyinfo
->display
;
558 x_catch_errors (dpy
);
559 rc
= XGetWindowProperty (dpy
,
560 dpyinfo
->xsettings_window
,
561 dpyinfo
->Xatom_xsettings_prop
,
562 0, LONG_MAX
, False
, AnyPropertyType
,
563 &act_type
, &act_form
, &nitems
, &bytes_after
,
566 if (rc
== Success
&& prop
!= NULL
&& act_form
== 8 && nitems
> 0
567 && act_type
== dpyinfo
->Xatom_xsettings_prop
)
568 rc
= parse_settings (prop
, nitems
, settings
);
579 apply_xft_settings (struct x_display_info
*dpyinfo
,
581 struct xsettings
*settings
)
585 struct xsettings oldsettings
;
588 memset (&oldsettings
, 0, sizeof (oldsettings
));
589 pat
= FcPatternCreate ();
590 XftDefaultSubstitute (dpyinfo
->display
,
591 XScreenNumberOfScreen (dpyinfo
->screen
),
593 FcPatternGetBool (pat
, FC_ANTIALIAS
, 0, &oldsettings
.aa
);
594 FcPatternGetBool (pat
, FC_HINTING
, 0, &oldsettings
.hinting
);
595 # ifdef FC_HINT_STYLE
596 FcPatternGetInteger (pat
, FC_HINT_STYLE
, 0, &oldsettings
.hintstyle
);
598 FcPatternGetInteger (pat
, FC_LCD_FILTER
, 0, &oldsettings
.lcdfilter
);
599 FcPatternGetInteger (pat
, FC_RGBA
, 0, &oldsettings
.rgba
);
600 FcPatternGetDouble (pat
, FC_DPI
, 0, &oldsettings
.dpi
);
602 if ((settings
->seen
& SEEN_AA
) != 0 && oldsettings
.aa
!= settings
->aa
)
604 FcPatternDel (pat
, FC_ANTIALIAS
);
605 FcPatternAddBool (pat
, FC_ANTIALIAS
, settings
->aa
);
607 oldsettings
.aa
= settings
->aa
;
610 if ((settings
->seen
& SEEN_HINTING
) != 0
611 && oldsettings
.hinting
!= settings
->hinting
)
613 FcPatternDel (pat
, FC_HINTING
);
614 FcPatternAddBool (pat
, FC_HINTING
, settings
->hinting
);
616 oldsettings
.hinting
= settings
->hinting
;
618 if ((settings
->seen
& SEEN_RGBA
) != 0 && oldsettings
.rgba
!= settings
->rgba
)
620 FcPatternDel (pat
, FC_RGBA
);
621 FcPatternAddInteger (pat
, FC_RGBA
, settings
->rgba
);
622 oldsettings
.rgba
= settings
->rgba
;
626 /* Older fontconfig versions don't have FC_LCD_FILTER. */
627 if ((settings
->seen
& SEEN_LCDFILTER
) != 0
628 && oldsettings
.lcdfilter
!= settings
->lcdfilter
)
630 FcPatternDel (pat
, FC_LCD_FILTER
);
631 FcPatternAddInteger (pat
, FC_LCD_FILTER
, settings
->lcdfilter
);
633 oldsettings
.lcdfilter
= settings
->lcdfilter
;
636 # ifdef FC_HINT_STYLE
637 if ((settings
->seen
& SEEN_HINTSTYLE
) != 0
638 && oldsettings
.hintstyle
!= settings
->hintstyle
)
640 FcPatternDel (pat
, FC_HINT_STYLE
);
641 FcPatternAddInteger (pat
, FC_HINT_STYLE
, settings
->hintstyle
);
643 oldsettings
.hintstyle
= settings
->hintstyle
;
647 if ((settings
->seen
& SEEN_DPI
) != 0 && oldsettings
.dpi
!= settings
->dpi
648 && settings
->dpi
> 0)
650 Lisp_Object frame
, tail
;
652 FcPatternDel (pat
, FC_DPI
);
653 FcPatternAddDouble (pat
, FC_DPI
, settings
->dpi
);
655 oldsettings
.dpi
= settings
->dpi
;
657 /* Change the DPI on this display and all frames on the display. */
658 dpyinfo
->resy
= dpyinfo
->resx
= settings
->dpi
;
659 FOR_EACH_FRAME (tail
, frame
)
660 if (FRAME_X_P (XFRAME (frame
))
661 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
662 XFRAME (frame
)->resy
= XFRAME (frame
)->resx
= settings
->dpi
;
667 static char const format
[] =
668 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
669 "Hintstyle: %d, DPI: %lf";
673 d_growth
= INT_BUFSIZE_BOUND (int) - sizeof "%d",
675 max_f_integer_digits
= DBL_MAX_10_EXP
+ 1,
677 lf_growth
= (sizeof "-." + max_f_integer_digits
+ f_precision
680 char buf
[sizeof format
+ d_formats
* d_growth
+ lf_formats
* lf_growth
];
682 XftDefaultSet (dpyinfo
->display
, pat
);
684 store_config_changed_event (Qfont_render
,
685 XCAR (dpyinfo
->name_list_element
));
686 sprintf (buf
, format
, oldsettings
.aa
, oldsettings
.hinting
,
687 oldsettings
.rgba
, oldsettings
.lcdfilter
,
688 oldsettings
.hintstyle
, oldsettings
.dpi
);
689 Vxft_settings
= build_string (buf
);
692 FcPatternDestroy (pat
);
693 #endif /* HAVE_XFT */
697 read_and_apply_settings (struct x_display_info
*dpyinfo
, int send_event_p
)
699 struct xsettings settings
;
700 Lisp_Object dpyname
= XCAR (dpyinfo
->name_list_element
);
702 if (!read_settings (dpyinfo
, &settings
))
705 apply_xft_settings (dpyinfo
, True
, &settings
);
706 if (settings
.seen
& SEEN_TB_STYLE
)
708 Lisp_Object style
= Qnil
;
709 if (strcmp (settings
.tb_style
, "both") == 0)
711 else if (strcmp (settings
.tb_style
, "both-horiz") == 0)
713 else if (strcmp (settings
.tb_style
, "icons") == 0)
715 else if (strcmp (settings
.tb_style
, "text") == 0)
717 if (!NILP (style
) && !EQ (style
, current_tool_bar_style
))
719 current_tool_bar_style
= style
;
721 store_config_changed_event (Qtool_bar_style
, dpyname
);
723 xfree (settings
.tb_style
);
726 if (settings
.seen
& SEEN_FONT
)
728 if (!current_font
|| strcmp (current_font
, settings
.font
) != 0)
730 xfree (current_font
);
731 current_font
= settings
.font
;
733 store_config_changed_event (Qfont_name
, dpyname
);
736 xfree (settings
.font
);
741 xft_settings_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
743 int check_window_p
= 0;
744 int apply_settings
= 0;
749 if (dpyinfo
->xsettings_window
== event
->xany
.window
)
754 if (event
->xclient
.message_type
== dpyinfo
->Xatom_xsettings_mgr
755 && event
->xclient
.data
.l
[1] == dpyinfo
->Xatom_xsettings_sel
756 && event
->xclient
.window
== dpyinfo
->root_window
)
761 if (event
->xproperty
.window
== dpyinfo
->xsettings_window
762 && event
->xproperty
.state
== PropertyNewValue
763 && event
->xproperty
.atom
== dpyinfo
->Xatom_xsettings_prop
)
771 dpyinfo
->xsettings_window
= None
;
772 get_prop_window (dpyinfo
);
773 if (dpyinfo
->xsettings_window
!= None
)
778 read_and_apply_settings (dpyinfo
, True
);
783 init_gsettings (void)
785 #ifdef HAVE_GSETTINGS
787 #ifdef HAVE_G_TYPE_INIT
791 gsettings_client
= g_settings_new (GSETTINGS_SCHEMA
);
792 if (!gsettings_client
) return;
793 g_object_ref_sink (G_OBJECT (gsettings_client
));
795 gsettings_obj
= g_object_new (EMACS_TYPE_SETTINGS
, NULL
);
798 g_object_unref (G_OBJECT (gsettings_client
));
801 g_object_ref_sink (G_OBJECT (gsettings_obj
));
803 val
= g_settings_get_value (gsettings_client
, SYSTEM_MONO_FONT
);
806 g_variant_ref_sink (val
);
807 if (g_variant_is_of_type (val
, G_VARIANT_TYPE_STRING
))
808 current_mono_font
= xstrdup (g_variant_get_string (val
, NULL
));
809 g_variant_unref (val
);
812 g_settings_bind (gsettings_client
, SYSTEM_MONO_FONT
, gsettings_obj
,
813 "monospace-font", G_SETTINGS_BIND_GET
);
814 g_settings_bind (gsettings_client
, SYSTEM_FONT
, gsettings_obj
,
815 "font", G_SETTINGS_BIND_GET
);
816 #endif /* HAVE_GSETTINGS */
823 #if defined (HAVE_GCONF) && defined (HAVE_XFT) && ! defined (HAVE_GSETTINGS)
826 #ifdef HAVE_G_TYPE_INIT
829 gconf_client
= gconf_client_get_default ();
830 s
= gconf_client_get_string (gconf_client
, SYSTEM_MONO_FONT
, NULL
);
833 current_mono_font
= xstrdup (s
);
836 s
= gconf_client_get_string (gconf_client
, SYSTEM_FONT
, NULL
);
839 current_font
= xstrdup (s
);
842 gconf_client_set_error_handling (gconf_client
, GCONF_CLIENT_HANDLE_NONE
);
843 gconf_client_add_dir (gconf_client
,
845 GCONF_CLIENT_PRELOAD_ONELEVEL
,
847 gconf_client_notify_add (gconf_client
,
851 #endif /* HAVE_GCONF && HAVE_XFT && ! HAVE_GSETTINGS */
855 init_xsettings (struct x_display_info
*dpyinfo
)
857 Display
*dpy
= dpyinfo
->display
;
861 /* Select events so we can detect client messages sent when selection
863 XSelectInput (dpy
, dpyinfo
->root_window
, StructureNotifyMask
);
865 get_prop_window (dpyinfo
);
866 if (dpyinfo
->xsettings_window
!= None
)
867 read_and_apply_settings (dpyinfo
, False
);
873 xsettings_initialize (struct x_display_info
*dpyinfo
)
875 if (first_dpyinfo
== NULL
) first_dpyinfo
= dpyinfo
;
878 init_xsettings (dpyinfo
);
882 xsettings_get_system_font (void)
884 return current_mono_font
;
889 xsettings_get_system_normal_font (void)
895 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font
,
896 Sfont_get_system_normal_font
,
898 doc
: /* Get the system default application font. */)
901 return current_font
? build_string (current_font
) : Qnil
;
904 DEFUN ("font-get-system-font", Ffont_get_system_font
, Sfont_get_system_font
,
906 doc
: /* Get the system default fixed width font. */)
909 return current_mono_font
? build_string (current_mono_font
) : Qnil
;
912 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style
,
913 Stool_bar_get_system_style
, 0, 0, 0,
914 doc
: /* Get the system tool bar style.
915 If no system tool bar style is known, return `tool-bar-style' if set to a
916 known style. Otherwise return image. */)
919 if (EQ (Vtool_bar_style
, Qimage
)
920 || EQ (Vtool_bar_style
, Qtext
)
921 || EQ (Vtool_bar_style
, Qboth
)
922 || EQ (Vtool_bar_style
, Qboth_horiz
)
923 || EQ (Vtool_bar_style
, Qtext_image_horiz
))
924 return Vtool_bar_style
;
925 if (!NILP (current_tool_bar_style
))
926 return current_tool_bar_style
;
931 syms_of_xsettings (void)
933 current_mono_font
= NULL
;
935 first_dpyinfo
= NULL
;
936 #ifdef HAVE_GSETTINGS
937 gsettings_client
= NULL
;
938 gsettings_obj
= NULL
;
945 DEFSYM (Qmonospace_font_name
, "monospace-font-name");
946 DEFSYM (Qfont_name
, "font-name");
947 DEFSYM (Qfont_render
, "font-render");
948 defsubr (&Sfont_get_system_font
);
949 defsubr (&Sfont_get_system_normal_font
);
951 DEFVAR_BOOL ("font-use-system-font", use_system_font
,
952 doc
: /* *Non-nil means to apply the system defined font dynamically.
953 When this is non-nil and the system defined fixed width font changes, we
954 update frames dynamically.
955 If this variable is nil, Emacs ignores system font changes. */);
958 DEFVAR_LISP ("xft-settings", Vxft_settings
,
959 doc
: /* Font settings applied to Xft. */);
960 Vxft_settings
= make_string ("", 0);
963 Fprovide (intern_c_string ("font-render-setting"), Qnil
);
964 #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
965 Fprovide (intern_c_string ("system-font-setting"), Qnil
);
969 current_tool_bar_style
= Qnil
;
970 DEFSYM (Qtool_bar_style
, "tool-bar-style");
971 defsubr (&Stool_bar_get_system_style
);
973 Fprovide (intern_c_string ("dynamic-setting"), Qnil
);