From 265075a748b91610ef34412bfe34c4e0f421d011 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 1 Dec 2018 00:47:23 -0500 Subject: [PATCH 7/7] Reset averages when a battery is removed/added. --- panel-plugin/battery.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/panel-plugin/battery.c b/panel-plugin/battery.c index 5ed0dd2..c516742 100644 --- a/panel-plugin/battery.c +++ b/panel-plugin/battery.c @@ -177,6 +177,7 @@ update_apm_status(t_battmon *battmon) static int last_lcapacity = 0; static int last_rate = 0; static int last_acline = 0; + static int last_present = 0; #if defined(__OpenBSD__) || defined(__NetBSD__) /* Code for OpenBSD by Joe Ammond . Using the same @@ -207,7 +208,7 @@ update_apm_status(t_battmon *battmon) for (i=0;ilast_full_capacity; ccapacity += acpistate->rcapacity; rate += acpistate->prate; @@ -218,8 +219,8 @@ update_apm_status(t_battmon *battmon) sum_rate += rate; update_time++; - if ( update_time >= AVERAGING_CYCLE || last_acline != acline ) { - if ( last_acline != acline ) { + if ( update_time >= AVERAGING_CYCLE || last_acline != acline || last_present != present ) { + if ( last_acline != acline || last_present != present ) { last_ccapacity = ccapacity; last_lcapacity = lcapacity; last_rate = rate; @@ -247,6 +248,7 @@ update_apm_status(t_battmon *battmon) time_remaining = 0; last_acline = acline; + last_present = present; } #endif -- 2.19.1