--- xfce4-settings-4.6.5/xfsettingsd/registry.c.orig 2010-12-19 11:08:14.000000000 +0000 +++ xfce4-settings-4.6.5/xfsettingsd/registry.c 2010-12-19 16:01:06.000000000 +0000 @@ -40,6 +40,7 @@ #include #include #include +#include #include @@ -305,114 +306,115 @@ } void -xsettings_registry_store_xrdb(XSettingsRegistry *registry) +update_property (GString *props, const gchar* key, const gchar* value) { - gchar *filename; - GError *error = NULL; - GString *string; - gchar *command, *contents; - gboolean result = TRUE; - - /* store the xft properties */ - filename = xfce_resource_save_location(XFCE_RESOURCE_CONFIG, "xfce4" G_DIR_SEPARATOR_S "Xft.xrdb", TRUE); - if (G_LIKELY (filename)) - { - /* create file contents */ - const gchar *xft_rgba = g_value_get_string (&properties[XSETTING_ENTRY_XFT_RGBA].value); - - string = g_string_sized_new (80); - g_string_append_printf (string, "Xft.antialias: %d\n" - "Xft.hinting: %d\n" - "Xft.rgba: %s\n", - g_value_get_int (&properties[XSETTING_ENTRY_XFT_ANTIALIAS].value), - g_value_get_int (&properties[XSETTING_ENTRY_XFT_HINTING].value), - xft_rgba ? xft_rgba : ""); - - if (g_value_get_int (&properties[XSETTING_ENTRY_XFT_HINTING].value)) - g_string_append_printf (string, "Xft.hintstyle: %s\n", g_value_get_string (&properties[XSETTING_ENTRY_XFT_HINTSTYLE].value)); - else - string = g_string_append (string, "Xft.hintstyle: hintnone\n"); - - if (g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value) > 0) - g_string_append_printf (string, "Xft.dpi: %d\n", g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value)); + gchar* needle; + size_t needle_len; + gchar* found = NULL; + + /* update an existing property */ + needle = g_strconcat (key, ":", NULL); + needle_len = strlen (needle); + if (g_str_has_prefix (props->str, needle)) + found = props->str; + else + found = strstr (props->str, needle); + + if (found) { + size_t value_index; + gchar* end; + + end = strchr (found, '\n'); + value_index = (found - props->str) + needle_len + 1; + g_string_erase (props, value_index, end ? (end - found - needle_len) : -1); + g_string_insert (props, value_index, "\n"); + g_string_insert (props, value_index, value); + } else { + g_string_append_printf (props, "%s:\t%s\n", key, value); + } +} - /* try to write the file contents */ - if (G_LIKELY (g_file_set_contents (filename, string->str, -1, &error))) - { - /* create command to merge with the x resource database */ - command = g_strdup_printf ("xrdb -nocpp -merge \"%s\"", filename); - result = g_spawn_command_line_async (command, &error); - g_free (command); - - /* remove dpi from the database if not set */ - if (result && g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value) == 0) - { - command = g_strdup ("sh -c \"xrdb -query | grep -i -v '^Xft.dpi:' | xrdb\""); - result = g_spawn_command_line_async (command, &error); - g_free (command); - } - } - else - { - /* print error */ - g_critical ("Failed to write to '%s': %s", filename, error->message); - g_error_free (error); - } - - /* cleanup */ - g_free (filename); - g_string_free (string, TRUE); - - /* leave when there where spawn problems */ - if (result == FALSE) - goto spawn_error; +void +remove_property (GString *props, const gchar* key) +{ + gchar* needle; + size_t needle_len; + gchar* found = NULL; + + /* search for the property */ + needle = g_strconcat (key, ":", NULL); + needle_len = strlen (needle); + if (g_str_has_prefix (props->str, needle)) + found = props->str; + else + found = strstr (props->str, needle); + + if (found) { + size_t value_index; + gchar* end; + + end = strchr (found, '\n'); + g_string_erase (props, found - props->str, end ? (end - found + 1) : -1); } - - /* store cursor settings */ - filename = xfce_resource_save_location(XFCE_RESOURCE_CONFIG, "xfce4" G_DIR_SEPARATOR_S "Xcursor.xrdb", TRUE); - if (G_LIKELY (filename)) +} + +void +xsettings_registry_store_xrdb(XSettingsRegistry *registry) +{ + Display *dpy; + GString *props; + + dpy = XOpenDisplay (NULL); + g_return_if_fail (dpy != NULL); + props = g_string_new (XResourceManagerString (dpy)); + + /* update the xft properties */ + gchar *xft_aa = g_strdup_printf ("%d", g_value_get_int (&properties[XSETTING_ENTRY_XFT_ANTIALIAS].value)); + gchar *xft_hinting = g_strdup_printf ("%d", g_value_get_int (&properties[XSETTING_ENTRY_XFT_HINTING].value)); + const gchar *xft_rgba = g_value_get_string (&properties[XSETTING_ENTRY_XFT_RGBA].value); + update_property (props, "Xft.antialias", xft_aa); + update_property (props, "Xft.hinting", xft_hinting); + update_property (props, "Xft.rgba", xft_rgba ? xft_rgba : ""); + g_free (xft_aa); + g_free (xft_hinting); + + if (g_value_get_int (&properties[XSETTING_ENTRY_XFT_HINTING].value)) + update_property (props, "Xft.hintstyle", g_value_get_string (&properties[XSETTING_ENTRY_XFT_HINTSTYLE].value)); + else + update_property (props, "Xft.hintstyle", "hintnone"); + + if (g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value) > 0) { - /* build file contents */ - const gchar *cursor_theme_name = g_value_get_string (&properties[XSETTING_ENTRY_GTK_CURSORTHEMENAME].value); - - contents = g_strdup_printf ("Xcursor.theme: %s\n" - "Xcursor.theme_core: true\n" - "Xcursor.size: %d\n", - cursor_theme_name ? cursor_theme_name : "", - g_value_get_int (&properties[XSETTING_ENTRY_GTK_CURSORTHEMESIZE].value)); - - /* write the contents to the file */ - if (G_LIKELY (g_file_set_contents (filename, contents, -1, &error))) - { - /* create command to merge with the x resource database */ - command = g_strdup_printf ("xrdb -nocpp -merge \"%s\"", filename); - result = g_spawn_command_line_async (command, &error); - g_free (command); - } - else - { - /* print error */ - g_critical ("Failed to write to '%s': %s", filename, error->message); - g_error_free (error); - } - - /* cleanup */ - g_free (filename); - g_free (contents); - - /* leave when there where spawn problems */ - if (result == FALSE) - goto spawn_error; + gchar *xft_dpi = g_strdup_printf ("%d", g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value)); + update_property (props, "Xft.dpi", xft_dpi); + g_free (xft_dpi); } + + /* update the xcursor properties */ + const gchar *cursor_theme_name = g_value_get_string (&properties[XSETTING_ENTRY_GTK_CURSORTHEMENAME].value); + gchar *cursor_size = g_strdup_printf("%d", g_value_get_int (&properties[XSETTING_ENTRY_GTK_CURSORTHEMESIZE].value)); + update_property (props, "Xcursor.theme", cursor_theme_name ? cursor_theme_name : ""); + update_property (props, "Xcursor.theme_core", "true"); + update_property (props, "Xcursor.size", cursor_size); + g_free (cursor_size); + + /* remove dpi from the database if not set */ + if (g_value_get_int (&properties[XSETTING_ENTRY_XFT_DPI].value) == 0) + remove_property (props, "Xft.dpi"); + + /* store the properties */ + dpy = XOpenDisplay (NULL); + g_return_if_fail (dpy != NULL); + + XChangeProperty(dpy, RootWindow (dpy, 0), + XA_RESOURCE_MANAGER, XA_STRING, 8, PropModeReplace, props->str, props->len); + + XCloseDisplay (dpy); + + g_string_free (props, TRUE); /* leave */ return; - - spawn_error: - - /* print warning */ - g_critical ("Failed to spawn xrdb: %s", error->message); - g_error_free (error); } static int