diff options
author | Bart Ribbers <bribbers@disroot.org> | 2020-02-25 10:32:13 +0100 |
---|---|---|
committer | Leo <thinkabit.ukim@gmail.com> | 2020-02-25 06:57:17 -0300 |
commit | 5851615b553d8b2dd7a74be84671ca1083a687ad (patch) | |
tree | 855bb614289da50640ee84e5553d098a6cf189c0 /community/xfce4-battery-plugin | |
parent | 3ceaf9c349894ff0b009412e9d21591174220816 (diff) | |
download | aports-5851615b553d8b2dd7a74be84671ca1083a687ad.tar.bz2 aports-5851615b553d8b2dd7a74be84671ca1083a687ad.tar.xz |
community/xfce4-battery-plugin: fix battery percentage detection
Fix by Daniele Debernari https://gitlab.com/postmarketOS/pmaports/-/merge_requests/595
Diffstat (limited to 'community/xfce4-battery-plugin')
-rw-r--r-- | community/xfce4-battery-plugin/00-fix-percentage-detection.patch | 71 | ||||
-rw-r--r-- | community/xfce4-battery-plugin/APKBUILD | 6 |
2 files changed, 75 insertions, 2 deletions
diff --git a/community/xfce4-battery-plugin/00-fix-percentage-detection.patch b/community/xfce4-battery-plugin/00-fix-percentage-detection.patch new file mode 100644 index 0000000000..c7deddd366 --- /dev/null +++ b/community/xfce4-battery-plugin/00-fix-percentage-detection.patch @@ -0,0 +1,71 @@ +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); diff --git a/community/xfce4-battery-plugin/APKBUILD b/community/xfce4-battery-plugin/APKBUILD index 1c3acbc7c6..ede7ba854e 100644 --- a/community/xfce4-battery-plugin/APKBUILD +++ b/community/xfce4-battery-plugin/APKBUILD @@ -1,7 +1,7 @@ # Maintainer: Natanael Copa <ncopa@alpinelinux.org> pkgname=xfce4-battery-plugin pkgver=1.1.3 -pkgrel=0 +pkgrel=1 pkgdesc="A battery monitor plugin for the Xfce panel" url="http://goodies.xfce.org/projects/panel-plugins/xfce4-battery-plugin" arch="all" @@ -9,6 +9,7 @@ license="GPL-2.0-or-later" makedepends="xfce4-panel-dev libxfce4ui-dev perl-xml-parser intltool linux-headers" subpackages="$pkgname-lang" source="https://archive.xfce.org/src/panel-plugins/xfce4-battery-plugin/${pkgver%.*}/xfce4-battery-plugin-$pkgver.tar.bz2 + 00-fix-percentage-detection.patch " build() { ./configure \ @@ -24,4 +25,5 @@ package() { make DESTDIR="$pkgdir" install } -sha512sums="a591fb37855efbd54d18ae97e320fa4521da611c8ea107813bfd66fa570e8c84576fcf779c7b676ee9918709912de728b0fed490e64d3d2ad403baf719db4520 xfce4-battery-plugin-1.1.3.tar.bz2" +sha512sums="a591fb37855efbd54d18ae97e320fa4521da611c8ea107813bfd66fa570e8c84576fcf779c7b676ee9918709912de728b0fed490e64d3d2ad403baf719db4520 xfce4-battery-plugin-1.1.3.tar.bz2 +b40d122d5b80ac548f739dcda3e9a049b9183b5aa8d0f2e0e5b7f4bb91024bdc0722ecb6492dc0296c6b0a50598a871a254181f33ce3cea2f4bdd7a64b32343e 00-fix-percentage-detection.patch" |