From b3ece5a5554a242522799864ef4714513d4bcf97 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 3 Mar 2019 16:40:09 +1300 Subject: Re-add debug macro, short circuit icon logic --- tray.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tray.c') diff --git a/tray.c b/tray.c index 3a5ea32..8f1ce17 100644 --- a/tray.c +++ b/tray.c @@ -1,4 +1,5 @@ #include "tray.h" +#include "common.h" #include "getcore.h" #include "getfreq.h" #include "getgov.h" @@ -17,6 +18,7 @@ static char tooltip_text[1024]; static GtkWidget* menu; static GSList* menu_items; static GtkWidget* checked_menu_item; +static old_adjusted_percent = -1; /*********************************************************************** @@ -213,7 +215,15 @@ static void update_icon() } } + if (adjusted_percent == old_adjusted_percent) { + debug("Unchanged, short circuiting\n"); + return; + } + + old_adjusted_percent = adjusted_percent; + snprintf(file, sizeof(file), "%s/cpu-%d.png", DEFAULT_THEME,adjusted_percent); + debug("Set icon to %s\n", file); gtk_status_icon_set_from_file(tray, file); } @@ -240,7 +250,7 @@ static gboolean update() switch ( now_bat_state ) { case STATE_DISCHARGING: - fprintf(stderr, "discharging\n"); + debug("discharging\n"); if (DEFAULT_BAT_GOV) { for (i = 0; i < gc_number(); i++) @@ -250,7 +260,7 @@ static gboolean update() case STATE_CHARGING: case STATE_FULL: - fprintf(stderr, "ac power\n"); + debug("ac power\n"); if (DEFAULT_AC_GOV) { for (i = 0; i < gc_number(); i++) @@ -306,7 +316,7 @@ void tray_init() g_signal_connect(G_OBJECT(tray), "query-tooltip", G_CALLBACK(show_tooltip), NULL); g_signal_connect(G_OBJECT(tray), "popup-menu", G_CALLBACK(popup_menu), NULL); - g_timeout_add(1000, update, NULL); + g_timeout_add(CPU_TRAY_UPDATE_INTERVAL, update, NULL); /* Force meaningful tooltip cached text and force meaningful icon */ update(); -- cgit v1.1