Updating branch refs/heads/master to 2189f6bf37f6f379c4c4d9478f5f76083e8cb08a (commit) from f622c1ad07bbb1f051a59bf798bdc5245d1147e0 (commit)
commit 2189f6bf37f6f379c4c4d9478f5f76083e8cb08a Author: Harald Judt <h.j...@gmx.at> Date: Tue Feb 5 00:22:44 2013 +0100 Power saving: Implement upower support. If the lid is closed, hide the scrollbox. If the machine is on battery, * decrease the regular update interval to 30 seconds, * stop the scrollbox animation and * update the summary window clock only every minute. panel-plugin/weather-config.c | 10 ++++- panel-plugin/weather-debug.c | 5 ++ panel-plugin/weather-summary.c | 17 +++++++- panel-plugin/weather.c | 82 +++++++++++++++++++++++++++++++++++++++- panel-plugin/weather.h | 8 ++++ 5 files changed, 115 insertions(+), 7 deletions(-) diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c index 2f0d337..61eea44 100644 --- a/panel-plugin/weather-config.c +++ b/panel-plugin/weather-config.c @@ -1706,8 +1706,14 @@ check_scrollbox_animate_toggled(GtkWidget *button, xfceweather_dialog *dialog = (xfceweather_dialog *) user_data; dialog->pd->scrollbox_animate = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); - gtk_scrollbox_set_animate(GTK_SCROLLBOX(dialog->pd->scrollbox), - dialog->pd->scrollbox_animate); +#ifdef HAVE_UPOWER_GLIB + if (dialog->pd->upower_on_battery) + gtk_scrollbox_set_animate(GTK_SCROLLBOX(dialog->pd->scrollbox), + FALSE); + else +#endif + gtk_scrollbox_set_animate(GTK_SCROLLBOX(dialog->pd->scrollbox), + dialog->pd->scrollbox_animate); } diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c index e9f7123..7e0392c 100644 --- a/panel-plugin/weather-debug.c +++ b/panel-plugin/weather-debug.c @@ -409,6 +409,9 @@ weather_dump_plugindata(const plugin_data *data) " panel orientation: %d\n" " plugin orientation: %d\n" " --------------------------------------------\n" + " upower on battery: %s\n" + " upower lid closed: %s\n" + " --------------------------------------------\n" " last astro update: %s\n" " next astro update: %s\n" " astro download attempts: %d\n" @@ -447,6 +450,8 @@ weather_dump_plugindata(const plugin_data *data) data->size, data->panel_orientation, data->orientation, + YESNO(data->upower_on_battery), + YESNO(data->upower_lid_closed), last_astro_update, next_astro_update, data->astro_update->attempt, diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c index a6483e1..1181543 100644 --- a/panel-plugin/weather-summary.c +++ b/panel-plugin/weather-summary.c @@ -990,7 +990,7 @@ update_summary_subtitle(plugin_data *data) { time_t now_t; GTimeVal now; - gchar *title, *date; + gchar *title, *date, *date_format; guint update_interval; gint64 now_ms; @@ -1004,7 +1004,13 @@ update_summary_subtitle(plugin_data *data) return FALSE; time(&now_t); - date = format_date(now_t, "%Y-%m-%d %H:%M:%S %z (%Z)", TRUE); +#ifdef HAVE_UPOWER_GLIB + if (data->upower_on_battery || data->upower_lid_closed) + date_format = "%Y-%m-%d %H:%M %z (%Z)"; + else +#endif + date_format = "%Y-%m-%d %H:%M:%S %z (%Z)"; + date = format_date(now_t, date_format, TRUE); title = g_strdup_printf("%s\n%s", data->location_name, date); g_free(date); xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(data->summary_window), @@ -1014,7 +1020,12 @@ update_summary_subtitle(plugin_data *data) /* compute and schedule the next update */ g_get_current_time(&now); now_ms = ((gint64) now.tv_sec * 1000) + ((gint64) now.tv_usec / 1000); - update_interval = 1000 - (now_ms % 1000) + 1; +#ifdef HAVE_UPOWER_GLIB + if (data->upower_on_battery || data->upower_lid_closed) + update_interval = 60000 - (now_ms % 60000) + 1; + else +#endif + update_interval = 1000 - (now_ms % 1000) + 1; data->summary_update_timer = g_timeout_add(update_interval, (GSourceFunc) update_summary_subtitle, data); diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c index 6085924..5a5ff8a 100644 --- a/panel-plugin/weather.c +++ b/panel-plugin/weather.c @@ -44,6 +44,12 @@ #define CONN_MAX_ATTEMPTS (3) /* max retry attempts using small interval */ #define CONN_RETRY_INTERVAL_SMALL (10) #define CONN_RETRY_INTERVAL_LARGE (10 * 60) + +/* power saving update interval in seconds used as a precaution to + deal with suspend/resume events etc., when nothing needs to be + updated earlier: */ +#define POWERSAVE_UPDATE_INTERVAL (30) + /* standard update interval in seconds used as a precaution to deal with suspend/resume events etc., when nothing needs to be updated earlier: */ @@ -312,6 +318,13 @@ update_icon(plugin_data *data) void scrollbox_set_visible(plugin_data *data) { +#ifdef HAVE_UPOWER_GLIB + if (data->upower_lid_closed) { + gtk_widget_hide_all(GTK_WIDGET(data->vbox_center_scrollbox)); + gtk_scrollbox_set_visible(GTK_SCROLLBOX(data->scrollbox), FALSE); + return; + } +#endif if (data->show_scrollbox && data->labels->len > 0) gtk_widget_show_all(GTK_WIDGET(data->vbox_center_scrollbox)); else @@ -358,8 +371,13 @@ update_scrollbox(plugin_data *data, weather_debug("No weather data available, set single label '%s'.", _("No Data")); } - gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox), - data->scrollbox_animate); +#ifdef HAVE_UPOWER_GLIB + if (data->upower_on_battery) + gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox), FALSE); + else +#endif + gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox), + data->scrollbox_animate); /* update labels immediately (mainly used on config change) */ if (immediately) { gtk_scrollbox_prev_label(GTK_SCROLLBOX(data->scrollbox)); @@ -695,6 +713,15 @@ schedule_next_wakeup(plugin_data *data) "sunset icon change"); } +#ifdef HAVE_UPOWER_GLIB + if (data->upower_on_battery && diff > POWERSAVE_UPDATE_INTERVAL) { + /* next wakeup time is greater than the power saving check + interval, so call the update handler earlier to deal with + cases like system resume events etc. */ + diff = POWERSAVE_UPDATE_INTERVAL; + data->next_wakeup_reason = "regular check (power saving)"; + } else +#endif if (diff > UPDATE_INTERVAL) { /* next wakeup time is greater than the standard check interval, so call the update handler earlier to deal with @@ -1451,6 +1478,39 @@ mi_click(GtkWidget *widget, } +#ifdef HAVE_UPOWER_GLIB +static void +upower_changed_cb(UpClient *client, + plugin_data *data) +{ + gboolean on_battery, lid_closed; + + if (G_UNLIKELY(data->upower == NULL)) + return; + + on_battery = data->upower_on_battery; + lid_closed = data->upower_lid_closed; + weather_debug("upower old status: on_battery=%d, lid_closed=%d", + on_battery, lid_closed); + + data->upower_on_battery = up_client_get_on_battery(client); + data->upower_lid_closed = up_client_get_lid_is_closed(client); + weather_debug("upower new status: on_battery=%d, lid_closed=%d", + data->upower_on_battery, data->upower_lid_closed); + + if (data->upower_on_battery != on_battery || + data->upower_lid_closed != lid_closed) { + if (data->summary_window) + update_summary_subtitle(data); + + update_icon(data); + update_scrollbox(data, FALSE); + schedule_next_wakeup(data); + } +} +#endif + + static void xfceweather_dialog_response(GtkWidget *dlg, gint response, @@ -1684,6 +1744,13 @@ xfceweather_create_control(XfcePanelPlugin *plugin) /* Initialize with sane default values */ data->plugin = plugin; +#ifdef HAVE_UPOWER_GLIB + data->upower = up_client_new(); + if (data->upower) { + data->upower_on_battery = up_client_get_on_battery(data->upower); + data->upower_lid_closed = up_client_get_lid_is_closed(data->upower); + } +#endif data->units = g_slice_new0(units_config); data->weatherdata = make_weather_data(); data->cache_file_max_age = CACHE_FILE_MAX_AGE; @@ -1796,6 +1863,11 @@ xfceweather_free(XfcePanelPlugin *plugin, data->update_timer = 0; } +#ifdef HAVE_UPOWER_GLIB + if (data->upower) + g_object_unref(data->upower); +#endif + if (data->weatherdata) xml_weather_free(data->weatherdata); @@ -2013,6 +2085,12 @@ weather_construct(XfcePanelPlugin *plugin) g_signal_connect(G_OBJECT(plugin), "about", G_CALLBACK(xfceweather_show_about), data); +#ifdef HAVE_UPOWER_GLIB + if (data->upower) + g_signal_connect(data->upower, "changed", + G_CALLBACK(upower_changed_cb), data); +#endif + /* call update handler updates */ update_handler(data); diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h index 60001f1..25d7a5a 100644 --- a/panel-plugin/weather.h +++ b/panel-plugin/weather.h @@ -22,6 +22,9 @@ #include <libxfce4panel/libxfce4panel.h> #include <libxfce4util/libxfce4util.h> #include <libsoup/soup.h> +#ifdef HAVE_UPOWER_GLIB +#include <upower.h> +#endif #include "weather-icon.h" #define PLUGIN_WEBSITE "http://goodies.xfce.org/projects/panel-plugins/xfce4-weather-plugin" @@ -59,6 +62,11 @@ typedef struct { typedef struct { XfcePanelPlugin *plugin; +#ifdef HAVE_UPOWER_GLIB + UpClient *upower; + gboolean upower_on_battery; + gboolean upower_lid_closed; +#endif SoupSession *session; gchar *geonames_username; _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits