Updating branch refs/heads/master to ceeb76b26a5d3e652ae5cd638bfe16ecfe0d68f4 (commit) from d9ab1de0f0d0d5e44a777b80e3b68f738dc5a04d (commit)
commit ceeb76b26a5d3e652ae5cd638bfe16ecfe0d68f4 Author: Jérôme Guelfucci <jero...@xfce.org> Date: Fri Jan 18 19:43:54 2013 +0100 The daemon no longer needs to be killed on theme update. This is a bit tricky but far cleaner than killing the daemon. xfce4-notifyd-config/main.c | 24 ---------------------- xfce4-notifyd/main.c | 28 +++++++++++++++++++++++++ xfce4-notifyd/xfce-notify-daemon.c | 39 ++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 28 deletions(-) diff --git a/xfce4-notifyd-config/main.c b/xfce4-notifyd-config/main.c index 13bba2d..d3a4726 100644 --- a/xfce4-notifyd-config/main.c +++ b/xfce4-notifyd-config/main.c @@ -38,29 +38,6 @@ #include "xfce4-notifyd-config.ui.h" -/* unfortunately, currently we have to kill the daemon to - * change themes. this is only annoying because existing notifications - * will get killed */ -static void -xfce4_notifyd_config_kill_daemon(void) -{ - DBusGConnection *dbus_conn; - DBusGProxy *proxy; - - dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - if(!dbus_conn) - return; - - proxy = dbus_g_proxy_new_for_name(dbus_conn, - "org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - "org.xfce.Notifyd"); - dbus_g_proxy_call_no_reply(proxy, "Quit", G_TYPE_INVALID); - - g_object_unref(G_OBJECT(proxy)); - dbus_g_connection_unref(dbus_conn); -} - static gchar * xfce4_notifyd_slider_format_value(GtkScale *slider, gdouble value, @@ -115,7 +92,6 @@ xfce4_notifyd_config_theme_changed(XfconfChannel *channel, gtk_combo_box_set_active_iter(GTK_COMBO_BOX(theme_combo), &iter); g_free(theme); - xfce4_notifyd_config_kill_daemon(); /* TRANSLATORS: notify-send is a command name in the following string, * it must not be translated. */ diff --git a/xfce4-notifyd/main.c b/xfce4-notifyd/main.c index a755b10..8fab30a 100644 --- a/xfce4-notifyd/main.c +++ b/xfce4-notifyd/main.c @@ -25,6 +25,8 @@ #include <string.h> #endif +#include <glib/gstdio.h> + #include <gtk/gtk.h> #include <xfconf/xfconf.h> @@ -39,8 +41,30 @@ main(int argc, { XfceNotifyDaemon *xndaemon; GError *error = NULL; + gchar *temp_theme_file; xfconf_init(NULL); + + /* For theming we need to rely on a trick. + * + * We can't use gtk_rc_parse to parse theme files because if we do + * so they get added to the list of rc files for Gtk widgets. Then, + * the next time you update the theme and parse a new GtkRc file, + * you still have the old values if the new theme does not override + * them. + * + * Thus, we create a temp file that we add to the list of default + * GtkRc files. This file will only contain an include to the actual + * theme file. That way we only have to call gtk_rc_reparse_all to + * update notifications' style. + * + * This has to be done before gtk_init. */ + + temp_theme_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_cache_dir(), + "xfce4-notifyd-theme.rc", NULL); + + gtk_rc_add_default_file(temp_theme_file); + gtk_init(&argc, &argv); xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8"); @@ -69,6 +93,10 @@ main(int argc, gtk_main(); + /* Remove the temp file for themes */ + g_unlink(temp_theme_file); + g_free(temp_theme_file); + g_object_unref(G_OBJECT(xndaemon)); return 0; diff --git a/xfce4-notifyd/xfce-notify-daemon.c b/xfce4-notifyd/xfce-notify-daemon.c index 3c02712..ec2972a 100644 --- a/xfce4-notifyd/xfce-notify-daemon.c +++ b/xfce4-notifyd/xfce-notify-daemon.c @@ -1119,23 +1119,54 @@ static void xfce_notify_daemon_set_theme(XfceNotifyDaemon *xndaemon, const gchar *theme) { - gchar *file, **files; + GError *error = NULL; + gchar *file, **files; + gchar *string; + gchar *temp_theme_file; + + DBG("New theme: %s", theme); + + /* See main.c for an explanation on how the theming works and why + * we use this temp file including the real file */ + + temp_theme_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_cache_dir(), + "xfce4-notifyd-theme.rc", NULL); /* old-style ~/.themes ... */ file = g_build_filename(xfce_get_homedir(), ".themes", theme, "xfce-notify-4.0", "gtkrc", NULL); if(g_file_test(file, G_FILE_TEST_EXISTS)) { - gtk_rc_parse(file); + string = g_strconcat("include \"", file, "\"", NULL); + if (!g_file_set_contents (temp_theme_file, string, -1, &error)) { + xfce_dialog_show_error (NULL, error, + _("Failed to set new theme")); + g_error_free (error); + } + else + gtk_rc_reparse_all (); + g_free(file); + g_free(string); + g_free(temp_theme_file); + return; } g_free(file); file = g_strconcat("themes/", theme, "/xfce-notify-4.0/gtkrc", NULL); files = xfce_resource_lookup_all(XFCE_RESOURCE_DATA, file); - if(files[0]) - gtk_rc_parse(files[0]); + string = g_strconcat("include \"", files[0], "\"", NULL); + if (!g_file_set_contents (temp_theme_file, string, -1, &error)) { + xfce_dialog_show_error (NULL, error, + _("Failed to set new theme")); + g_error_free (error); + } + else + gtk_rc_reparse_all (); + + g_free(string); + g_free(temp_theme_file); g_free(file); g_strfreev(files); } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits