[Xfce4-commits] <xfdesktop:eric/settings-changes> Add a chronological backdrop cycle option
Eric Koegel
noreply at xfce.org
Mon Oct 21 08:14:01 CEST 2013
Updating branch refs/heads/eric/settings-changes
to d12988225513fff7c219df973dd11e18a4670a27 (commit)
from 8ee9256cf6459ee827d8a98e09fa51e0ca7e2a30 (commit)
commit d12988225513fff7c219df973dd11e18a4670a27
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Mon Oct 21 09:11:46 2013 +0300
Add a chronological backdrop cycle option
When cycling backdrops sequentially with a period of hourly, setting
this option causes xfdesktop to map files in the selected directory
to hours of the day. Fewer images in the directory than hours in the
day are handled by repeating images to scale them over the time range.
That means there will be at most 24 images displayed showing the first
image from midnight to one, the second from one until two o'clock,
etc. If there were 6 images in the directory then every image would
be displayed for 4 hour time intervals before advancing. If there's
more images in the folder than hours then they won't be shown.
The entire point is that the user can have darker backdrops shown at
night or do other fancy time of day image selections (i.e. one image
in the morning, one in the afternoon, one in the evening, etc).
common/xfdesktop-common.c | 128 --------
common/xfdesktop-common.h | 3 -
settings/main.c | 36 +++
.../xfdesktop-settings-appearance-frame-ui.glade | 16 +
src/xfce-backdrop.c | 310 +++++++++++++++++++-
src/xfce-backdrop.h | 6 +
src/xfce-workspace.c | 32 +-
7 files changed, 372 insertions(+), 159 deletions(-)
diff --git a/common/xfdesktop-common.c b/common/xfdesktop-common.c
index bf86ba4..2011e6c 100644
--- a/common/xfdesktop-common.c
+++ b/common/xfdesktop-common.c
@@ -53,134 +53,6 @@
#include "xfdesktop-common.h"
#include "xfce-backdrop.h" /* for XfceBackdropImageStyle */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-static GList *
-list_files_in_dir(const gchar *path)
-{
- GDir *dir;
- gboolean needs_slash = TRUE;
- const gchar *file;
- GList *files = NULL;
-
- dir = g_dir_open(path, 0, 0);
- if(!dir)
- return NULL;
-
- if(path[strlen(path)-1] == '/')
- needs_slash = FALSE;
-
- while((file = g_dir_read_name(dir))) {
- gchar *current_file = g_strdup_printf(needs_slash ? "%s/%s" : "%s%s",
- path, file);
-
- files = g_list_insert_sorted(files, current_file, (GCompareFunc)g_strcmp0);
- }
-
- g_dir_close(dir);
-
- return files;
-}
-
-/* Gets the next valid image file in the folder. Free when done using it
- * returns NULL on fail. */
-gchar *
-xfdesktop_backdrop_choose_next(const gchar *filename)
-{
- GList *files, *current_file, *start_file;
- gchar *file = NULL;
-
- g_return_val_if_fail(filename, NULL);
-
- /* We don't cache the list at all. This way the user can add/remove items
- * whenever they like without xfdesktop having to do anything */
- files = list_files_in_dir(g_path_get_dirname(filename));
- if(!files)
- return NULL;
-
- /* Get the our current background in the list */
- current_file = g_list_find_custom(files, filename, (GCompareFunc)g_strcmp0);
-
- /* if somehow we don't have a valid file, grab the first one available */
- if(current_file == NULL)
- current_file = g_list_first(files);
-
- start_file = current_file;
-
- /* We want the next valid image file in the dir while making sure
- * we don't loop on ourselves */
- do {
- current_file = g_list_next(current_file);
-
- /* we hit the end of the list */
- if(current_file == NULL)
- current_file = g_list_first(files);
-
- /* We went through every item in the list */
- if(g_strcmp0(start_file->data, current_file->data) == 0)
- break;
-
- } while(!xfdesktop_image_file_is_valid(current_file->data));
-
- file = g_strdup(current_file->data);
- g_list_free_full(files, g_free);
-
- return file;
-}
-
-/* Gets a random valid image file in the folder. Free when done using it.
- * returns NULL on fail. */
-gchar *
-xfdesktop_backdrop_choose_random(const gchar *filename)
-{
- static gint previndex = -1;
- GList *files;
- gchar *file = NULL;
- gint n_items = 0, cur_file, tries = 0;
-
- g_return_val_if_fail(filename, NULL);
-
- /* We don't cache the list at all. This way the user can add/remove items
- * whenever they like without xfdesktop having to do anything */
- files = list_files_in_dir(g_path_get_dirname(filename));
- if(!files)
- return NULL;
-
- n_items = g_list_length(files);
-
- /* If there's only 1 item, just return it, easy */
- if(1 == n_items) {
- file = g_strdup(g_list_first(files)->data);
- g_list_free_full(files, g_free);
- return file;
- }
-
- do {
- if(tries++ == n_items) {
- /* this isn't precise, but if we've failed to get a good
- * image after all this time, let's just give up */
- g_warning("Unable to find good image from list; giving up");
- g_list_free_full(files, g_free);
- return NULL;
- }
-
- do {
- /* g_random_int_range bounds to n_items-1 */
- cur_file = g_random_int_range(0, n_items);
- } while(cur_file == previndex && G_LIKELY(previndex != -1));
-
- } while(!xfdesktop_image_file_is_valid(g_list_nth(files, cur_file)->data));
-
- previndex = cur_file;
-
- /* Keep a copy of our new random item, free everything else */
- file = g_strdup(g_list_nth(files, cur_file)->data);
- g_list_free_full(files, g_free);
-
- return file;
-}
gchar *
xfdesktop_get_file_mimetype(const gchar *file)
diff --git a/common/xfdesktop-common.h b/common/xfdesktop-common.h
index 88e86c5..dde3fa40 100644
--- a/common/xfdesktop-common.h
+++ b/common/xfdesktop-common.h
@@ -85,9 +85,6 @@
G_BEGIN_DECLS
-gchar *xfdesktop_backdrop_choose_next(const gchar *filename);
-gchar *xfdesktop_backdrop_choose_random(const gchar *filename);
-
gboolean xfdesktop_image_file_is_valid(const gchar *filename);
gchar *xfdesktop_get_file_mimetype(const gchar *file);
diff --git a/settings/main.c b/settings/main.c
index cbc7e2d..7122d35 100644
--- a/settings/main.c
+++ b/settings/main.c
@@ -114,6 +114,7 @@ typedef struct
GtkWidget *combo_backdrop_cycle_period;
GtkWidget *backdrop_cycle_spinbox;
GtkWidget *random_backdrop_order_chkbox;
+ GtkWidget *chrono_backdrop_order_chkbox;
GThread *preview_thread;
GAsyncQueue *preview_queue;
@@ -900,6 +901,25 @@ update_backdrop_cycle_spinbox(AppearancePanel *panel)
}
static void
+update_backdrop_chrono_order_chkbox(AppearancePanel *panel)
+{
+ gboolean sensitive = FALSE;
+ gint period;
+
+ /* For this check box to be active the combo_backdrop_cycle_period needs
+ * to be active and needs to be set to hourly so it would apply */
+ if(gtk_widget_get_sensitive(panel->combo_backdrop_cycle_period)) {
+ period = gtk_combo_box_get_active(GTK_COMBO_BOX(panel->combo_backdrop_cycle_period));
+ if(period == XFCE_BACKDROP_PERIOD_HOURLY)
+ {
+ sensitive = TRUE;
+ }
+ }
+
+ gtk_widget_set_sensitive(panel->chrono_backdrop_order_chkbox, sensitive);
+}
+
+static void
cb_combo_backdrop_cycle_period_change(GtkComboBox *combo,
gpointer user_data)
{
@@ -907,6 +927,8 @@ cb_combo_backdrop_cycle_period_change(GtkComboBox *combo,
/* determine if the spin box should be sensitive */
update_backdrop_cycle_spinbox(panel);
+ /* same with the chronological backdrop order */
+ update_backdrop_chrono_order_chkbox(panel);
}
static void
@@ -927,6 +949,8 @@ cb_xfdesktop_chk_cycle_backdrop_toggled(GtkCheckButton *button,
gtk_widget_set_sensitive(panel->random_backdrop_order_chkbox, sensitive);
/* determine if the spin box should be sensitive */
update_backdrop_cycle_spinbox(panel);
+ /* same with the chronological backdrop order */
+ update_backdrop_chrono_order_chkbox(panel);
}
static gboolean
@@ -1316,6 +1340,16 @@ xfdesktop_settings_background_tab_change_bindings(AppearancePanel *panel,
}
g_free(buf);
+ /* chronological order check box */
+ buf = xfdesktop_settings_generate_per_workspace_binding_string(panel, "backdrop-cycle-chronological-order");
+ if(remove_binding) {
+ xfconf_g_property_unbind_by_property(channel, buf,
+ G_OBJECT(panel->chrono_backdrop_order_chkbox), "active");
+ } else {
+ xfconf_g_property_bind(channel, buf, G_TYPE_BOOLEAN,
+ G_OBJECT(panel->chrono_backdrop_order_chkbox), "active");
+ }
+ g_free(buf);
}
static void
@@ -1726,6 +1760,8 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
"spin_backdrop_time"));
panel->random_backdrop_order_chkbox = GTK_WIDGET(gtk_builder_get_object(appearance_gxml,
"chk_random_backdrop_order"));
+ panel->chrono_backdrop_order_chkbox = GTK_WIDGET(gtk_builder_get_object(appearance_gxml,
+ "chk_chrono_backdrop_order"));
/* Pick the first entry so something shows up */
gtk_combo_box_set_active(GTK_COMBO_BOX(panel->combo_backdrop_cycle_period), XFCE_BACKDROP_PERIOD_MINUES);
diff --git a/settings/xfdesktop-settings-appearance-frame-ui.glade b/settings/xfdesktop-settings-appearance-frame-ui.glade
index a878fad..bfa1f66 100644
--- a/settings/xfdesktop-settings-appearance-frame-ui.glade
+++ b/settings/xfdesktop-settings-appearance-frame-ui.glade
@@ -325,6 +325,22 @@
<property name="label" translatable="yes">_Random Order</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
+ <property name="tooltip-text" translatable="yes">Randomly selects another image from the same directory when the wallpaper is to cycle. Overrides the Chronological option.</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="chk_chrono_backdrop_order">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">C_hronological</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="tooltip-text" translatable="yes">Chronologically maps images in the folder to specific hours of the day. When every hour is selected the first image in the folder will be displayed from midnight to one in the morning, the second image will show at two in the morning, etc. If there are fewer items in the folder than hours in the day, the images will be spaced out accordingly. I.e. a folder with 4 items will display the first image from midnight to six in the morning, the second image will then be displayed until noon, etc. If there are more images than hours in the day then they won't be displayed with this option selected.</property>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/xfce-backdrop.c b/src/xfce-backdrop.c
index fb07043..10c146c 100644
--- a/src/xfce-backdrop.c
+++ b/src/xfce-backdrop.c
@@ -47,6 +47,10 @@
#define XFCE_BACKDROP_BUFFER_SIZE 32768
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
typedef struct _XfceBackdropImageData XfceBackdropImageData;
static void xfce_backdrop_finalize(GObject *object);
@@ -80,6 +84,10 @@ static void xfce_backdrop_file_input_stream_ready_cb(GObject *source_object,
static void xfce_backdrop_image_data_release(XfceBackdropImageData *image_data);
+gchar *xfce_backdrop_choose_next (const gchar *filename);
+gchar *xfce_backdrop_choose_random (const gchar *filename);
+gchar *xfce_backdrop_choose_chronological(const gchar *filename);
+
struct _XfceBackdropPriv
{
gint width, height;
@@ -100,6 +108,7 @@ struct _XfceBackdropPriv
guint cycle_timer_id;
XfceBackdropCyclePeriod cycle_period;
gboolean random_backdrop_order;
+ gboolean chrono_backdrop_order;
};
struct _XfceBackdropImageData
@@ -133,7 +142,8 @@ enum
PROP_BACKDROP_CYCLE_ENABLE,
PROP_BACKDROP_CYCLE_PERIOD,
PROP_BACKDROP_CYCLE_TIMER,
- PROP_BACKDROP_RANDOM_ORDER
+ PROP_BACKDROP_RANDOM_ORDER,
+ PROP_BACKDROP_CHRONO_ORDER,
};
static guint backdrop_signals[LAST_SIGNAL] = { 0, };
@@ -232,6 +242,198 @@ xfce_backdrop_clear_cached_image(XfceBackdrop *backdrop)
backdrop->priv->pix = NULL;
}
+static GList *
+list_files_in_dir(const gchar *path)
+{
+ GDir *dir;
+ gboolean needs_slash = TRUE;
+ const gchar *file;
+ GList *files = NULL;
+
+ dir = g_dir_open(path, 0, 0);
+ if(!dir)
+ return NULL;
+
+ if(path[strlen(path)-1] == '/')
+ needs_slash = FALSE;
+
+ while((file = g_dir_read_name(dir))) {
+ gchar *current_file = g_strdup_printf(needs_slash ? "%s/%s" : "%s%s",
+ path, file);
+
+ files = g_list_insert_sorted(files, current_file, (GCompareFunc)g_strcmp0);
+ }
+
+ g_dir_close(dir);
+
+ return files;
+}
+
+/* Gets the next valid image file in the folder. Free when done using it
+ * returns NULL on fail. */
+gchar *
+xfce_backdrop_choose_next(const gchar *filename)
+{
+ GList *files, *current_file, *start_file;
+ gchar *file = NULL;
+
+ TRACE("entering");
+
+ g_return_val_if_fail(filename, NULL);
+
+ /* We don't cache the list at all. This way the user can add/remove items
+ * whenever they like without xfdesktop having to do anything */
+ files = list_files_in_dir(g_path_get_dirname(filename));
+ if(!files)
+ return NULL;
+
+ /* Get the our current background in the list */
+ current_file = g_list_find_custom(files, filename, (GCompareFunc)g_strcmp0);
+
+ /* if somehow we don't have a valid file, grab the first one available */
+ if(current_file == NULL)
+ current_file = g_list_first(files);
+
+ start_file = current_file;
+
+ /* We want the next valid image file in the dir while making sure
+ * we don't loop on ourselves */
+ do {
+ current_file = g_list_next(current_file);
+
+ /* we hit the end of the list */
+ if(current_file == NULL)
+ current_file = g_list_first(files);
+
+ /* We went through every item in the list */
+ if(g_strcmp0(start_file->data, current_file->data) == 0)
+ break;
+
+ } while(!xfdesktop_image_file_is_valid(current_file->data));
+
+ /* Keep a copy of our new item, free everything else */
+ file = g_strdup(current_file->data);
+ g_list_free_full(files, g_free);
+
+ return file;
+}
+
+/* Gets a random valid image file in the folder. Free when done using it.
+ * returns NULL on fail. */
+gchar *
+xfce_backdrop_choose_random(const gchar *filename)
+{
+ static gint previndex = -1;
+ GList *files;
+ gchar *file = NULL;
+ gint n_items = 0, cur_file, tries = 0;
+
+ TRACE("entering");
+
+ g_return_val_if_fail(filename, NULL);
+
+ /* We don't cache the list at all. This way the user can add/remove items
+ * whenever they like without xfdesktop having to do anything */
+ files = list_files_in_dir(g_path_get_dirname(filename));
+ if(!files)
+ return NULL;
+
+ n_items = g_list_length(files);
+
+ /* If there's only 1 item, just return it, easy */
+ if(1 == n_items) {
+ file = g_strdup(g_list_first(files)->data);
+ g_list_free_full(files, g_free);
+ return file;
+ }
+
+ do {
+ if(tries++ == n_items) {
+ /* this isn't precise, but if we've failed to get a good
+ * image after all this time, let's just give up */
+ g_warning("Unable to find good image from list; giving up");
+ g_list_free_full(files, g_free);
+ return NULL;
+ }
+
+ do {
+ /* g_random_int_range bounds to n_items-1 */
+ cur_file = g_random_int_range(0, n_items);
+ } while(cur_file == previndex && G_LIKELY(previndex != -1));
+
+ } while(!xfdesktop_image_file_is_valid(g_list_nth(files, cur_file)->data));
+
+ previndex = cur_file;
+
+ /* Keep a copy of our new random item, free everything else */
+ file = g_strdup(g_list_nth(files, cur_file)->data);
+ g_list_free_full(files, g_free);
+
+ return file;
+}
+
+/* Provides a mapping of image files in the parent folder of file. It selects
+ * the image based on the hour of the day scaled for how many images are in
+ * the directory, using the first 24 if there are more.
+ * Returns a new image path or NULL on failure. Free when done using it. */
+gchar *
+xfce_backdrop_choose_chronological(const gchar *filename)
+{
+ GDateTime *datetime;
+ GList *files, *current_file, *start_file;
+ gchar *file = NULL;
+ gint n_items = 0, epoch;
+
+ TRACE("entering");
+
+ g_return_val_if_fail(filename, NULL);
+
+ /* We don't cache the list at all. This way the user can add/remove items
+ * whenever they like without xfdesktop having to do anything. If we start
+ * supporting sub-directories we may want to re-think that assumption */
+ files = list_files_in_dir(g_path_get_dirname(filename));
+ if(!files)
+ return NULL;
+
+ n_items = g_list_length(files);
+
+ /* If there's only 1 item, just return it, easy */
+ if(1 == n_items) {
+ file = g_strdup(g_list_first(files)->data);
+ g_list_free_full(files, g_free);
+ return file;
+ }
+
+ datetime = g_date_time_new_now_local();
+
+ /* Figure out which image to display based on what time of day it is
+ * and how many images we have to work with */
+ epoch = (gdouble)g_date_time_get_hour(datetime) / (24.0f / MIN(n_items, 24.0f));
+ DBG("epoch %d, hour %d, items %d", epoch, g_date_time_get_minute(datetime), n_items);
+
+ start_file = current_file = g_list_nth(files, epoch);
+
+ /* We want the next valid image file in the dir while making sure
+ * we don't loop on ourselves */
+ while(!xfdesktop_image_file_is_valid(current_file->data)) {
+ current_file = g_list_next(current_file);
+
+ /* we hit the end of the list */
+ if(current_file == NULL)
+ current_file = g_list_first(files);
+
+ /* We went through every item in the list */
+ if(g_strcmp0(start_file->data, current_file->data) == 0)
+ break;
+ }
+
+ /* Keep a copy of our new item, free everything else */
+ file = g_strdup(current_file->data);
+ g_list_free_full(files, g_free);
+ g_date_time_unref(datetime);
+
+ return file;
+}
/* gobject-related functions */
@@ -341,6 +543,13 @@ xfce_backdrop_class_init(XfceBackdropClass *klass)
FALSE,
XFDESKTOP_PARAM_FLAGS));
+ g_object_class_install_property(gobject_class, PROP_BACKDROP_CHRONO_ORDER,
+ g_param_spec_boolean("backdrop-cycle-chronological-order",
+ "backdrop-cycle-chronological-order",
+ "backdrop-cycle-chronological-order",
+ FALSE,
+ XFDESKTOP_PARAM_FLAGS));
+
#undef XFDESKTOP_PARAM_FLAGS
}
@@ -431,6 +640,10 @@ xfce_backdrop_set_property(GObject *object,
xfce_backdrop_set_random_order(backdrop, g_value_get_boolean(value));
break;
+ case PROP_BACKDROP_CHRONO_ORDER:
+ xfce_backdrop_set_chronological_order(backdrop, g_value_get_boolean(value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
@@ -483,6 +696,10 @@ xfce_backdrop_get_property(GObject *object,
g_value_set_boolean(value, xfce_backdrop_get_random_order(backdrop));
break;
+ case PROP_BACKDROP_CHRONO_ORDER:
+ g_value_set_boolean(value, xfce_backdrop_get_chronological_order(backdrop));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
@@ -717,6 +934,10 @@ xfce_backdrop_set_image_filename(XfceBackdrop *backdrop, const gchar *filename)
TRACE("entering, filename %s", filename);
+ /* Don't do anything if the filename doesn't change */
+ if(g_strcmp0(backdrop->priv->image_path, filename) == 0)
+ return;
+
g_free(backdrop->priv->image_path);
if(filename)
@@ -736,6 +957,45 @@ xfce_backdrop_get_image_filename(XfceBackdrop *backdrop)
return backdrop->priv->image_path;
}
+static void
+xfce_backdrop_cycle_backdrop(XfceBackdrop *backdrop)
+{
+ XfceBackdropCyclePeriod period;
+ gchar *current_backdrop, *new_backdrop;
+
+ TRACE("entering");
+
+ g_return_if_fail(XFCE_IS_BACKDROP(backdrop));
+
+ current_backdrop = backdrop->priv->image_path;
+ period = backdrop->priv->cycle_period;
+
+ /* sanity checks */
+ if(current_backdrop == NULL || !backdrop->priv->cycle_backdrop)
+ return;
+
+ if(backdrop->priv->random_backdrop_order) {
+ /* Random always takes priority */
+ new_backdrop = xfce_backdrop_choose_random(current_backdrop);
+ }
+ else if(backdrop->priv->chrono_backdrop_order && period == XFCE_BACKDROP_PERIOD_HOURLY)
+ {
+ /* chronological */
+ new_backdrop = xfce_backdrop_choose_chronological(current_backdrop);
+ }
+ else
+ {
+ /* sequential, the default */
+ new_backdrop = xfce_backdrop_choose_next(current_backdrop);
+ }
+
+ /* Only emit the cycle signal if something changed */
+ if(g_strcmp0(backdrop->priv->image_path, new_backdrop) != 0) {
+ xfce_backdrop_set_image_filename(backdrop, new_backdrop);
+ g_signal_emit(G_OBJECT(backdrop), backdrop_signals[BACKDROP_CYCLE], 0);
+ }
+}
+
static gboolean
xfce_backdrop_timer(XfceBackdrop *backdrop)
{
@@ -750,7 +1010,7 @@ xfce_backdrop_timer(XfceBackdrop *backdrop)
/* Don't bother with trying to cycle a backdrop if we're not using images */
if(backdrop->priv->image_style != XFCE_BACKDROP_IMAGE_NONE)
- g_signal_emit(G_OBJECT(backdrop), backdrop_signals[BACKDROP_CYCLE], 0);
+ xfce_backdrop_cycle_backdrop(backdrop);
/* Now to complicate things; we have to handle some special cases */
switch(backdrop->priv->cycle_period) {
@@ -766,7 +1026,6 @@ xfce_backdrop_timer(XfceBackdrop *backdrop)
second = g_date_time_get_second(local_time);
/* find out how long until the next hour so we cycle on the hour */
- DBG("minute %d, second %d", minute, second);
cycle_interval = ((59 - minute) * 60) + (60 - second);
/* We created a new instance, kill this one */
@@ -781,7 +1040,6 @@ xfce_backdrop_timer(XfceBackdrop *backdrop)
second = g_date_time_get_second(local_time);
/* find out how long until the next day so we cycle on the day */
- DBG("hour %d minute %d, second %d", hour, minute, second);
cycle_interval = ((23 - hour) * 60 * 60) + ((59 - minute) * 60) + (60 - second);
/* We created a new instance, kill this one */
@@ -866,7 +1124,6 @@ xfce_backdrop_set_cycle_timer(XfceBackdrop *backdrop, guint cycle_timer)
second = g_date_time_get_second(local_time);
/* find out how long until the next hour so we cycle on the hour */
- DBG("minute %d, second %d", minute, second);
cycle_interval = ((59 - minute) * 60) + (60 - second);
break;
@@ -878,7 +1135,6 @@ xfce_backdrop_set_cycle_timer(XfceBackdrop *backdrop, guint cycle_timer)
second = g_date_time_get_second(local_time);
/* find out how long until the next day so we cycle on the day */
- DBG("hour %d minute %d, second %d", hour, minute, second);
cycle_interval = ((23 - hour) * 60 * 60) + ((59 - minute) * 60) + (60 - second);
break;
@@ -978,7 +1234,8 @@ xfce_backdrop_get_cycle_period(XfceBackdrop *backdrop)
*
* When cycling backdrops, they will either be show sequentially (and this value
* will be FALSE) or they will be selected at random. The images are choosen from
- * the same folder the current backdrop image file is in.
+ * the same folder the current backdrop image file is in. This option overrides
+ * the chronological order if it is also set.
**/
void
xfce_backdrop_set_random_order(XfceBackdrop *backdrop,
@@ -999,6 +1256,45 @@ xfce_backdrop_get_random_order(XfceBackdrop *backdrop)
return backdrop->priv->random_backdrop_order;
}
+/**
+ * xfce_backdrop_set_chronological_order:
+ * @backdrop: An #XfceBackdrop.
+ * @chronological_order: When TRUE and the backdrops are set to cycle and
+ * the period is set to XFCE_BACKDROP_PERIOD_HOURLY
+ * then the backdrops in the folder will be mapped at
+ * the next hour.
+ *
+ * When cycling backdrops sequentially with a period of XFCE_BACKDROP_PERIOD_HOURLY,
+ * setting this option causes xfdesktop to map files in the selected directory
+ * to hours of the day. Fewer images in the directory than hours in the day are
+ * handled by repeating images to scale them over the time range. That means
+ * there will be at most 24 images displayed showing the first image from
+ * midnight to one, the second from one until two o'clock, etc. If there were 6
+ * images in the directory then every image would be displayed for 4 hour time
+ * intervals before advancing. If there's more images in the folder than hours
+ * then they won't be shown.
+ **/
+void
+xfce_backdrop_set_chronological_order(XfceBackdrop *backdrop,
+ gboolean chronological_order)
+{
+ g_return_if_fail(XFCE_IS_BACKDROP(backdrop));
+
+ TRACE("entering");
+
+ backdrop->priv->chrono_backdrop_order = chronological_order;
+}
+
+gboolean
+xfce_backdrop_get_chronological_order(XfceBackdrop *backdrop)
+{
+ g_return_val_if_fail(XFCE_IS_BACKDROP(backdrop), FALSE);
+
+ return backdrop->priv->chrono_backdrop_order;
+}
+
+/* Generates the background that will either be displayed or will have the
+ * image drawn on top of */
static GdkPixbuf *
xfce_backdrop_generate_canvas(XfceBackdrop *backdrop)
{
diff --git a/src/xfce-backdrop.h b/src/xfce-backdrop.h
index 3de02d0..5e89a09 100644
--- a/src/xfce-backdrop.h
+++ b/src/xfce-backdrop.h
@@ -142,6 +142,12 @@ void xfce_backdrop_set_random_order (XfceBackdrop *backdrop,
gboolean random_order);
gboolean xfce_backdrop_get_random_order (XfceBackdrop *backdrop);
+void xfce_backdrop_set_chronological_order
+ (XfceBackdrop *backdrop,
+ gboolean random_order);
+gboolean xfce_backdrop_get_chronological_order
+ (XfceBackdrop *backdrop);
+
GdkPixbuf *xfce_backdrop_get_pixbuf (XfceBackdrop *backdrop);
void xfce_backdrop_generate_async (XfceBackdrop *backdrop);
diff --git a/src/xfce-workspace.c b/src/xfce-workspace.c
index 9d33a6f..af21f7a 100644
--- a/src/xfce-workspace.c
+++ b/src/xfce-workspace.c
@@ -170,33 +170,18 @@ xfce_workspace_change_backdrop(XfceWorkspace *workspace,
static void
backdrop_cycle_cb(XfceBackdrop *backdrop, gpointer user_data)
{
- const gchar* backdrop_file;
- gchar *new_backdrop = NULL;
XfceWorkspace *workspace = XFCE_WORKSPACE(user_data);
+ const gchar *new_backdrop;
TRACE("entering");
g_return_if_fail(XFCE_IS_BACKDROP(backdrop));
- backdrop_file = xfce_backdrop_get_image_filename(backdrop);
+ new_backdrop = xfce_backdrop_get_image_filename(backdrop);
- if(backdrop_file == NULL)
- return;
-
- if(xfce_backdrop_get_random_order(backdrop)) {
- DBG("Random! current file: %s", backdrop_file);
- new_backdrop = xfdesktop_backdrop_choose_random(backdrop_file);
- } else {
- DBG("Next! current file: %s", backdrop_file);
- new_backdrop = xfdesktop_backdrop_choose_next(backdrop_file);
- }
- DBG("new file: %s for Workspace %d", new_backdrop,
- xfce_workspace_get_workspace_num(workspace));
-
- if(g_strcmp0(backdrop_file, new_backdrop) != 0) {
+ /* update the xfconf property */
+ if(new_backdrop != NULL)
xfce_workspace_change_backdrop(workspace, backdrop, new_backdrop);
- g_free(new_backdrop);
- }
}
static void
@@ -491,8 +476,8 @@ xfce_workspace_migrate_backdrop_image_style(XfceWorkspace *workspace,
xfce_backdrop_set_image_style(backdrop, style);
g_value_unset(&value);
} else {
- /* If no value was ever set default to stretched */
- xfce_backdrop_set_image_style(backdrop, XFCE_BACKDROP_IMAGE_STRETCHED);
+ /* If no value was ever set default to stretched */
+ xfce_backdrop_set_image_style(backdrop, XFCE_BACKDROP_IMAGE_STRETCHED);
}
}
@@ -561,6 +546,11 @@ xfce_workspace_connect_backdrop_settings(XfceWorkspace *workspace,
G_OBJECT(backdrop), "backdrop-cycle-random-order");
buf[pp_len] = 0;
+ g_strlcat(buf, "backdrop-cycle-chronological-order", sizeof(buf));
+ xfconf_g_property_bind(channel, buf, G_TYPE_BOOLEAN,
+ G_OBJECT(backdrop), "backdrop-cycle-chronological-order");
+
+ buf[pp_len] = 0;
g_strlcat(buf, "last-image", sizeof(buf));
xfconf_g_property_bind(channel, buf, G_TYPE_STRING,
G_OBJECT(backdrop), "image-filename");
More information about the Xfce4-commits
mailing list