[Xfce4-commits] <xfce4-systemload-plugin:master> Added a power-saving interval option using upower.
Mike Massonnet
noreply at xfce.org
Sun Jan 22 11:06:09 CET 2012
Updating branch refs/heads/master
to b25bf9852ef17801e30f55b5c2e9fee63191288d (commit)
from 49e2baa452f0704159b7c1e95f43fd5d7ad92f54 (commit)
commit b25bf9852ef17801e30f55b5c2e9fee63191288d
Author: David Schneider <dnschneid at gmail.com>
Date: Sat Jan 21 13:16:00 2012 -0800
Added a power-saving interval option using upower.
configure.ac.in | 2 +
panel-plugin/Makefile.am | 4 +-
panel-plugin/systemload.c | 95 +++++++++++++++++++++++++++++++++++++++++---
3 files changed, 93 insertions(+), 8 deletions(-)
diff --git a/configure.ac.in b/configure.ac.in
index b278f26..b0a7268 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -60,6 +60,8 @@ XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.6.0])
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.3.99.1])
XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.7.0])
XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.3.99.1])
+XDT_CHECK_OPTIONAL_PACKAGE([UPOWER_GLIB], [upower-glib], [0.9.0], [upower],
+ [upower for adapting update interval to power state])
dnl ***********************************
dnl *** Check for debugging support ***
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index a271a82..f58f1e8 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -24,12 +24,14 @@ xfce4_systemload_plugin_CFLAGS = \
$(LIBXFCE4UTIL_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
$(LIBXFCE4PANEL_CFLAGS) \
+ $(UPOWER_GLIB_CFLAGS) \
$(PLATFORM_CFLAGS)
xfce4_systemload_plugin_LDADD = \
$(LIBXFCE4UTIL_LIBS) \
$(LIBXFCE4UI_LIBS) \
- $(LIBXFCE4PANEL_LIBS)
+ $(LIBXFCE4PANEL_LIBS) \
+ $(UPOWER_GLIB_LIBS)
#
# Desktop file
diff --git a/panel-plugin/systemload.c b/panel-plugin/systemload.c
index b512c16..e516faf 100644
--- a/panel-plugin/systemload.c
+++ b/panel-plugin/systemload.c
@@ -38,6 +38,10 @@
#include <libxfce4ui/libxfce4ui.h>
#include <libxfce4panel/xfce-panel-plugin.h>
+#ifdef HAVE_UPOWER_GLIB
+#include <upower.h>
+#endif
+
#include "cpu.h"
#include "memswap.h"
#include "uptime.h"
@@ -49,6 +53,7 @@ static gchar *DEFAULT_TEXT[] = { "cpu", "mem", "swap" };
static gchar *DEFAULT_COLOR[] = { "#0000c0", "#00c000", "#f0f000" };
#define UPDATE_TIMEOUT 250
+#define UPDATE_TIMEOUT_SECONDS 1
#define BORDER 8
@@ -93,9 +98,14 @@ typedef struct
XfcePanelPlugin *plugin;
GtkWidget *ebox;
GtkWidget *box;
- guint timeout, timeout_id;
+ guint timeout, timeout_seconds;
+ gboolean use_timeout_seconds;
+ guint timeout_id;
t_monitor *monitor[3];
t_uptime_monitor *uptime;
+#ifdef HAVE_UPOWER_GLIB
+ UpClient *upower;
+#endif
} t_global_monitor;
static gint
@@ -329,8 +339,13 @@ monitor_control_new(XfcePanelPlugin *plugin)
t_global_monitor *global;
global = g_new(t_global_monitor, 1);
+#ifdef HAVE_UPOWER_GLIB
+ global->upower = up_client_new();
+#endif
global->plugin = plugin;
global->timeout = UPDATE_TIMEOUT;
+ global->timeout_seconds = UPDATE_TIMEOUT_SECONDS;
+ global->use_timeout_seconds = TRUE;
global->timeout_id = 0;
global->ebox = gtk_event_box_new();
gtk_container_set_border_width (GTK_CONTAINER (global->ebox), BORDER/2);
@@ -372,6 +387,13 @@ monitor_free(XfcePanelPlugin *plugin, t_global_monitor *global)
{
gint count;
+#ifdef HAVE_UPOWER_GLIB
+ if (global->upower) {
+ g_object_unref(global->upower);
+ global->upower = NULL;
+ }
+#endif
+
if (global->timeout_id)
g_source_remove(global->timeout_id);
@@ -392,6 +414,29 @@ monitor_free(XfcePanelPlugin *plugin, t_global_monitor *global)
}
static void
+setup_timer(t_global_monitor *global)
+{
+ if (global->timeout_id)
+ g_source_remove(global->timeout_id);
+#ifdef HAVE_UPOWER_GLIB
+ if (global->upower && global->use_timeout_seconds) {
+ if (up_client_get_on_battery(global->upower)) {
+ if (!up_client_get_lid_is_closed(global->upower)) {
+ global->timeout_id = g_timeout_add_seconds(
+ global->timeout_seconds,
+ (GSourceFunc)update_monitors, global);
+ } else {
+ /* Don't do any timeout if the lid is closed on battery */
+ global->timeout_id = 0;
+ }
+ return;
+ }
+ }
+#endif
+ global->timeout_id = g_timeout_add(global->timeout, (GSourceFunc)update_monitors, global);
+}
+
+static void
setup_monitor(t_global_monitor *global)
{
gint count;
@@ -434,6 +479,8 @@ setup_monitor(t_global_monitor *global)
}
gtk_widget_show(GTK_WIDGET(global->uptime->ebox));
}
+
+ setup_timer(global);
}
static void
@@ -457,6 +504,10 @@ monitor_read_config(XfcePanelPlugin *plugin, t_global_monitor *global)
{
xfce_rc_set_group (rc, "Main");
global->timeout = xfce_rc_read_int_entry (rc, "Timeout", global->timeout);
+ global->timeout_seconds = xfce_rc_read_int_entry (
+ rc, "Timeout_Seconds", global->timeout_seconds);
+ global->use_timeout_seconds = xfce_rc_read_bool_entry (
+ rc, "Use_Timeout_Seconds", global->use_timeout_seconds);
}
for(count = 0; count < 3; count++)
@@ -515,6 +566,9 @@ monitor_write_config(XfcePanelPlugin *plugin, t_global_monitor *global)
xfce_rc_set_group (rc, "Main");
xfce_rc_write_int_entry (rc, "Timeout", global->timeout);
+ xfce_rc_write_int_entry (rc, "Timeout_Seconds", global->timeout_seconds);
+ xfce_rc_write_bool_entry (rc, "Use_Timeout_Seconds",
+ global->use_timeout_seconds);
for(count = 0; count < 3; count++)
{
@@ -571,6 +625,14 @@ monitor_set_size(XfcePanelPlugin *plugin, int size, t_global_monitor *global)
return TRUE;
}
+#ifdef HAVE_UPOWER_GLIB
+static void
+upower_changed_cb(UpClient *client, t_global_monitor *global)
+{
+ setup_timer(global);
+}
+#endif
+
static void
entry_changed_cb(GtkEntry *entry, t_global_monitor *global)
{
@@ -616,11 +678,19 @@ change_timeout_cb(GtkSpinButton *spin, t_global_monitor *global)
{
global->timeout = gtk_spin_button_get_value(spin) * 1000;
- if (global->timeout_id)
- g_source_remove(global->timeout_id);
- global->timeout_id = g_timeout_add(global->timeout, (GSourceFunc)update_monitors, global);
+ setup_timer(global);
}
+#ifdef HAVE_UPOWER_GLIB
+static void
+change_timeout_seconds_cb(GtkSpinButton *spin, t_global_monitor *global)
+{
+ global->timeout_seconds = gtk_spin_button_get_value(spin);
+
+ setup_timer(global);
+}
+#endif
+
/* Create a new frame, optionally with a checkbox.
* Set boolvar to NULL if you do not want a checkbox.
* Returns the GtkTable inside the frame. */
@@ -764,11 +834,18 @@ monitor_create_options(XfcePanelPlugin *plugin, t_global_monitor *global)
content = GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dlg)));
- table = new_frame(global, content, _("General"), 1, NULL);
+ table = new_frame(global, content, _("General"), 2, NULL);
new_spin_button(global, table, 0,
_("Update interval:"), _("s"),
(gfloat)global->timeout/1000.0, 0.100, 10.000, .050,
G_CALLBACK(change_timeout_cb), NULL);
+#ifdef HAVE_UPOWER_GLIB
+ new_spin_button(global, table, 1,
+ _("Power-saving interval:"), _("s"),
+ (gfloat)global->timeout_seconds, 1, 10, 1,
+ G_CALLBACK(change_timeout_seconds_cb),
+ &global->use_timeout_seconds);
+#endif
for(count = 0; count < 3; count++)
{
@@ -814,8 +891,12 @@ systemload_construct (XfcePanelPlugin *plugin)
update_monitors (global);
- global->timeout_id =
- g_timeout_add(global->timeout, (GSourceFunc)update_monitors, global);
+#ifdef HAVE_UPOWER_GLIB
+ if (global->upower) {
+ g_signal_connect (global->upower, "changed",
+ G_CALLBACK(upower_changed_cb), global);
+ }
+#endif
g_signal_connect (plugin, "free-data", G_CALLBACK (monitor_free), global);
More information about the Xfce4-commits
mailing list