temp/upower: sync icon and warn for low battery level (MR 2255)
Commitscfb5d41b
andead17254
updated the default battery levels for warnings and actions in the pinephone and the pinetab. Since then, the chances of the phone dying for lack of battery power have completely dissapeared. However, the battery icon in phosh was never updated to show a "caution" battery level. The value was hardcoded and ignored the setting in the config file. This commit fixes that issue
This commit is contained in:
parent
8efe40cee0
commit
5d47add5f1
2 changed files with 167 additions and 3 deletions
|
@ -0,0 +1,160 @@
|
|||
From ae19116af161ba6f053ebe7950b6d9ea46ce2d74 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Pablo=20Correa=20G=C3=B3mez?= <ablocorrea@hotmail.com>
|
||||
Date: Thu, 17 Jun 2021 01:01:32 +0200
|
||||
Subject: [PATCH] daemon: Sync icon and warning for non-default low level
|
||||
|
||||
Before, the low level for changing the battery icon was hardcoded.
|
||||
However, as the `low_percentage` property is settable by the user using
|
||||
`PercentageLow` option. That can lead to inconsistencies when PercentageLow
|
||||
is not the default. For example, if PercentageLow is set higher than 10,
|
||||
the Low Battery level warning will be sent at the user-set level, but the
|
||||
battery icon would not be updated to "caution" until the percentage
|
||||
drops below 10%.
|
||||
|
||||
This issue is solved in this commit by using the `low_percentage` property
|
||||
for the comparison instead of hardcoding the default.
|
||||
---
|
||||
src/up-daemon.c | 34 ++++++++++++++++++++++++++++++++++
|
||||
src/up-daemon.h | 4 ++++
|
||||
src/up-device.c | 47 ++++++++++-------------------------------------
|
||||
3 files changed, 48 insertions(+), 37 deletions(-)
|
||||
|
||||
diff --git a/src/up-daemon.c b/src/up-daemon.c
|
||||
index ef2cd6b..70b75dd 100644
|
||||
--- a/src/up-daemon.c
|
||||
+++ b/src/up-daemon.c
|
||||
@@ -704,6 +704,40 @@ up_daemon_update_warning_level (UpDaemon *daemon)
|
||||
up_daemon_set_warning_level (daemon, warning_level);
|
||||
}
|
||||
|
||||
+const gchar *
|
||||
+up_daemon_get_charge_icon (UpDaemon *daemon,
|
||||
+ gdouble percentage,
|
||||
+ UpDeviceLevel battery_level,
|
||||
+ gboolean charging)
|
||||
+{
|
||||
+ if (battery_level == UP_DEVICE_LEVEL_NONE && daemon != NULL) {
|
||||
+ if (percentage <= daemon->priv->low_percentage)
|
||||
+ return charging ? "battery-caution-charging-symbolic" : "battery-caution-symbolic";
|
||||
+ else if (percentage < 30)
|
||||
+ return charging ? "battery-low-charging-symbolic" : "battery-low-symbolic";
|
||||
+ else if (percentage < 60)
|
||||
+ return charging ? "battery-good-charging-symbolic" : "battery-good-symbolic";
|
||||
+ return charging ? "battery-full-charging-symbolic" : "battery-full-symbolic";
|
||||
+ } else {
|
||||
+ switch (battery_level) {
|
||||
+ case UP_DEVICE_LEVEL_UNKNOWN:
|
||||
+ /* The lack of symmetry is on purpose */
|
||||
+ return charging ? "battery-good-charging-symbolic" : "battery-caution-symbolic";
|
||||
+ case UP_DEVICE_LEVEL_LOW:
|
||||
+ case UP_DEVICE_LEVEL_CRITICAL:
|
||||
+ return charging ? "battery-caution-charging-symbolic" : "battery-caution-symbolic";
|
||||
+ case UP_DEVICE_LEVEL_NORMAL:
|
||||
+ return charging ? "battery-low-charging-symbolic" : "battery-low-symbolic";
|
||||
+ case UP_DEVICE_LEVEL_HIGH:
|
||||
+ return charging ? "battery-good-charging-symbolic" : "battery-good-symbolic";
|
||||
+ case UP_DEVICE_LEVEL_FULL:
|
||||
+ return charging ? "battery-full-charging-symbolic" : "battery-full-symbolic";
|
||||
+ default:
|
||||
+ g_assert_not_reached ();
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/**
|
||||
* up_daemon_device_changed_cb:
|
||||
**/
|
||||
diff --git a/src/up-daemon.h b/src/up-daemon.h
|
||||
index 7160e0e..76e7937 100644
|
||||
--- a/src/up-daemon.h
|
||||
+++ b/src/up-daemon.h
|
||||
@@ -82,6 +82,10 @@ UpDeviceLevel up_daemon_compute_warning_level(UpDaemon *daemon,
|
||||
gboolean power_supply,
|
||||
gdouble percentage,
|
||||
gint64 time_to_empty);
|
||||
+const gchar *up_daemon_get_charge_icon (UpDaemon *daemon,
|
||||
+ gdouble percentage,
|
||||
+ UpDeviceLevel battery_level,
|
||||
+ gboolean charging);
|
||||
|
||||
void up_daemon_start_poll (GObject *object,
|
||||
GSourceFunc callback);
|
||||
diff --git a/src/up-device.c b/src/up-device.c
|
||||
index 37ec129..0a56810 100644
|
||||
--- a/src/up-device.c
|
||||
+++ b/src/up-device.c
|
||||
@@ -89,39 +89,6 @@ update_warning_level (UpDevice *device)
|
||||
up_exported_device_set_warning_level (skeleton, warning_level);
|
||||
}
|
||||
|
||||
-static const gchar *
|
||||
-get_device_charge_icon (gdouble percentage,
|
||||
- UpDeviceLevel battery_level,
|
||||
- gboolean charging)
|
||||
-{
|
||||
- if (battery_level == UP_DEVICE_LEVEL_NONE) {
|
||||
- if (percentage < 10)
|
||||
- return charging ? "battery-caution-charging-symbolic" : "battery-caution-symbolic";
|
||||
- else if (percentage < 30)
|
||||
- return charging ? "battery-low-charging-symbolic" : "battery-low-symbolic";
|
||||
- else if (percentage < 60)
|
||||
- return charging ? "battery-good-charging-symbolic" : "battery-good-symbolic";
|
||||
- return charging ? "battery-full-charging-symbolic" : "battery-full-symbolic";
|
||||
- } else {
|
||||
- switch (battery_level) {
|
||||
- case UP_DEVICE_LEVEL_UNKNOWN:
|
||||
- /* The lack of symmetry is on purpose */
|
||||
- return charging ? "battery-good-charging-symbolic" : "battery-caution-symbolic";
|
||||
- case UP_DEVICE_LEVEL_LOW:
|
||||
- case UP_DEVICE_LEVEL_CRITICAL:
|
||||
- return charging ? "battery-caution-charging-symbolic" : "battery-caution-symbolic";
|
||||
- case UP_DEVICE_LEVEL_NORMAL:
|
||||
- return charging ? "battery-low-charging-symbolic" : "battery-low-symbolic";
|
||||
- case UP_DEVICE_LEVEL_HIGH:
|
||||
- return charging ? "battery-good-charging-symbolic" : "battery-good-symbolic";
|
||||
- case UP_DEVICE_LEVEL_FULL:
|
||||
- return charging ? "battery-full-charging-symbolic" : "battery-full-symbolic";
|
||||
- default:
|
||||
- g_assert_not_reached ();
|
||||
- }
|
||||
- }
|
||||
-}
|
||||
-
|
||||
/* This needs to be called when one of those properties changes:
|
||||
* type
|
||||
* state
|
||||
@@ -134,6 +101,10 @@ update_icon_name (UpDevice *device)
|
||||
const gchar *icon_name = NULL;
|
||||
UpExportedDevice *skeleton = UP_EXPORTED_DEVICE (device);
|
||||
|
||||
+ /* Not finished setting up the object? */
|
||||
+ if (device->priv->daemon == NULL)
|
||||
+ return;
|
||||
+
|
||||
/* get the icon from some simple rules */
|
||||
if (up_exported_device_get_type_ (skeleton) == UP_DEVICE_KIND_LINE_POWER) {
|
||||
icon_name = "ac-adapter-symbolic";
|
||||
@@ -152,14 +123,16 @@ update_icon_name (UpDevice *device)
|
||||
break;
|
||||
case UP_DEVICE_STATE_CHARGING:
|
||||
case UP_DEVICE_STATE_PENDING_CHARGE:
|
||||
- icon_name = get_device_charge_icon (up_exported_device_get_percentage (skeleton),
|
||||
- up_exported_device_get_battery_level (skeleton),
|
||||
+ icon_name = up_daemon_get_charge_icon (device->priv->daemon,
|
||||
+ up_exported_device_get_percentage (skeleton),
|
||||
+ up_exported_device_get_battery_level (skeleton),
|
||||
TRUE);
|
||||
break;
|
||||
case UP_DEVICE_STATE_DISCHARGING:
|
||||
case UP_DEVICE_STATE_PENDING_DISCHARGE:
|
||||
- icon_name = get_device_charge_icon (up_exported_device_get_percentage (skeleton),
|
||||
- up_exported_device_get_battery_level (skeleton),
|
||||
+ icon_name = up_daemon_get_charge_icon (device->priv->daemon,
|
||||
+ up_exported_device_get_percentage (skeleton),
|
||||
+ up_exported_device_get_battery_level (skeleton),
|
||||
FALSE);
|
||||
break;
|
||||
default:
|
||||
--
|
||||
2.17.1
|
||||
|
|
@ -4,7 +4,7 @@ pkgname=upower
|
|||
pkgver=9999
|
||||
_pkgver=0.99.11
|
||||
_distver="UPOWER_${_pkgver//./_}"
|
||||
pkgrel=2
|
||||
pkgrel=3
|
||||
pkgdesc="Power Management Services"
|
||||
url="https://upower.freedesktop.org"
|
||||
arch="aarch64 armv7"
|
||||
|
@ -18,6 +18,7 @@ source="https://gitlab.freedesktop.org/upower/upower/-/archive/$_distver/upower-
|
|||
0001-Add-torch-support.patch
|
||||
0002-Detect-USB-Type-C-port-controller-and-other-chargers.patch
|
||||
0003-torch-be-more-specific-when-searching-for-an-led-dev.patch
|
||||
0004-daemon-Sync-icon-and-warning-for-non-default-low-level.patch
|
||||
"
|
||||
builddir="$srcdir/$pkgname-$_distver"
|
||||
|
||||
|
@ -55,7 +56,10 @@ package() {
|
|||
make DESTDIR="$pkgdir" install
|
||||
}
|
||||
|
||||
sha512sums="918fdba13df7ba85fd276daae68228554e71df95011b48dc42b006a059cf2996f906ce08e98f6d1da07c8f2a4235bc9622992fa42eaaf05a08f1a3650f4ae4b6 upower-UPOWER_0_99_11.tar.bz2
|
||||
sha512sums="
|
||||
918fdba13df7ba85fd276daae68228554e71df95011b48dc42b006a059cf2996f906ce08e98f6d1da07c8f2a4235bc9622992fa42eaaf05a08f1a3650f4ae4b6 upower-UPOWER_0_99_11.tar.bz2
|
||||
c6c8a557f8ca650e6e2b8b1f64f70744dc610f86f71d88602014b6c241c96821b5662f48ab63da6a2da9e52017b8d9f7a87655f8f640e87b5d17417577079b0b 0001-Add-torch-support.patch
|
||||
0673d32e8c3d313e21437e7d431068b4a0c51a4d63acf414fc93430c461ab5acbcc2ae8740d6614ed9487fadb8ae2c685e02fb7ad3623b71a20ccb90c1a0bd28 0002-Detect-USB-Type-C-port-controller-and-other-chargers.patch
|
||||
c0c440103f3712106728e02520de66875de36fb7799c57bfef8952d03bae00beaa2c9b6335115050e9d484d013f3bcb88230d7d9a1bc8c0f0305f77a0e8fcfa8 0003-torch-be-more-specific-when-searching-for-an-led-dev.patch"
|
||||
c0c440103f3712106728e02520de66875de36fb7799c57bfef8952d03bae00beaa2c9b6335115050e9d484d013f3bcb88230d7d9a1bc8c0f0305f77a0e8fcfa8 0003-torch-be-more-specific-when-searching-for-an-led-dev.patch
|
||||
77d8ab65118a3e776522665cdb66b7653eb0f9c6db2c82ddac0bf7ef0b25a262a054f38ccc403da3321209081b09ddfdc053fcf432b2e43a14e965aa60ae5c12 0004-daemon-Sync-icon-and-warning-for-non-default-low-level.patch
|
||||
"
|
||||
|
|
Loading…
Add table
Reference in a new issue