Updating branch refs/heads/master to 600504bab2c3067515e225136afa765a6e93e6bb (commit) from 1264428edda474f7c59befee1b0d779bc385fc14 (commit)
commit 600504bab2c3067515e225136afa765a6e93e6bb Author: Eric Koegel <eric.koe...@gmail.com> Date: Sun Feb 12 13:12:32 2012 +0300 Backdrop image cycling on a timer This code adds the ability to change the backdrop image when it's set to an image-list and the backdrop-cycle-enable setting is TRUE. It will then change the background every backdrop-cycle-timer minutes. The settings app allows the user to change these settings. Bug 4850 settings/main.c | 47 ++++++ .../xfdesktop-settings-appearance-frame-ui.glade | 48 ++++++ src/xfce-backdrop.c | 158 +++++++++++++++++++- src/xfce-backdrop.h | 14 ++ src/xfce-desktop.c | 48 ++++++- 5 files changed, 312 insertions(+), 3 deletions(-) diff --git a/settings/main.c b/settings/main.c index a6be3b8..9442f30 100644 --- a/settings/main.c +++ b/settings/main.c @@ -104,6 +104,9 @@ typedef struct GtkWidget *brightness_slider; GtkWidget *saturation_slider; + + GtkWidget *backdrop_cycle_spinbox; + GtkWidget *backdrop_cycle_chkbox; } AppearancePanel; typedef struct @@ -758,6 +761,21 @@ cb_xfdesktop_chk_custom_font_size_toggled(GtkCheckButton *button, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))); } +static void +cb_xfdesktop_chk_cycle_backdrop_toggled(GtkCheckButton *button, + gpointer user_data) +{ + gboolean sensitive = FALSE; + GtkWidget *spin_button = GTK_WIDGET(user_data); + + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) && + gtk_widget_get_sensitive(GTK_WIDGET(button))) { + sensitive = TRUE; + } + + gtk_widget_set_sensitive(spin_button, sensitive); +} + static gboolean xfdesktop_spin_icon_size_timer(GtkSpinButton *button) { @@ -1024,6 +1042,8 @@ cb_image_type_radio_clicked(GtkWidget *w, gtk_widget_set_sensitive(panel->btn_minus, FALSE); gtk_widget_set_sensitive(panel->btn_newlist, FALSE); gtk_widget_set_sensitive(panel->frame_image_list, TRUE); + gtk_widget_set_sensitive(panel->backdrop_cycle_chkbox, FALSE); + gtk_widget_set_sensitive(panel->backdrop_cycle_spinbox, FALSE); DBG("show_image=%s", panel->show_image?"true":"false"); if(!panel->show_image) { panel->show_image = TRUE; @@ -1049,6 +1069,11 @@ cb_image_type_radio_clicked(GtkWidget *w, gtk_widget_set_sensitive(panel->btn_minus, TRUE); gtk_widget_set_sensitive(panel->btn_newlist, TRUE); gtk_widget_set_sensitive(panel->frame_image_list, TRUE); + gtk_widget_set_sensitive(panel->backdrop_cycle_chkbox, TRUE); + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(panel->backdrop_cycle_chkbox))) + gtk_widget_set_sensitive(panel->backdrop_cycle_spinbox, TRUE); + else + gtk_widget_set_sensitive(panel->backdrop_cycle_spinbox, FALSE); DBG("show_image=%s", panel->show_image?"true":"false"); if(!panel->show_image) { panel->show_image = TRUE; @@ -1057,6 +1082,8 @@ cb_image_type_radio_clicked(GtkWidget *w, } else if(w == panel->radio_none) { DBG("widget is none"); gtk_widget_set_sensitive(panel->frame_image_list, FALSE); + gtk_widget_set_sensitive(panel->backdrop_cycle_chkbox, FALSE); + gtk_widget_set_sensitive(panel->backdrop_cycle_spinbox, FALSE); DBG("show_image=%s", panel->show_image?"true":"false"); if(panel->show_image) { panel->show_image = FALSE; @@ -1433,6 +1460,26 @@ xfdesktop_settings_dialog_add_screens(GtkBuilder *main_gxml, g_signal_connect(G_OBJECT(panel->btn_newlist), "clicked", G_CALLBACK(newlist_button_clicked), panel); + panel->backdrop_cycle_chkbox = GTK_WIDGET(gtk_builder_get_object(appearance_gxml, + "chk_cycle_backdrop")); + panel->backdrop_cycle_spinbox = GTK_WIDGET(gtk_builder_get_object(appearance_gxml, + "spin_backdrop_time_minutes")); + + g_signal_connect(G_OBJECT(panel->backdrop_cycle_chkbox), "toggled", + G_CALLBACK(cb_xfdesktop_chk_cycle_backdrop_toggled), + panel->backdrop_cycle_spinbox); + + g_snprintf(buf, sizeof(buf), PER_SCREEN_PROP_FORMAT "/backdrop-cycle-enable", + i, j); + xfconf_g_property_bind(channel, buf, G_TYPE_BOOLEAN, + G_OBJECT(panel->backdrop_cycle_chkbox), "active"); + + g_snprintf(buf, sizeof(buf), PER_SCREEN_PROP_FORMAT "/backdrop-cycle-timer", + i, j); + xfconf_g_property_bind(channel, buf, G_TYPE_UINT, + G_OBJECT(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(panel->backdrop_cycle_spinbox))), + "value"); + panel->radio_singleimage = GTK_WIDGET(gtk_builder_get_object(appearance_gxml, "radio_singleimage")); g_signal_connect(G_OBJECT(panel->radio_singleimage), "toggled", diff --git a/settings/xfdesktop-settings-appearance-frame-ui.glade b/settings/xfdesktop-settings-appearance-frame-ui.glade index 3a4fed6..caf55fc 100644 --- a/settings/xfdesktop-settings-appearance-frame-ui.glade +++ b/settings/xfdesktop-settings-appearance-frame-ui.glade @@ -17,6 +17,14 @@ <property name="page_size">0</property> <property name="value">1</property> </object> + <object class="GtkAdjustment" id="adjustment3"> + <property name="upper">65535</property> + <property name="lower">1</property> + <property name="page_increment">10</property> + <property name="step_increment">1</property> + <property name="page_size">0</property> + <property name="value">10</property> + </object> <object class="GtkListStore" id="model1"> <columns> <column type="gchararray"/> @@ -528,6 +536,46 @@ <property name="position">1</property> </packing> </child> + <child> + <object class="GtkHBox" id="hbox9"> + <property name="visible">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="spacing">4</property> + <child> + <object class="GtkCheckButton" id="chk_cycle_backdrop"> + <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">_Change the background (in minutes):</property> + <property name="tooltip-text" translatable="yes">While in image list mode, select this option to automatically select a different background from the image list after a set number of minutes.</property> + <property name="use_underline">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + </packing> + </child> + <child> + <object class="GtkSpinButton" id="spin_backdrop_time_minutes"> + <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="adjustment">adjustment3</property> + <property name="tooltip-text" translatable="yes">Number of minutes before a different background is randomly selected from the list.</property> + </object> + <packing> + <property name="expand">False</property> + <property name="position">2</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">2</property> + </packing> + </child> </object> </child> </object> diff --git a/src/xfce-backdrop.c b/src/xfce-backdrop.c index 486a796..600d7fd 100644 --- a/src/xfce-backdrop.c +++ b/src/xfce-backdrop.c @@ -52,6 +52,7 @@ static void xfce_backdrop_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); +static void xfce_backdrop_timer(XfceBackdrop *backdrop); struct _XfceBackdropPriv { @@ -65,14 +66,20 @@ struct _XfceBackdropPriv gboolean show_image; XfceBackdropImageStyle image_style; gchar *image_path; + gchar *backdrop_list; gint brightness; gdouble saturation; + + gboolean cycle_backdrop; + guint cycle_timer; + guint cycle_timer_id; }; enum { BACKDROP_CHANGED, + BACKDROP_CYCLE, LAST_SIGNAL, }; @@ -87,6 +94,8 @@ enum PROP_IMAGE_FILENAME, PROP_BRIGHTNESS, PROP_SATURATION, + PROP_BACKDROP_CYCLE_ENABLE, + PROP_BACKDROP_CYCLE_TIMER, }; static guint backdrop_signals[LAST_SIGNAL] = { 0, }; @@ -240,6 +249,10 @@ xfce_backdrop_class_init(XfceBackdropClass *klass) G_OBJECT_CLASS_TYPE(gobject_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(XfceBackdropClass, changed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + backdrop_signals[BACKDROP_CYCLE] = g_signal_new("cycle", + G_OBJECT_CLASS_TYPE(gobject_class), G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(XfceBackdropClass, cycle), NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); #define XFDESKTOP_PARAM_FLAGS (G_PARAM_READWRITE \ | G_PARAM_CONSTRUCT \ @@ -305,6 +318,20 @@ xfce_backdrop_class_init(XfceBackdropClass *klass) -10.0, 10.0, 1.0, XFDESKTOP_PARAM_FLAGS)); + g_object_class_install_property(gobject_class, PROP_BACKDROP_CYCLE_ENABLE, + g_param_spec_boolean("backdrop-cycle-enable", + "backdrop-cycle-enable", + "backdrop-cycle-enable", + FALSE, + XFDESKTOP_PARAM_FLAGS)); + + g_object_class_install_property(gobject_class, PROP_BACKDROP_CYCLE_TIMER, + g_param_spec_uint("backdrop-cycle-timer", + "backdrop-cycle-timer", + "backdrop-cycle-timer", + 0, G_MAXUSHORT, 10, + XFDESKTOP_PARAM_FLAGS)); + #undef XFDESKTOP_PARAM_FLAGS } @@ -314,6 +341,8 @@ xfce_backdrop_init(XfceBackdrop *backdrop) backdrop->priv = G_TYPE_INSTANCE_GET_PRIVATE(backdrop, XFCE_TYPE_BACKDROP, XfceBackdropPriv); backdrop->priv->show_image = TRUE; + backdrop->priv->cycle_timer_id = 0; + backdrop->priv->backdrop_list = NULL; /* color defaults */ backdrop->priv->color1.red = 0x1515; @@ -333,7 +362,17 @@ xfce_backdrop_finalize(GObject *object) if(backdrop->priv->image_path) g_free(backdrop->priv->image_path); - + + if(backdrop->priv->cycle_timer_id != 0) { + g_source_remove(backdrop->priv->cycle_timer_id); + backdrop->priv->cycle_timer_id = 0; + } + + if(backdrop->priv->backdrop_list != NULL) { + g_free(backdrop->priv->backdrop_list); + backdrop->priv->backdrop_list = NULL; + } + G_OBJECT_CLASS(xfce_backdrop_parent_class)->finalize(object); } @@ -384,6 +423,14 @@ xfce_backdrop_set_property(GObject *object, xfce_backdrop_set_saturation(backdrop, g_value_get_double(value)); break; + case PROP_BACKDROP_CYCLE_ENABLE: + xfce_backdrop_set_cycle_backdrop(backdrop, g_value_get_boolean(value)); + break; + + case PROP_BACKDROP_CYCLE_TIMER: + xfce_backdrop_set_cycle_timer(backdrop, g_value_get_uint(value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; @@ -432,6 +479,14 @@ xfce_backdrop_get_property(GObject *object, g_value_set_double(value, xfce_backdrop_get_saturation(backdrop)); break; + case PROP_BACKDROP_CYCLE_ENABLE: + g_value_set_boolean(value, xfce_backdrop_get_cycle_backdrop(backdrop)); + break; + + case PROP_BACKDROP_CYCLE_TIMER: + g_value_set_uint(value, xfce_backdrop_get_cycle_timer(backdrop)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; @@ -701,6 +756,37 @@ xfce_backdrop_get_image_filename(XfceBackdrop *backdrop) } /** + * xfce_backdrop_set_list: + * @backdrop: An #XfceBackdrop. + * @backdrop_list: A list of backdrop images. + * + * Sets the internal list of wallpaper images assigned to this backdrop. + * Frees any previous backdrop list before setting the new one. + * [Transfer full] + **/ +void +xfce_backdrop_set_list(XfceBackdrop *backdrop, + gchar *backdrop_list) +{ + g_return_if_fail(XFCE_IS_BACKDROP(backdrop)); + + if(backdrop->priv->backdrop_list != NULL) { + g_free(backdrop->priv->backdrop_list); + backdrop->priv->backdrop_list = NULL; + } + + backdrop->priv->backdrop_list = backdrop_list; +} + +G_CONST_RETURN gchar* +xfce_backdrop_get_list(XfceBackdrop *backdrop) +{ + g_return_val_if_fail(XFCE_IS_BACKDROP(backdrop), NULL); + + return backdrop->priv->backdrop_list; +} + +/** * xfce_backdrop_set_brightness: * @backdrop: An #XfceBackdrop. * @brightness: A brightness value. @@ -745,6 +831,76 @@ xfce_backdrop_get_saturation(XfceBackdrop *backdrop) return backdrop->priv->saturation; } +static void +xfce_backdrop_timer(XfceBackdrop *backdrop) +{ + g_return_if_fail(XFCE_IS_BACKDROP(backdrop)); + + g_signal_emit(G_OBJECT(backdrop), backdrop_signals[BACKDROP_CYCLE], 0); +} + +/** + * xfce_backdrop_set_cycle_timer: + * @backdrop: An #XfceBackdrop. + * @cycle_timer: The amount of time, in minutes, to wait before changing the + * background image. + * + * If cycle_backdrop is enabled then this function will change the backdrop + * image based on the cycle_timer, a value between 0 and G_MAXUSHORT. + * A value of 0 indicates that the backdrop should not be changed. + **/ +void +xfce_backdrop_set_cycle_timer(XfceBackdrop *backdrop, guint cycle_timer) +{ + g_return_if_fail(XFCE_IS_BACKDROP(backdrop)); + + if(cycle_timer > G_MAXUSHORT) + cycle_timer = G_MAXUSHORT; + + backdrop->priv->cycle_timer = cycle_timer; + + if(backdrop->priv->cycle_timer_id != 0) { + g_source_remove(backdrop->priv->cycle_timer_id); + backdrop->priv->cycle_timer_id = 0; + } + + if(backdrop->priv->cycle_timer != 0 && + backdrop->priv->cycle_backdrop == TRUE) { + backdrop->priv->cycle_timer_id = g_timeout_add_seconds(backdrop->priv->cycle_timer * 60, + (GSourceFunc)xfce_backdrop_timer, + backdrop); + } +} + +guint +xfce_backdrop_get_cycle_timer(XfceBackdrop *backdrop) +{ + g_return_val_if_fail(XFCE_IS_BACKDROP(backdrop), 0); + return backdrop->priv->cycle_timer; +} + +void +xfce_backdrop_set_cycle_backdrop(XfceBackdrop *backdrop, + gboolean cycle_backdrop) +{ + g_return_if_fail(XFCE_IS_BACKDROP(backdrop)); + + if(backdrop->priv->cycle_backdrop != cycle_backdrop) { + backdrop->priv->cycle_backdrop = cycle_backdrop; + /* Start or stop the backdrop changing */ + xfce_backdrop_set_cycle_timer(backdrop, + xfce_backdrop_get_cycle_timer(backdrop)); + } +} + +gboolean +xfce_backdrop_get_cycle_backdrop(XfceBackdrop *backdrop) +{ + g_return_val_if_fail(XFCE_IS_BACKDROP(backdrop), 0); + + return backdrop->priv->cycle_backdrop; +} + /** * xfce_backdrop_get_pixbuf: * @backdrop: An #XfceBackdrop. diff --git a/src/xfce-backdrop.h b/src/xfce-backdrop.h index d193644..78ba6b0 100644 --- a/src/xfce-backdrop.h +++ b/src/xfce-backdrop.h @@ -70,6 +70,7 @@ struct _XfceBackdropClass /*< signals >*/ void (*changed)(XfceBackdrop *backdrop); + void (*cycle)(XfceBackdrop *backdrop); }; GType xfce_backdrop_get_type (void) G_GNUC_CONST; @@ -113,6 +114,11 @@ void xfce_backdrop_set_image_filename (XfceBackdrop *backdrop, G_CONST_RETURN gchar *xfce_backdrop_get_image_filename (XfceBackdrop *backdrop); +void xfce_backdrop_set_list (XfceBackdrop *backdrop, + gchar *backdrop_list); +G_CONST_RETURN gchar *xfce_backdrop_get_list + (XfceBackdrop *backdrop); + void xfce_backdrop_set_brightness (XfceBackdrop *backdrop, gint brightness); gint xfce_backdrop_get_brightness (XfceBackdrop *backdrop); @@ -121,6 +127,14 @@ void xfce_backdrop_set_saturation (XfceBackdrop *backdrop, gdouble saturation); gdouble xfce_backdrop_get_saturation (XfceBackdrop *backdrop); +void xfce_backdrop_set_cycle_backdrop (XfceBackdrop *backdrop, + gboolean cycle_backdrop); +gboolean xfce_backdrop_get_cycle_backdrop(XfceBackdrop *backdrop); + +void xfce_backdrop_set_cycle_timer (XfceBackdrop *backdrop, + guint cycle_timer); +guint xfce_backdrop_get_cycle_timer (XfceBackdrop *backdrop); + GdkPixbuf *xfce_backdrop_get_pixbuf (XfceBackdrop *backdrop); G_END_DECLS diff --git a/src/xfce-desktop.c b/src/xfce-desktop.c index fc7839f..df90f5d 100644 --- a/src/xfce-desktop.c +++ b/src/xfce-desktop.c @@ -363,6 +363,28 @@ backdrop_changed_cb(XfceBackdrop *backdrop, gpointer user_data) } static void +backdrop_cycle_cb(XfceBackdrop *backdrop, gpointer user_data) +{ + const gchar* backdrop_list; + + g_return_if_fail(XFCE_IS_BACKDROP(backdrop)); + + backdrop_list = xfce_backdrop_get_list(backdrop); + + if(xfdesktop_backdrop_list_is_valid(backdrop_list)) { + gchar *backdrop_file; + GError *error = NULL; + + backdrop_file = xfdesktop_backdrop_list_choose_random(backdrop_list, + &error); + + xfce_backdrop_set_image_filename(backdrop, backdrop_file); + g_free(backdrop_file); + backdrop_changed_cb(backdrop, user_data); + } +} + +static void screen_size_changed_cb(GdkScreen *gscreen, gpointer user_data) { XfceDesktop *desktop = user_data; @@ -434,6 +456,9 @@ xfce_desktop_monitors_changed(GdkScreen *gscreen, g_signal_connect(G_OBJECT(desktop->priv->backdrops[0]), "changed", G_CALLBACK(backdrop_changed_cb), desktop); + g_signal_connect(G_OBJECT(desktop->priv->backdrops[0]), + "cycle", + G_CALLBACK(backdrop_cycle_cb), desktop); } desktop->priv->nbackdrops = 1; } @@ -459,6 +484,10 @@ xfce_desktop_monitors_changed(GdkScreen *gscreen, "changed", G_CALLBACK(backdrop_changed_cb), desktop); + g_signal_connect(G_OBJECT(desktop->priv->backdrops[i]), + "cycle", + G_CALLBACK(backdrop_cycle_cb), + desktop); } } desktop->priv->nbackdrops = n_monitors; @@ -626,7 +655,7 @@ xfce_desktop_finalize(GObject *object) g_object_unref(G_OBJECT(desktop->priv->channel)); g_free(desktop->priv->property_prefix); - + G_OBJECT_CLASS(xfce_desktop_parent_class)->finalize(object); } @@ -1029,8 +1058,13 @@ xfce_desktop_image_filename_changed(XfconfChannel *channel, xfce_backdrop_set_image_filename(backdrop, backdrop_file); g_free(backdrop_file); - } else + + xfce_backdrop_set_list(backdrop, g_strdup(filename)); + } else { xfce_backdrop_set_image_filename(backdrop, filename); + + xfce_backdrop_set_list(backdrop, NULL); + } } } @@ -1082,6 +1116,16 @@ xfce_desktop_connect_backdrop_settings(XfceDesktop *desktop, xfconf_g_property_bind(channel, buf, G_TYPE_DOUBLE, G_OBJECT(backdrop), "saturation"); + buf[pp_len] = 0; + g_strlcat(buf, "backdrop-cycle-enable", sizeof(buf)); + xfconf_g_property_bind(channel, buf, G_TYPE_BOOLEAN, + G_OBJECT(backdrop), "backdrop-cycle-enable"); + + buf[pp_len] = 0; + g_strlcat(buf, "backdrop-cycle-timer", sizeof(buf)); + xfconf_g_property_bind(channel, buf, G_TYPE_UINT, + G_OBJECT(backdrop), "backdrop-cycle-timer"); + /* the image filename could be an image or a backdrop list, so we * can't just bind the property directly */ buf[pp_len] = 0; _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits