ColinJones/cbatticon — Issue #6: High power usage --- consider longer interval, or provide parameters
Author: XeCycle
Created: 2011-12-15 13:56:59+00:00
State: open

I had a look at powertop, and found your program is consuming way too much power. It causes more wakeups than the window manager does (sawfish my wm), so I took a look at your code, and changed to a longer interval. But I think I may need to be accurate sometimes, so I added a callback to update it when icon clicked:

diff --git a/cbatticon.c b/cbatticon.c
index 645e1a7..4260736 100644
--- a/cbatticon.c
+++ b/cbatticon.c
@@ -29,7 +29,7 @@
/* info so the value is not always accurate when the notification is sent. */

#define STR_LTH 256
-#define UPDATE_INT 2
+#define UPDATE_INT 20
#define ERROR_TIME -1

static void get_battery (gchar *udev_device_suffix);
@@ -51,6 +51,9 @@ static void notify_battery_information (gint state, gint percentage, gchar *time
static void set_tooltip_and_icon (GtkStatusIcon *tray_icon, gint state, gint percentage, gchar *time);
static gchar* get_time_string (gint minutes);
static gchar* get_icon_name (gint state, gint percentage, gchar *time);
+static gboolean update_on_click_cb (GtkStatusIcon *tray_icon,
+ GdkEvent *event,
+ gpointer user_data);

/*
* udev functions
@@ -318,6 +321,8 @@ static GtkStatusIcon* create_tray_icon (void)

update_tray_icon (tray_icon);
g_timeout_add_seconds (UPDATE_INT, (GSourceFunc)update_tray_icon, (gpointer)tray_icon);
+ g_signal_connect (tray_icon, "button-press-event",
+ G_CALLBACK(update_on_click_cb), NULL);

return tray_icon;
}
@@ -336,6 +341,14 @@ static gboolean update_tray_icon (GtkStatusIcon *tray_icon)
return TRUE;
}

+static gboolean update_on_click_cb (GtkStatusIcon *tray_icon,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ update_tray_icon (tray_icon);
+ return TRUE;
+}
+
static void reset_estimated_vars(){
secs_last_time_change=0;
prev_remaining_capacity=-1;

I'd appreciate it if you provide some commandline parameters to modify intervals.