pmos/temp/xfce4-battery-plugin/00-fix-percentage-detection.patch
Daniele Debernardi dd0f32d9aa
temp/xfce4-battery-plugin: fix battery capacity detection (!595)
If someone also noticed the missing battery icon in the xfce4 panel,
please test with this patched plugin and report back. Thanks.
2019-09-19 00:34:13 +02:00

72 lines
2.6 KiB
Diff

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..2737fe3 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)
@@ -559,7 +560,11 @@ read_acpi_state_sysfs(int battery)
{
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);