From c9e86eff9a1740e21d491d1887f2bfc9d7266e76 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sun, 15 Mar 2015 14:52:06 +0300 Subject: [PATCH] Monitor the wallpaper file for changes (Bug #11620) Since Xfdesktop is already monitoring the wallpaper folder for files being added and removed, have it also monitor and update the current background when it is changed. This way user's custom scripts can update the background without having to reload all the desktop icons as well. --- src/xfce-backdrop.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/xfce-backdrop.c b/src/xfce-backdrop.c index 600b82e..955a383 100644 --- a/src/xfce-backdrop.c +++ b/src/xfce-backdrop.c @@ -276,6 +276,8 @@ cb_xfce_backdrop__image_files_changed(GFileMonitor *monitor, case G_FILE_MONITOR_EVENT_CREATED: changed_file = g_file_get_path(file); + XF_DEBUG("file added: %s", changed_file); + /* Make sure we don't already have the new file in the list */ if(g_list_find(backdrop->priv->image_files, changed_file)) { g_free(changed_file); @@ -299,6 +301,8 @@ cb_xfce_backdrop__image_files_changed(GFileMonitor *monitor, case G_FILE_MONITOR_EVENT_DELETED: changed_file = g_file_get_path(file); + XF_DEBUG("file deleted: %s", changed_file); + /* find the file in the list */ item = g_list_find_custom(backdrop->priv->image_files, changed_file, @@ -310,6 +314,23 @@ cb_xfce_backdrop__image_files_changed(GFileMonitor *monitor, g_free(changed_file); break; + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: + changed_file = g_file_get_path(file); + + XF_DEBUG("file changed: %s", changed_file); + XF_DEBUG("image_path: %s", backdrop->priv->image_path); + + if(g_strcmp0(changed_file, backdrop->priv->image_path) == 0) { + DBG("match"); + /* clear the outdated backdrop */ + xfce_backdrop_clear_cached_image(backdrop); + + /* backdrop changed! */ + g_signal_emit(G_OBJECT(backdrop), backdrop_signals[BACKDROP_CHANGED], 0); + } + + g_free(changed_file); + break; default: break; } @@ -354,6 +375,8 @@ list_image_files_in_dir(const gchar *filename) static void xfce_backdrop_load_image_files(XfceBackdrop *backdrop) { + TRACE("entering"); + /* generate the image_files list if it doesn't exist and monitor that * directory so we can update the list */ if(backdrop->priv->image_files == NULL && backdrop->priv->image_path) { @@ -395,9 +418,6 @@ xfce_backdrop_choose_next(XfceBackdrop *backdrop) filename = backdrop->priv->image_path; - if(backdrop->priv->image_files == NULL) - xfce_backdrop_load_image_files(backdrop); - if(!backdrop->priv->image_files) return NULL; @@ -432,8 +452,6 @@ xfce_backdrop_choose_random(XfceBackdrop *backdrop) g_return_val_if_fail(XFCE_IS_BACKDROP(backdrop), NULL); - xfce_backdrop_load_image_files(backdrop); - if(!backdrop->priv->image_files) return NULL; @@ -470,8 +488,6 @@ xfce_backdrop_choose_chronological(XfceBackdrop *backdrop) g_return_val_if_fail(XFCE_IS_BACKDROP(backdrop), NULL); - xfce_backdrop_load_image_files(backdrop); - if(!backdrop->priv->image_files) return NULL; @@ -1038,6 +1054,8 @@ xfce_backdrop_set_image_filename(XfceBackdrop *backdrop, const gchar *filename) xfce_backdrop_clear_cached_image(backdrop); + xfce_backdrop_load_image_files(backdrop); + g_signal_emit(G_OBJECT(backdrop), backdrop_signals[BACKDROP_CHANGED], 0); } -- 2.3.1