X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/d607b96bc2824116a8fe0e5840ce49da7ce4514f..55645c67978eb15884ed5ca919b1691b3715e3ad:/src/xsettings.c diff --git a/src/xsettings.c b/src/xsettings.c index 0d9c9cadb2..066c6e795e 100644 --- a/src/xsettings.c +++ b/src/xsettings.c @@ -1,6 +1,6 @@ -/* Functions for handle font and other changes dynamically. - Copyright (C) 2009, 2010 - Free Software Foundation, Inc. +/* Functions for handling font and other changes dynamically. + +Copyright (C) 2009-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ #include + +#include #include #include #include @@ -32,9 +34,15 @@ along with GNU Emacs. If not, see . */ #include +#ifdef HAVE_GSETTINGS +#include +#include +#endif + #ifdef HAVE_GCONF #include #endif + #ifdef HAVE_XFT #include #endif @@ -44,14 +52,9 @@ static char *current_font; static struct x_display_info *first_dpyinfo; static Lisp_Object Qmonospace_font_name, Qfont_name, Qfont_render, Qtool_bar_style; -static int use_system_font; -static Lisp_Object Vxft_settings; static Lisp_Object current_tool_bar_style; -#ifdef HAVE_GCONF -static GConfClient *gconf_client; -#endif - +/* Store an config changed event in to the event queue. */ static void store_config_changed_event (Lisp_Object arg, Lisp_Object display_name) @@ -64,6 +67,99 @@ store_config_changed_event (Lisp_Object arg, Lisp_Object display_name) kbd_buffer_store_event (&event); } +/* Return non-zero if DPYINFO is still valid. */ +static int +dpyinfo_valid (struct x_display_info *dpyinfo) +{ + int found = 0; + if (dpyinfo != NULL) + { + struct x_display_info *d; + for (d = x_display_list; !found && d; d = d->next) + found = d == dpyinfo && d->display == dpyinfo->display; + } + return found; +} + +/* Store a monospace font change event if the monospaced font changed. */ + +#if defined HAVE_XFT && (defined HAVE_GSETTINGS || defined HAVE_GCONF) +static void +store_monospaced_changed (const char *newfont) +{ + if (current_mono_font != NULL && strcmp (newfont, current_mono_font) == 0) + return; /* No change. */ + + xfree (current_mono_font); + current_mono_font = xstrdup (newfont); + + if (dpyinfo_valid (first_dpyinfo) && use_system_font) + { + store_config_changed_event (Qmonospace_font_name, + XCAR (first_dpyinfo->name_list_element)); + } +} +#endif + +/* Store a font name change event if the font name changed. */ + +#ifdef HAVE_XFT +static void +store_font_name_changed (const char *newfont) +{ + if (current_font != NULL && strcmp (newfont, current_font) == 0) + return; /* No change. */ + + xfree (current_font); + current_font = xstrdup (newfont); + + if (dpyinfo_valid (first_dpyinfo)) + { + store_config_changed_event (Qfont_name, + XCAR (first_dpyinfo->name_list_element)); + } +} +#endif /* HAVE_XFT */ + +/* Map TOOL_BAR_STYLE from a string to its corresponding Lisp value. + Return Qnil if TOOL_BAR_STYLE is not known. */ + +static Lisp_Object +map_tool_bar_style (const char *tool_bar_style) +{ + Lisp_Object style = Qnil; + if (tool_bar_style) + { + if (strcmp (tool_bar_style, "both") == 0) + style = Qboth; + else if (strcmp (tool_bar_style, "both-horiz") == 0) + style = Qboth_horiz; + else if (strcmp (tool_bar_style, "icons") == 0) + style = Qimage; + else if (strcmp (tool_bar_style, "text") == 0) + style = Qtext; + } + + return style; +} + +/* Store a tool bar style change event if the tool bar style changed. */ + +static void +store_tool_bar_style_changed (const char *newstyle, + struct x_display_info *dpyinfo) +{ + Lisp_Object style = map_tool_bar_style (newstyle); + if (EQ (current_tool_bar_style, style)) + return; /* No change. */ + + current_tool_bar_style = style; + if (dpyinfo_valid (dpyinfo)) + store_config_changed_event (Qtool_bar_style, + XCAR (dpyinfo->name_list_element)); +} + + #define XSETTINGS_FONT_NAME "Gtk/FontName" #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle" @@ -77,61 +173,134 @@ enum { SEEN_FONT = 0x40, SEEN_TB_STYLE = 0x80, }; -struct xsettings +struct xsettings { #ifdef HAVE_XFT FcBool aa, hinting; int rgba, lcdfilter, hintstyle; double dpi; -#endif char *font; +#endif + char *tb_style; unsigned seen; }; +#ifdef HAVE_GSETTINGS +#define GSETTINGS_SCHEMA "org.gnome.desktop.interface" +#define GSETTINGS_TOOL_BAR_STYLE "toolbar-style" + +#ifdef HAVE_XFT +#define GSETTINGS_MONO_FONT "monospace-font-name" +#define GSETTINGS_FONT_NAME "font-name" +#endif + + +/* The single GSettings instance, or NULL if not connected to GSettings. */ + +static GSettings *gsettings_client; + +/* Callback called when something changed in GSettings. */ + +static void +something_changed_gsettingsCB (GSettings *settings, + gchar *key, + gpointer user_data) +{ + GVariant *val; + + if (strcmp (key, GSETTINGS_TOOL_BAR_STYLE) == 0) + { + val = g_settings_get_value (settings, GSETTINGS_TOOL_BAR_STYLE); + if (val) + { + g_variant_ref_sink (val); + if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) + { + const gchar *newstyle = g_variant_get_string (val, NULL); + store_tool_bar_style_changed (newstyle, first_dpyinfo); + } + g_variant_unref (val); + } + } +#ifdef HAVE_XFT + else if (strcmp (key, GSETTINGS_MONO_FONT) == 0) + { + val = g_settings_get_value (settings, GSETTINGS_MONO_FONT); + if (val) + { + g_variant_ref_sink (val); + if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) + { + const gchar *newfont = g_variant_get_string (val, NULL); + store_monospaced_changed (newfont); + } + g_variant_unref (val); + } + } + else if (strcmp (key, GSETTINGS_FONT_NAME) == 0) + { + val = g_settings_get_value (settings, GSETTINGS_FONT_NAME); + if (val) + { + g_variant_ref_sink (val); + if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) + { + const gchar *newfont = g_variant_get_string (val, NULL); + store_font_name_changed (newfont); + } + g_variant_unref (val); + } + } +#endif /* HAVE_XFT */ +} + +#endif /* HAVE_GSETTINGS */ + #ifdef HAVE_GCONF +#define GCONF_TOOL_BAR_STYLE "/desktop/gnome/interface/toolbar_style" +#ifdef HAVE_XFT +#define GCONF_MONO_FONT "/desktop/gnome/interface/monospace_font_name" +#define GCONF_FONT_NAME "/desktop/gnome/interface/font_name" +#endif -#define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name" -#define SYSTEM_FONT "/desktop/gnome/interface/font_name" +/* The single GConf instance, or NULL if not connected to GConf. */ -/* Callback called when something changed in GConf that we care about, - that is SYSTEM_MONO_FONT. */ +static GConfClient *gconf_client; + +/* Callback called when something changed in GConf that we care about. */ static void -something_changedCB (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer user_data) +something_changed_gconfCB (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer user_data) { GConfValue *v = gconf_entry_get_value (entry); - - if (!v) return; - if (v->type == GCONF_VALUE_STRING) + const char *key = gconf_entry_get_key (entry); + + if (!v || v->type != GCONF_VALUE_STRING || ! key) return; + if (strcmp (key, GCONF_TOOL_BAR_STYLE) == 0) { const char *value = gconf_value_get_string (v); - if (current_mono_font != NULL && strcmp (value, current_mono_font) == 0) - return; /* No change. */ - - xfree (current_mono_font); - current_mono_font = xstrdup (value); + store_tool_bar_style_changed (value, first_dpyinfo); } - - - if (first_dpyinfo != NULL) +#ifdef HAVE_XFT + else if (strcmp (key, GCONF_MONO_FONT) == 0) + { + const char *value = gconf_value_get_string (v); + store_monospaced_changed (value); + } + else if (strcmp (key, GCONF_FONT_NAME) == 0) { - /* Check if display still open */ - struct x_display_info *dpyinfo; - int found = 0; - for (dpyinfo = x_display_list; !found && dpyinfo; dpyinfo = dpyinfo->next) - found = dpyinfo == first_dpyinfo; - - if (found && use_system_font) - store_config_changed_event (Qmonospace_font_name, - XCAR (first_dpyinfo->name_list_element)); + const char *value = gconf_value_get_string (v); + store_font_name_changed (value); } +#endif /* HAVE_XFT */ } + #endif /* HAVE_GCONF */ #ifdef HAVE_XFT @@ -198,7 +367,7 @@ get_prop_window (struct x_display_info *dpyinfo) 4 CARD32 last-change-serial and then the value, For string: - + bytes type what ------------------------------------ 4 CARD32 n = value-length @@ -277,12 +446,12 @@ parse_settings (unsigned char *prop, want_this = #ifdef HAVE_XFT (nlen > 6 && strncmp (name, "Xft/", 4) == 0) + || strcmp (XSETTINGS_FONT_NAME, name) == 0 || #endif - (strcmp (XSETTINGS_FONT_NAME, name) == 0) - || (strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0); + strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0; - switch (type) + switch (type) { case 0: /* Integer */ if (bytes_parsed+4 > bytes) return BadLength; @@ -312,27 +481,27 @@ parse_settings (unsigned char *prop, case 2: /* RGB value */ /* No need to parse this */ if (bytes_parsed+8 > bytes) return BadLength; - bytes_parsed += 8; /* 4 values (r, b, g, alpha), 2 bytes each. */ + bytes_parsed += 8; /* 4 values (r, b, g, alpha), 2 bytes each. */ break; default: /* Parse Error */ return BadValue; } - if (want_this) + if (want_this) { ++settings_seen; - if (strcmp (name, XSETTINGS_FONT_NAME) == 0) - { - settings->font = xstrdup (sval); - settings->seen |= SEEN_FONT; - } - else if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0) + if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0) { settings->tb_style = xstrdup (sval); settings->seen |= SEEN_TB_STYLE; } #ifdef HAVE_XFT + else if (strcmp (name, XSETTINGS_FONT_NAME) == 0) + { + settings->font = xstrdup (sval); + settings->seen |= SEEN_FONT; + } else if (strcmp (name, "Xft/Antialias") == 0) { settings->seen |= SEEN_AA; @@ -343,6 +512,7 @@ parse_settings (unsigned char *prop, settings->seen |= SEEN_HINTING; settings->hinting = ival != 0; } +# ifdef FC_HINT_STYLE else if (strcmp (name, "Xft/HintStyle") == 0) { settings->seen |= SEEN_HINTSTYLE; @@ -357,6 +527,7 @@ parse_settings (unsigned char *prop, else settings->seen &= ~SEEN_HINTSTYLE; } +# endif else if (strcmp (name, "Xft/RGBA") == 0) { settings->seen |= SEEN_RGBA; @@ -395,6 +566,10 @@ parse_settings (unsigned char *prop, return settings_seen; } +/* Read settings from the XSettings property window on display for DPYINFO. + Store settings read in SETTINGS. + Return non-zero if successful, zero if not. */ + static int read_settings (struct x_display_info *dpyinfo, struct xsettings *settings) { @@ -424,6 +599,8 @@ read_settings (struct x_display_info *dpyinfo, struct xsettings *settings) return rc != 0; } +/* Apply Xft settings in SETTINGS to the Xft library. + If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */ static void apply_xft_settings (struct x_display_info *dpyinfo, @@ -434,17 +611,17 @@ apply_xft_settings (struct x_display_info *dpyinfo, FcPattern *pat; struct xsettings oldsettings; int changed = 0; - char buf[256]; memset (&oldsettings, 0, sizeof (oldsettings)); - buf[0] = '\0'; pat = FcPatternCreate (); XftDefaultSubstitute (dpyinfo->display, XScreenNumberOfScreen (dpyinfo->screen), pat); FcPatternGetBool (pat, FC_ANTIALIAS, 0, &oldsettings.aa); FcPatternGetBool (pat, FC_HINTING, 0, &oldsettings.hinting); +#ifdef FC_HINT_STYLE FcPatternGetInteger (pat, FC_HINT_STYLE, 0, &oldsettings.hintstyle); +#endif FcPatternGetInteger (pat, FC_LCD_FILTER, 0, &oldsettings.lcdfilter); FcPatternGetInteger (pat, FC_RGBA, 0, &oldsettings.rgba); FcPatternGetDouble (pat, FC_DPI, 0, &oldsettings.dpi); @@ -456,7 +633,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, ++changed; oldsettings.aa = settings->aa; } - sprintf (buf, "Antialias: %d", oldsettings.aa); if ((settings->seen & SEEN_HINTING) != 0 && oldsettings.hinting != settings->hinting) @@ -466,8 +642,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, ++changed; oldsettings.hinting = settings->hinting; } - if (strlen (buf) > 0) strcat (buf, ", "); - sprintf (buf+strlen (buf), "Hinting: %d", oldsettings.hinting); if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba) { FcPatternDel (pat, FC_RGBA); @@ -475,8 +649,6 @@ apply_xft_settings (struct x_display_info *dpyinfo, oldsettings.rgba = settings->rgba; ++changed; } - if (strlen (buf) > 0) strcat (buf, ", "); - sprintf (buf+strlen (buf), "RGBA: %d", oldsettings.rgba); /* Older fontconfig versions don't have FC_LCD_FILTER. */ if ((settings->seen & SEEN_LCDFILTER) != 0 @@ -487,9 +659,8 @@ apply_xft_settings (struct x_display_info *dpyinfo, ++changed; oldsettings.lcdfilter = settings->lcdfilter; } - if (strlen (buf) > 0) strcat (buf, ", "); - sprintf (buf+strlen (buf), "LCDFilter: %d", oldsettings.lcdfilter); +#ifdef FC_HINT_STYLE if ((settings->seen & SEEN_HINTSTYLE) != 0 && oldsettings.hintstyle != settings->hintstyle) { @@ -498,8 +669,7 @@ apply_xft_settings (struct x_display_info *dpyinfo, ++changed; oldsettings.hintstyle = settings->hintstyle; } - if (strlen (buf) > 0) strcat (buf, ", "); - sprintf (buf+strlen (buf), "Hintstyle: %d", oldsettings.hintstyle); +#endif if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi && settings->dpi > 0) @@ -510,7 +680,7 @@ apply_xft_settings (struct x_display_info *dpyinfo, FcPatternAddDouble (pat, FC_DPI, settings->dpi); ++changed; oldsettings.dpi = settings->dpi; - + /* Change the DPI on this display and all frames on the display. */ dpyinfo->resy = dpyinfo->resx = settings->dpi; FOR_EACH_FRAME (tail, frame) @@ -519,27 +689,44 @@ apply_xft_settings (struct x_display_info *dpyinfo, XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi; } - if (strlen (buf) > 0) strcat (buf, ", "); - sprintf (buf+strlen (buf), "DPI: %lf", oldsettings.dpi); - if (changed) { + static char const format[] = + "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, " + "Hintstyle: %d, DPI: %lf"; + enum + { + d_formats = 5, + d_growth = INT_BUFSIZE_BOUND (int) - sizeof "%d", + lf_formats = 1, + max_f_integer_digits = DBL_MAX_10_EXP + 1, + f_precision = 6, + lf_growth = (sizeof "-." + max_f_integer_digits + f_precision + - sizeof "%lf") + }; + char buf[sizeof format + d_formats * d_growth + lf_formats * lf_growth]; + XftDefaultSet (dpyinfo->display, pat); if (send_event_p) store_config_changed_event (Qfont_render, XCAR (dpyinfo->name_list_element)); - Vxft_settings = make_string (buf, strlen (buf)); + sprintf (buf, format, oldsettings.aa, oldsettings.hinting, + oldsettings.rgba, oldsettings.lcdfilter, + oldsettings.hintstyle, oldsettings.dpi); + Vxft_settings = build_string (buf); } else FcPatternDestroy (pat); #endif /* HAVE_XFT */ } +/* Read XSettings from the display for DPYINFO. + If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */ + static void read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) { struct xsettings settings; - Lisp_Object dpyname = XCAR (dpyinfo->name_list_element); if (!read_settings (dpyinfo, &settings)) return; @@ -547,38 +734,29 @@ read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) apply_xft_settings (dpyinfo, True, &settings); if (settings.seen & SEEN_TB_STYLE) { - Lisp_Object style = Qnil; - if (strcmp (settings.tb_style, "both") == 0) - style = Qboth; - else if (strcmp (settings.tb_style, "both-horiz") == 0) - style = Qboth_horiz; - else if (strcmp (settings.tb_style, "icons") == 0) - style = Qimage; - else if (strcmp (settings.tb_style, "text") == 0) - style = Qtext; - if (!NILP (style) && !EQ (style, current_tool_bar_style)) - { - current_tool_bar_style = style; - if (send_event_p) - store_config_changed_event (Qtool_bar_style, dpyname); - } - free (settings.tb_style); + if (send_event_p) + store_tool_bar_style_changed (settings.tb_style, dpyinfo); + else + current_tool_bar_style = map_tool_bar_style (settings.tb_style); + xfree (settings.tb_style); } - +#ifdef HAVE_XFT if (settings.seen & SEEN_FONT) { - if (!current_font || strcmp (current_font, settings.font) != 0) + if (send_event_p) + store_font_name_changed (settings.font); + else { - free (current_font); - current_font = settings.font; - if (send_event_p) - store_config_changed_event (Qfont_name, dpyname); + xfree (current_font); + current_font = xstrdup (settings.font); } - else - free (settings.font); + xfree (settings.font); } +#endif } +/* Check if EVENT for the display in DPYINFO is XSettings related. */ + void xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) { @@ -620,54 +798,137 @@ xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) read_and_apply_settings (dpyinfo, True); } +/* Initialize GSettings and read startup values. */ + +static void +init_gsettings (void) +{ +#ifdef HAVE_GSETTINGS + GVariant *val; + const gchar *const *schemas; + int schema_found = 0; + +#ifdef HAVE_G_TYPE_INIT + g_type_init (); +#endif + + schemas = g_settings_list_schemas (); + if (schemas == NULL) return; + while (! schema_found && *schemas != NULL) + schema_found = strcmp (*schemas++, GSETTINGS_SCHEMA) == 0; + if (!schema_found) return; + + gsettings_client = g_settings_new (GSETTINGS_SCHEMA); + if (!gsettings_client) return; + g_object_ref_sink (G_OBJECT (gsettings_client)); + g_signal_connect (G_OBJECT (gsettings_client), "changed", + G_CALLBACK (something_changed_gsettingsCB), NULL); + + val = g_settings_get_value (gsettings_client, GSETTINGS_TOOL_BAR_STYLE); + if (val) + { + g_variant_ref_sink (val); + if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) + current_tool_bar_style + = map_tool_bar_style (g_variant_get_string (val, NULL)); + g_variant_unref (val); + } + +#ifdef HAVE_XFT + val = g_settings_get_value (gsettings_client, GSETTINGS_MONO_FONT); + if (val) + { + g_variant_ref_sink (val); + if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) + current_mono_font = xstrdup (g_variant_get_string (val, NULL)); + g_variant_unref (val); + } + + val = g_settings_get_value (gsettings_client, GSETTINGS_FONT_NAME); + if (val) + { + g_variant_ref_sink (val); + if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) + current_font = xstrdup (g_variant_get_string (val, NULL)); + g_variant_unref (val); + } +#endif /* HAVE_XFT */ + +#endif /* HAVE_GSETTINGS */ +} + +/* Init GConf and read startup values. */ static void init_gconf (void) { -#if defined (HAVE_GCONF) && defined (HAVE_XFT) +#if defined (HAVE_GCONF) char *s; +#ifdef HAVE_G_TYPE_INIT g_type_init (); +#endif + gconf_client = gconf_client_get_default (); - s = gconf_client_get_string (gconf_client, SYSTEM_MONO_FONT, NULL); + gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE); + gconf_client_add_dir (gconf_client, + GCONF_TOOL_BAR_STYLE, + GCONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + gconf_client_notify_add (gconf_client, + GCONF_TOOL_BAR_STYLE, + something_changed_gconfCB, + NULL, NULL, NULL); + + s = gconf_client_get_string (gconf_client, GCONF_TOOL_BAR_STYLE, NULL); + if (s) + { + current_tool_bar_style = map_tool_bar_style (s); + g_free (s); + } + +#ifdef HAVE_XFT + s = gconf_client_get_string (gconf_client, GCONF_MONO_FONT, NULL); if (s) { current_mono_font = xstrdup (s); g_free (s); } - s = gconf_client_get_string (gconf_client, SYSTEM_FONT, NULL); + s = gconf_client_get_string (gconf_client, GCONF_FONT_NAME, NULL); if (s) { current_font = xstrdup (s); g_free (s); } - gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE); gconf_client_add_dir (gconf_client, - SYSTEM_MONO_FONT, + GCONF_MONO_FONT, + GCONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + gconf_client_notify_add (gconf_client, + GCONF_MONO_FONT, + something_changed_gconfCB, + NULL, NULL, NULL); + gconf_client_add_dir (gconf_client, + GCONF_FONT_NAME, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_notify_add (gconf_client, - SYSTEM_MONO_FONT, - something_changedCB, + GCONF_FONT_NAME, + something_changed_gconfCB, NULL, NULL, NULL); -#endif /* HAVE_GCONF && HAVE_XFT */ +#endif /* HAVE_XFT */ +#endif /* HAVE_GCONF */ } +/* Init Xsettings and read startup values. */ + static void init_xsettings (struct x_display_info *dpyinfo) { - char sel[64]; Display *dpy = dpyinfo->display; BLOCK_INPUT; - sprintf (sel, "_XSETTINGS_S%d", XScreenNumberOfScreen (dpyinfo->screen)); - dpyinfo->Xatom_xsettings_sel = XInternAtom (dpy, sel, False); - dpyinfo->Xatom_xsettings_prop = XInternAtom (dpy, - "_XSETTINGS_SETTINGS", - False); - dpyinfo->Xatom_xsettings_mgr = XInternAtom (dpy, "MANAGER", False); - /* Select events so we can detect client messages sent when selection owner changes. */ XSelectInput (dpy, dpyinfo->root_window, StructureNotifyMask); @@ -685,19 +946,28 @@ xsettings_initialize (struct x_display_info *dpyinfo) if (first_dpyinfo == NULL) first_dpyinfo = dpyinfo; init_gconf (); init_xsettings (dpyinfo); + init_gsettings (); } +/* Return the system monospaced font. + May be NULL if not known. */ + const char * xsettings_get_system_font (void) { return current_mono_font; } +#ifdef USE_LUCID +/* Return the system font. + May be NULL if not known. */ + const char * xsettings_get_system_normal_font (void) { return current_font; } +#endif DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font, Sfont_get_system_normal_font, @@ -705,9 +975,7 @@ DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font, doc: /* Get the system default application font. */) (void) { - return current_font - ? make_string (current_font, strlen (current_font)) - : Qnil; + return current_font ? build_string (current_font) : Qnil; } DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font, @@ -715,13 +983,11 @@ DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font, doc: /* Get the system default fixed width font. */) (void) { - return current_mono_font - ? make_string (current_mono_font, strlen (current_mono_font)) - : Qnil; + return current_mono_font ? build_string (current_mono_font) : Qnil; } -DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style, Stool_bar_get_system_style, - 0, 0, 0, +DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style, + Stool_bar_get_system_style, 0, 0, 0, doc: /* Get the system tool bar style. If no system tool bar style is known, return `tool-bar-style' if set to a known style. Otherwise return image. */) @@ -744,44 +1010,40 @@ syms_of_xsettings (void) current_mono_font = NULL; current_font = NULL; first_dpyinfo = NULL; +#ifdef HAVE_GSETTINGS + gsettings_client = NULL; +#endif #ifdef HAVE_GCONF gconf_client = NULL; #endif - Qmonospace_font_name = intern_c_string ("monospace-font-name"); - staticpro (&Qmonospace_font_name); - Qfont_name = intern_c_string ("font-name"); - staticpro (&Qfont_name); - Qfont_render = intern_c_string ("font-render"); - staticpro (&Qfont_render); + DEFSYM (Qmonospace_font_name, "monospace-font-name"); + DEFSYM (Qfont_name, "font-name"); + DEFSYM (Qfont_render, "font-render"); defsubr (&Sfont_get_system_font); defsubr (&Sfont_get_system_normal_font); - DEFVAR_BOOL ("font-use-system-font", &use_system_font, + DEFVAR_BOOL ("font-use-system-font", use_system_font, doc: /* *Non-nil means to apply the system defined font dynamically. When this is non-nil and the system defined fixed width font changes, we update frames dynamically. If this variable is nil, Emacs ignores system font changes. */); use_system_font = 0; - DEFVAR_LISP ("xft-settings", &Vxft_settings, + DEFVAR_LISP ("xft-settings", Vxft_settings, doc: /* Font settings applied to Xft. */); Vxft_settings = make_string ("", 0); #ifdef HAVE_XFT Fprovide (intern_c_string ("font-render-setting"), Qnil); -#ifdef HAVE_GCONF +#if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) Fprovide (intern_c_string ("system-font-setting"), Qnil); #endif #endif current_tool_bar_style = Qnil; - Qtool_bar_style = intern_c_string ("tool-bar-style"); - staticpro (&Qtool_bar_style); + DEFSYM (Qtool_bar_style, "tool-bar-style"); defsubr (&Stool_bar_get_system_style); Fprovide (intern_c_string ("dynamic-setting"), Qnil); } - -/* arch-tag: 541716ed-2e6b-42e1-8212-3197e01ea61d - (do not change this comment) */