From efa7dc7ba49c0479cdbe247049052491b5b0b9ef Mon Sep 17 00:00:00 2001 From: Kiri <56218513+kiriDevs@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:34:35 +0200 Subject: [PATCH 1/6] fix(battery): Register health replacement for main format --- src/modules/battery.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 8dae43d5..e9fa3db2 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -714,7 +714,8 @@ auto waybar::modules::Battery::update() -> void { label_.set_markup( fmt::format(fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), fmt::arg("icon", getIcon(capacity, icons)), - fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles))); + fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles), + fmt::arg("health", fmt::format("{:.3}", health)))); } // Call parent update ALabel::update(); From 54a85ea15fa8bcda0eeeba428728ed5d7670dbef Mon Sep 17 00:00:00 2001 From: Kiri <56218513+kiriDevs@users.noreply.github.com> Date: Wed, 24 Apr 2024 08:56:24 +0000 Subject: [PATCH 2/6] style: Apply clang-format change At least I hope I copy-pased it correctly --- src/modules/battery.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index e9fa3db2..7566e33e 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -712,10 +712,10 @@ auto waybar::modules::Battery::update() -> void { event_box_.show(); auto icons = std::vector{status + "-" + state, status, state}; label_.set_markup( - fmt::format(fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), - fmt::arg("icon", getIcon(capacity, icons)), - fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles), - fmt::arg("health", fmt::format("{:.3}", health)))); + label_.set_markup(fmt::format( + fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), + fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("time", time_remaining_formatted), + fmt::arg("cycles", cycles), fmt::arg("health", fmt::format("{:.3}", health)))); } // Call parent update ALabel::update(); From 8d962430dd7c058ca77ebb037b4763baa47f7a8b Mon Sep 17 00:00:00 2001 From: Kiri <56218513+kiriDevs@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:02:03 +0000 Subject: [PATCH 3/6] fix(battery): Remove duplicate line This is what happens when you copy-paste from GitHub actions --- src/modules/battery.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 7566e33e..8a9c80d9 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -711,11 +711,10 @@ auto waybar::modules::Battery::update() -> void { } else { event_box_.show(); auto icons = std::vector{status + "-" + state, status, state}; - label_.set_markup( - label_.set_markup(fmt::format( - fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), - fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("time", time_remaining_formatted), - fmt::arg("cycles", cycles), fmt::arg("health", fmt::format("{:.3}", health)))); + label_.set_markup(fmt::format( + fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), + fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("time", time_remaining_formatted), + fmt::arg("cycles", cycles), fmt::arg("health", fmt::format("{:.3}", health)))); } // Call parent update ALabel::update(); From 5c4e36881916760d0741b193c1339fb62980ee3f Mon Sep 17 00:00:00 2001 From: Kiri <56218513+kiriDevs@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:05:11 +0000 Subject: [PATCH 4/6] style(battery): Indent level It's now *inconsistent* in the file, but clang-tidy should be happy, sooo... --- src/modules/battery.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 8a9c80d9..5d822f10 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -712,9 +712,9 @@ auto waybar::modules::Battery::update() -> void { event_box_.show(); auto icons = std::vector{status + "-" + state, status, state}; label_.set_markup(fmt::format( - fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), - fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("time", time_remaining_formatted), - fmt::arg("cycles", cycles), fmt::arg("health", fmt::format("{:.3}", health)))); + fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), + fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("time", time_remaining_formatted), + fmt::arg("cycles", cycles), fmt::arg("health", fmt::format("{:.3}", health)))); } // Call parent update ALabel::update(); From 57197b8e016b5ad42f4ae39b4860afa857b47a70 Mon Sep 17 00:00:00 2001 From: Kiri <56218513+kiriDevs@users.noreply.github.com> Date: Wed, 24 Apr 2024 14:53:04 +0200 Subject: [PATCH 5/6] feat(battery): Also support energy_full (instead of charge_full) --- src/modules/battery.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 5d822f10..43816d9c 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -374,6 +374,11 @@ waybar::modules::Battery::getInfos() { if (mainBatHealthPercent == 0.0f || batHealthPercent < mainBatHealthPercent) { mainBatHealthPercent = batHealthPercent; } + } else if (energy_full_exists && energy_full_design_exists) { + float batHealthPercent = ((float)energy_full / energy_full_design) * 100; + if (mainBatHealthPercent == 0.0f || batHealthPercent < mainBatHealthPercent) { + mainBatHealthPercent = batHealthPercent; + } } } From a2c5a8215ba996acada6ac9229767847fbc1dc85 Mon Sep 17 00:00:00 2001 From: Kiri <56218513+kiriDevs@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:07:20 +0200 Subject: [PATCH 6/6] style(battery): Capitalize float 'F' suffix --- src/modules/battery.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 43816d9c..327420ae 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -371,12 +371,12 @@ waybar::modules::Battery::getInfos() { if (charge_full_exists && charge_full_design_exists) { float batHealthPercent = ((float)charge_full / charge_full_design) * 100; - if (mainBatHealthPercent == 0.0f || batHealthPercent < mainBatHealthPercent) { + if (mainBatHealthPercent == 0.0F || batHealthPercent < mainBatHealthPercent) { mainBatHealthPercent = batHealthPercent; } } else if (energy_full_exists && energy_full_design_exists) { float batHealthPercent = ((float)energy_full / energy_full_design) * 100; - if (mainBatHealthPercent == 0.0f || batHealthPercent < mainBatHealthPercent) { + if (mainBatHealthPercent == 0.0F || batHealthPercent < mainBatHealthPercent) { mainBatHealthPercent = batHealthPercent; } }