From 55f23453c66c35a5f0a0c2de703c3d625a696e25 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Mon, 13 Nov 2023 11:42:11 -0600 Subject: [PATCH] Show a notification when the battery is present, not absent. --- debian/changelog | 1 + debian/patches/battery-ux.patch | 114 ++++++++++++++++++++++++++++++++ debian/patches/series | 1 + 3 files changed, 116 insertions(+) create mode 100644 debian/patches/battery-ux.patch create mode 100644 debian/patches/series diff --git a/debian/changelog b/debian/changelog index f298ffc..1eea312 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ lxqt-powermanagement (1.4.0-0ubuntu1) UNRELEASED; urgency=medium * New upstream release. * Bump build dependencies. + * Show a notification when the battery is present, not absent. -- Simon Quigley Mon, 13 Nov 2023 11:39:49 -0600 diff --git a/debian/patches/battery-ux.patch b/debian/patches/battery-ux.patch new file mode 100644 index 0000000..eb95cb1 --- /dev/null +++ b/debian/patches/battery-ux.patch @@ -0,0 +1,114 @@ +Description: Show a notification when the battery is present, not absent + In virtual machines especially, it is odd to see a message about the battery not being present. This commit moves that message to only display when there is a battery present. +Author: Simon Quigley +Origin: upstream +Forwarded: https://github.com/lxqt/lxqt-powermanagement/pull/382 +Last-Update: 2023-10-03 +--- +This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ +--- a/src/batterywatcher.cpp ++++ b/src/batterywatcher.cpp +@@ -43,13 +43,6 @@ BatteryWatcher::BatteryWatcher(QObject * + { + const QList devices = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString()); + +- if (devices.isEmpty()) +- { +- LXQt::Notification::notify(tr("No battery!"), +- tr("LXQt could not find data about any battery - monitoring disabled"), +- QSL("lxqt-powermanagement")); +- } +- + for (Solid::Device device : devices) + { + Solid::Battery *battery = device.as(); +@@ -57,11 +50,24 @@ BatteryWatcher::BatteryWatcher(QObject * + { + continue; + } ++ + mBatteries << battery; + connect(battery, &Solid::Battery::energyChanged, this, &BatteryWatcher::batteryChanged); + connect(battery, &Solid::Battery::chargeStateChanged, this, &BatteryWatcher::batteryChanged); + } + ++ bool discharging; ++ double chargeLevel; ++ chargeLevelAndStatus(discharging, chargeLevel); ++ ++ if (!devices.isEmpty()) { ++ QString status = discharging ? QStringLiteral("Discharging") : QStringLiteral("Charging"); ++ QString message = tr("%1 (%2%)").arg(status).arg(chargeLevel); ++ LXQt::Notification::notify(tr("Battery Present"), ++ message, ++ QSL("lxqt-powermanagement")); ++ } ++ + mBatteryInfoDialog = new BatteryInfoDialog(mBatteries); + + connect(&mSettings, &PowerManagementSettings::settingsChanged, this, &BatteryWatcher::settingsChanged); +@@ -85,19 +91,10 @@ void BatteryWatcher::batteryChanged() + static QTime actionTime; + static LXQt::Notification *notification = nullptr; + +- double totalEnergyFull = 0; +- double totalEnergyNow = 0; +- bool discharging = true; ++ bool discharging; + double chargeLevel; + +- for (const Solid::Battery *battery : qAsConst(mBatteries)) +- { +- totalEnergyFull += battery->energyFull(); +- totalEnergyNow += battery->energy(); +- discharging &= (battery->chargeState() == Solid::Battery::Discharging); +- } +- +- chargeLevel = 100 * totalEnergyNow / totalEnergyFull; ++ chargeLevelAndStatus(discharging, chargeLevel); + + qDebug() << "BatteryChanged" + << "discharging:" << discharging +@@ -160,6 +157,31 @@ void BatteryWatcher::batteryChanged() + } + } + ++void BatteryWatcher::chargeLevelAndStatus(bool &discharging, double &chargeLevel) ++{ ++ double totalEnergyFull = 0; ++ double totalEnergyNow = 0; ++ bool batteries = false; ++ discharging = true; ++ ++ for (const Solid::Battery *battery : qAsConst(mBatteries)) ++ { ++ batteries = true; ++ ++ totalEnergyFull += battery->energyFull(); ++ totalEnergyNow += battery->energy(); ++ discharging &= (battery->chargeState() == Solid::Battery::Discharging); ++ } ++ ++ if (!batteries) { ++ discharging = false; ++ chargeLevel = 0; ++ } ++ else { ++ chargeLevel = 100 * totalEnergyNow / totalEnergyFull; ++ } ++} ++ + void BatteryWatcher::settingsChanged() + { + if (!mSettings.isShowIcon()) +--- a/src/batterywatcher.h ++++ b/src/batterywatcher.h +@@ -51,6 +51,8 @@ private slots: + void setPause(TrayIcon::PAUSE duration); + + private: ++ void chargeLevelAndStatus(bool &discharging, double &chargeLevel); ++ + QList mBatteries; + QList mTrayIcons; + QTimer mPauseTimer; diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 0000000..a4919f2 --- /dev/null +++ b/debian/patches/series @@ -0,0 +1 @@ +battery-ux.patch