X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/5725bd2cc0e691dadc31bd958f210b1bbcf17c49..51721edc6ba92f9c7cb6a2daab45bb538a696f3d:/src/xsettings.c diff --git a/src/xsettings.c b/src/xsettings.c index a28d75d942..e9cc960ce8 100644 --- a/src/xsettings.c +++ b/src/xsettings.c @@ -1,6 +1,6 @@ /* Functions for handling font and other changes dynamically. -Copyright (C) 2009-2012 Free Software Foundation, Inc. +Copyright (C) 2009-2014 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -21,8 +21,10 @@ along with GNU Emacs. If not, see . */ #include #include -#include #include + +#include + #include "lisp.h" #include "xterm.h" #include "xsettings.h" @@ -30,7 +32,6 @@ along with GNU Emacs. If not, see . */ #include "keyboard.h" #include "blockinput.h" #include "termhooks.h" -#include "termopts.h" #include @@ -90,8 +91,7 @@ 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); + dupstring (¤t_mono_font, newfont); if (dpyinfo_valid (first_dpyinfo) && use_system_font) { @@ -110,8 +110,7 @@ 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); + dupstring (¤t_font, newfont); if (dpyinfo_valid (first_dpyinfo)) { @@ -172,7 +171,7 @@ enum { SEEN_HINTSTYLE = 0x10, SEEN_DPI = 0x20, SEEN_FONT = 0x40, - SEEN_TB_STYLE = 0x80, + SEEN_TB_STYLE = 0x80 }; struct xsettings { @@ -338,9 +337,6 @@ get_prop_window (struct x_display_info *dpyinfo) XUngrabServer (dpy); } -#define SWAP32(nr) (((nr) << 24) | (((nr) << 8) & 0xff0000) \ - | (((nr) >> 8) & 0xff00) | ((nr) >> 24)) -#define SWAP16(nr) (((nr) << 8) | ((nr) >> 8)) #define PAD(nr) (((nr) + 3) & ~3) /* Parse xsettings and extract those that deal with Xft. @@ -395,7 +391,7 @@ get_prop_window (struct x_display_info *dpyinfo) static int parse_settings (unsigned char *prop, - long unsigned int bytes, + unsigned long bytes, struct xsettings *settings) { Lisp_Object byteorder = Fbyteorder (); @@ -410,7 +406,7 @@ parse_settings (unsigned char *prop, if (bytes < 12) return BadLength; memcpy (&n_settings, prop+8, 4); - if (my_bo != that_bo) n_settings = SWAP32 (n_settings); + if (my_bo != that_bo) n_settings = bswap_32 (n_settings); bytes_parsed = 12; memset (settings, 0, sizeof (*settings)); @@ -432,7 +428,7 @@ parse_settings (unsigned char *prop, memcpy (&nlen, prop+bytes_parsed, 2); bytes_parsed += 2; - if (my_bo != that_bo) nlen = SWAP16 (nlen); + if (my_bo != that_bo) nlen = bswap_16 (nlen); if (bytes_parsed+nlen > bytes) return BadLength; to_cpy = nlen > 127 ? 127 : nlen; memcpy (name, prop+bytes_parsed, to_cpy); @@ -459,7 +455,7 @@ parse_settings (unsigned char *prop, if (want_this) { memcpy (&ival, prop+bytes_parsed, 4); - if (my_bo != that_bo) ival = SWAP32 (ival); + if (my_bo != that_bo) ival = bswap_32 (ival); } bytes_parsed += 4; break; @@ -468,7 +464,7 @@ parse_settings (unsigned char *prop, if (bytes_parsed+4 > bytes) return BadLength; memcpy (&vlen, prop+bytes_parsed, 4); bytes_parsed += 4; - if (my_bo != that_bo) vlen = SWAP32 (vlen); + if (my_bo != that_bo) vlen = bswap_32 (vlen); if (want_this) { to_cpy = vlen > 127 ? 127 : vlen; @@ -494,13 +490,13 @@ parse_settings (unsigned char *prop, ++settings_seen; if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0) { - settings->tb_style = xstrdup (sval); + dupstring (&settings->tb_style, sval); settings->seen |= SEEN_TB_STYLE; } #ifdef HAVE_XFT else if (strcmp (name, XSETTINGS_FONT_NAME) == 0) { - settings->font = xstrdup (sval); + dupstring (&settings->font, sval); settings->seen |= SEEN_FONT; } else if (strcmp (name, "Xft/Antialias") == 0) @@ -675,26 +671,21 @@ apply_xft_settings (struct x_display_info *dpyinfo, if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi && settings->dpi > 0) { - Lisp_Object frame, tail; - FcPatternDel (pat, FC_DPI); FcPatternAddDouble (pat, FC_DPI, settings->dpi); ++changed; oldsettings.dpi = settings->dpi; - /* Change the DPI on this display and all frames on the display. */ + /* Changing the DPI on this display affects all frames on it. + Check FRAME_RES_X and FRAME_RES_Y in frame.h to see how. */ dpyinfo->resy = dpyinfo->resx = settings->dpi; - FOR_EACH_FRAME (tail, frame) - if (FRAME_X_P (XFRAME (frame)) - && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) - XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi; } if (changed) { static char const format[] = "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, " - "Hintstyle: %d, DPI: %lf"; + "Hintstyle: %d, DPI: %f"; enum { d_formats = 5, @@ -703,7 +694,7 @@ apply_xft_settings (struct x_display_info *dpyinfo, max_f_integer_digits = DBL_MAX_10_EXP + 1, f_precision = 6, lf_growth = (sizeof "-." + max_f_integer_digits + f_precision - - sizeof "%lf") + - sizeof "%f") }; char buf[sizeof format + d_formats * d_growth + lf_formats * lf_growth]; @@ -711,12 +702,12 @@ apply_xft_settings (struct x_display_info *dpyinfo, if (send_event_p) store_config_changed_event (Qfont_render, XCAR (dpyinfo->name_list_element)); - Vxft_settings + Vxft_settings = make_formatted_string (buf, format, oldsettings.aa, oldsettings.hinting, oldsettings.rgba, oldsettings.lcdfilter, oldsettings.hintstyle, oldsettings.dpi); - + } else FcPatternDestroy (pat); @@ -749,10 +740,7 @@ read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) if (send_event_p) store_font_name_changed (settings.font); else - { - xfree (current_font); - current_font = xstrdup (settings.font); - } + dupstring (¤t_font, settings.font); xfree (settings.font); } #endif @@ -761,10 +749,9 @@ read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) /* Check if EVENT for the display in DPYINFO is XSettings related. */ void -xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) +xft_settings_event (struct x_display_info *dpyinfo, const XEvent *event) { - int check_window_p = 0; - int apply_settings = 0; + bool check_window_p = 0, apply_settings_p = 0; switch (event->type) { @@ -784,7 +771,7 @@ xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) if (event->xproperty.window == dpyinfo->xsettings_window && event->xproperty.state == PropertyNewValue && event->xproperty.atom == dpyinfo->Xatom_xsettings_prop) - apply_settings = 1; + apply_settings_p = 1; break; } @@ -794,10 +781,10 @@ xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) dpyinfo->xsettings_window = None; get_prop_window (dpyinfo); if (dpyinfo->xsettings_window != None) - apply_settings = 1; + apply_settings_p = 1; } - if (apply_settings) + if (apply_settings_p) read_and_apply_settings (dpyinfo, True); } @@ -808,17 +795,29 @@ init_gsettings (void) { #ifdef HAVE_GSETTINGS GVariant *val; - const gchar *const *schemas; int schema_found = 0; -#ifdef HAVE_G_TYPE_INIT +#if ! GLIB_CHECK_VERSION (2, 36, 0) 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 GLIB_CHECK_VERSION (2, 32, 0) + { + GSettingsSchema *sc = g_settings_schema_source_lookup + (g_settings_schema_source_get_default (), + GSETTINGS_SCHEMA, + TRUE); + schema_found = sc != NULL; + if (sc) g_settings_schema_unref (sc); + } +#else + { + const gchar *const *schemas = g_settings_list_schemas (); + if (schemas == NULL) return; + while (! schema_found && *schemas != NULL) + schema_found = strcmp (*schemas++, GSETTINGS_SCHEMA) == 0; + } +#endif if (!schema_found) return; gsettings_client = g_settings_new (GSETTINGS_SCHEMA); @@ -843,7 +842,7 @@ init_gsettings (void) { 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)); + dupstring (¤t_mono_font, g_variant_get_string (val, NULL)); g_variant_unref (val); } @@ -852,7 +851,7 @@ init_gsettings (void) { 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)); + dupstring (¤t_font, g_variant_get_string (val, NULL)); g_variant_unref (val); } #endif /* HAVE_XFT */ @@ -868,7 +867,7 @@ init_gconf (void) #if defined (HAVE_GCONF) char *s; -#ifdef HAVE_G_TYPE_INIT +#if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif @@ -894,13 +893,13 @@ init_gconf (void) s = gconf_client_get_string (gconf_client, GCONF_MONO_FONT, NULL); if (s) { - current_mono_font = xstrdup (s); + dupstring (¤t_mono_font, s); g_free (s); } s = gconf_client_get_string (gconf_client, GCONF_FONT_NAME, NULL); if (s) { - current_font = xstrdup (s); + dupstring (¤t_font, s); g_free (s); } gconf_client_add_dir (gconf_client, @@ -930,7 +929,7 @@ init_xsettings (struct x_display_info *dpyinfo) { Display *dpy = dpyinfo->display; - BLOCK_INPUT; + block_input (); /* Select events so we can detect client messages sent when selection owner changes. */ @@ -940,7 +939,7 @@ init_xsettings (struct x_display_info *dpyinfo) if (dpyinfo->xsettings_window != None) read_and_apply_settings (dpyinfo, False); - UNBLOCK_INPUT; + unblock_input (); } void @@ -1010,6 +1009,8 @@ known style. Otherwise return image. */) void syms_of_xsettings (void) { +#include "xsettings.x" + current_mono_font = NULL; current_font = NULL; first_dpyinfo = NULL; @@ -1023,8 +1024,6 @@ syms_of_xsettings (void) 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, doc: /* Non-nil means to apply the system defined font dynamically. @@ -1046,7 +1045,6 @@ If this variable is nil, Emacs ignores system font changes. */); current_tool_bar_style = Qnil; DEFSYM (Qtool_bar_style, "tool-bar-style"); - defsubr (&Stool_bar_get_system_style); Fprovide (intern_c_string ("dynamic-setting"), Qnil); }