From c772bb28f65bebae8f58945aa15ff4e9c21fd496 Mon Sep 17 00:00:00 2001 From: Clement Bouvet Date: Fri, 12 Jun 2026 16:33:23 +0200 Subject: [PATCH] feat(battery widget): add hide-when-idle option --- assets/translations/en.json | 4 ++++ src/shell/bar/widget_factory.cpp | 4 +++- src/shell/bar/widgets/battery_widget.cpp | 10 +++++++--- src/shell/bar/widgets/battery_widget.h | 3 ++- src/shell/settings/widget_settings_registry.cpp | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 2092cf3a02..06cd45953d 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -2474,6 +2474,10 @@ "description": "Hide the battery widget when fully charged", "label": "Hide When Full" }, + "hide-when-idle": { + "description": "Hide the battery widget while plugged in but not charging (e.g. held at a BIOS charge limit)", + "label": "Hide When Idle" + }, "hide-when-no-connected-device": { "description": "Hide the bluetooth widget when no device is connected", "label": "Hide When No Connected Device" diff --git a/src/shell/bar/widget_factory.cpp b/src/shell/bar/widget_factory.cpp index a0c1752db8..0668a519ab 100644 --- a/src/shell/bar/widget_factory.cpp +++ b/src/shell/bar/widget_factory.cpp @@ -182,6 +182,7 @@ std::unique_ptr WidgetFactory::create( const bool showLabel = wc != nullptr ? wc->getBool("show_label", true) : true; const bool hideWhenPlugged = wc != nullptr ? wc->getBool("hide_when_plugged", false) : false; const bool hideWhenFull = wc != nullptr ? wc->getBool("hide_when_full", false) : false; + const bool hideWhenIdle = wc != nullptr ? wc->getBool("hide_when_idle", false) : false; BatteryDisplayMode displayMode = BatteryDisplayMode::Glyph; if (displayModeStr == "graphic") { displayMode = BatteryDisplayMode::Graphic; @@ -189,7 +190,8 @@ std::unique_ptr WidgetFactory::create( kLog.warn("invalid widget.{}.display_mode '{}'; expected glyph or graphic", name, displayModeStr); } auto widget = std::make_unique( - m_upower, deviceSelector, warningThreshold, warningColor, displayMode, showLabel, hideWhenPlugged, hideWhenFull + m_upower, deviceSelector, warningThreshold, warningColor, displayMode, showLabel, hideWhenPlugged, hideWhenFull, + hideWhenIdle ); widget->setContentScale(contentScale); return widget; diff --git a/src/shell/bar/widgets/battery_widget.cpp b/src/shell/bar/widgets/battery_widget.cpp index 5d137f0cde..dc57e888ea 100644 --- a/src/shell/bar/widgets/battery_widget.cpp +++ b/src/shell/bar/widgets/battery_widget.cpp @@ -68,11 +68,11 @@ namespace { BatteryWidget::BatteryWidget( UPowerService* upower, std::string deviceSelector, int warningThreshold, ColorSpec warningColor, - BatteryDisplayMode displayMode, bool showLabel, bool hideWhenPlugged, bool hideWhenFull + BatteryDisplayMode displayMode, bool showLabel, bool hideWhenPlugged, bool hideWhenFull, bool hideWhenIdle ) : m_upower(upower), m_deviceSelector(std::move(deviceSelector)), m_warningThreshold(warningThreshold), m_warningColor(warningColor), m_displayMode(displayMode), m_showLabel(showLabel), - m_hideWhenPlugged(hideWhenPlugged), m_hideWhenFull(hideWhenFull) {} + m_hideWhenPlugged(hideWhenPlugged), m_hideWhenFull(hideWhenFull), m_hideWhenIdle(hideWhenIdle) {} void BatteryWidget::create() { auto container = std::make_unique(); @@ -356,9 +356,13 @@ void BatteryWidget::syncState(Renderer& renderer) { || s.state == BatteryState::FullyCharged || s.state == BatteryState::PendingCharge; + // The battery is not charging due to a charge limit, but still plugged in. + const bool isIdle = s.state == BatteryState::PendingCharge; + const bool showWidget = s.isPresent && !(m_hideWhenPlugged && isPluggedIn) - && !(m_hideWhenFull && (s.state == BatteryState::FullyCharged || s.state == BatteryState::PendingCharge)); + && !(m_hideWhenFull && s.state == BatteryState::FullyCharged) + && !(m_hideWhenIdle && isIdle); auto* rootNode = root(); if (rootNode != nullptr) { diff --git a/src/shell/bar/widgets/battery_widget.h b/src/shell/bar/widgets/battery_widget.h index a9cbf9bffb..e3b69aee65 100644 --- a/src/shell/bar/widgets/battery_widget.h +++ b/src/shell/bar/widgets/battery_widget.h @@ -19,7 +19,7 @@ class BatteryWidget : public Widget { BatteryWidget( UPowerService* upower, std::string deviceSelector = "auto", int warningThreshold = 0, ColorSpec warningColor = {}, BatteryDisplayMode displayMode = BatteryDisplayMode::Glyph, bool showLabel = true, bool hideWhenPlugged = false, - bool hideWhenFull = false + bool hideWhenFull = false, bool hideWhenIdle = false ); void create() override; @@ -45,6 +45,7 @@ class BatteryWidget : public Widget { bool m_showLabel = true; bool m_hideWhenPlugged = false; bool m_hideWhenFull = false; + bool m_hideWhenIdle = false; // Glyph mode nodes Glyph* m_glyph = nullptr; diff --git a/src/shell/settings/widget_settings_registry.cpp b/src/shell/settings/widget_settings_registry.cpp index 4704a26fe1..d9afebd610 100644 --- a/src/shell/settings/widget_settings_registry.cpp +++ b/src/shell/settings/widget_settings_registry.cpp @@ -639,6 +639,7 @@ namespace settings { add(boolSpec("show_label", true)); add(boolSpec("hide_when_plugged", false)); add(boolSpec("hide_when_full", false)); + add(boolSpec("hide_when_idle", false)); add(selectSpec("device", "auto", {{"auto", "common.states.auto"}})); { auto warn = colorSpec("warning_color", "error");