diff --git a/panel-plugin/battery.c b/panel-plugin/battery.c
index b730274..aa0d993 100644
--- a/panel-plugin/battery.c
+++ b/panel-plugin/battery.c
@@ -160,6 +160,7 @@ update_apm_status(t_battmon *battmon)
int method = BM_BROKEN;
int present = 0, charge = 0, rate = 0;
int lcapacity = 0, ccapacity = 0;
+ int percentage = 0;
gboolean fan = FALSE;
const char *temp;
static int old_state = -1, new_state = BM_MISSING;
@@ -216,6 +217,7 @@ update_apm_status(t_battmon *battmon)
lcapacity += acpiinfo->last_full_capacity;
ccapacity += acpistate->rcapacity;
rate += acpistate->prate;
+ percentage += acpistate->percentage;
}
sum_lcapacity += lcapacity;
@@ -241,7 +243,10 @@ update_apm_status(t_battmon *battmon)
rate = last_rate;
}
- charge = (((float)ccapacity)/((float)lcapacity))*100;
+ if (lcapacity > 0)
+ charge = (((float)ccapacity)/((float)lcapacity))*100;
+ else if (percentage > 0 && present > 0)
+ charge = percentage/present;
if (last_acline)
time_remaining = ((float)(lcapacity-ccapacity)/(float)(rate))*60;
diff --git a/panel-plugin/libacpi.c b/panel-plugin/libacpi.c
index 0755585..671d624 100644
--- a/panel-plugin/libacpi.c
+++ b/panel-plugin/libacpi.c
@@ -518,6 +518,7 @@ read_acpi_state_sysfs(int battery)
DIR *sysfs;
struct dirent *propety;
char *name;
+ int percentage_found;
sysfs = opendir(batteries[battery]);
if (sysfs == 0)
@@ -555,11 +556,15 @@ read_acpi_state_sysfs(int battery)
}
/* on my system this is called charge_now */
- if ((strcmp(name,"energy_now") == 0) || (strcmp(name,"charge_now") == 0))
+ if ((strcmp(name,"energy_now") == 0) || (strcmp(name,"charge_now") == 0) || (strcmp(name,"charge_counter") == 0))
{
sprintf(buf,"%s/%s",batteries[battery], name);
acpistate->rcapacity = read_sysfs_int(buf);
- acpistate->percentage = (((float) acpistate->rcapacity)/acpiinfo->last_full_capacity) * 100;
+ /* calculate percentage based on remaining capacity only if actual percentage is not found */
+ if (!percentage_found)
+ {
+ acpistate->percentage = (((float) acpistate->rcapacity)/acpiinfo->last_full_capacity) * 100;
+ }
}
if ((strcmp(name,"current_now") == 0) || (strcmp(name,"power_now") == 0))
@@ -577,6 +582,13 @@ read_acpi_state_sysfs(int battery)
sprintf(buf,"%s/%s",batteries[battery], name);
acpistate->pvoltage = read_sysfs_int(buf);
}
+
+ if (strcmp(name,"capacity") == 0)
+ {
+ sprintf(buf,"%s/%s",batteries[battery], name);
+ acpistate->percentage = read_sysfs_int(buf);
+ percentage_found = 1;
+ }
}
closedir(sysfs);