From 49013bf4a5fd570fe05910f2d145a926410fc140 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Sun, 6 Feb 2022 20:56:49 -0700 Subject: [PATCH] applets/battery: adjust show/hide conditions for charge limits When we are using a charge threshold, the kernel may stop charging within a percentage point of the actual threshold and this is considered correct behavior, so we have to handle that. See https://bugzilla.kernel.org/show_bug.cgi?id=215531. Also, Upower may give us a status of "Not charging" rather than "Fully charged", so we need to account for that as well. See https://gitlab.freedesktop.org/upower/upower/-/issues/142. BUG: 435931 --- .../batterymonitor/package/contents/ui/main.qml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/applets/batterymonitor/package/contents/ui/main.qml b/applets/batterymonitor/package/contents/ui/main.qml index 3eb3ddcea..ad223dcd9 100644 --- a/applets/batterymonitor/package/contents/ui/main.qml +++ b/applets/batterymonitor/package/contents/ui/main.qml @@ -108,7 +108,20 @@ Item { } if (pmSource.data.Battery["Has Cumulative"] - && !(pmSource.data["Battery"]["State"] === "FullyCharged" && pmSource.data["AC Adapter"]["Plugged in"])) { + && !((pmSource.data["AC Adapter"]["Plugged in"] && pmSource.data["Battery"]["State"] === "FullyCharged") || + // When we are using a charge threshold, the kernel + // may stop charging within a percentage point of the actual threshold + // and this is considered correct behavior, so we have to handle + // that. See https://bugzilla.kernel.org/show_bug.cgi?id=215531. + (pmSource.data["AC Adapter"]["Plugged in"] + && typeof pmSource.data["Battery"]["Charge Stop Threshold"] === "number" + && (pmSource.data.Battery.Percent >= pmSource.data["Battery"]["Charge Stop Threshold"] - 1 + && pmSource.data.Battery.Percent <= pmSource.data["Battery"]["Charge Stop Threshold"] + 1) + // Also, Upower may give us a status of "Not charging" rather than + // "Fully charged", so we need to account for that as well. See + // https://gitlab.freedesktop.org/upower/upower/-/issues/142. + && (pmSource.data["Battery"]["State"] === "NoCharge" || pmSource.data["Battery"]["State"] === "FullyCharged")) + )){ return PlasmaCore.Types.ActiveStatus; }