Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/shell/bar/widget_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ std::unique_ptr<Widget> 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;
} else if (displayModeStr != "glyph") {
kLog.warn("invalid widget.{}.display_mode '{}'; expected glyph or graphic", name, displayModeStr);
}
auto widget = std::make_unique<BatteryWidget>(
m_upower, deviceSelector, warningThreshold, warningColor, displayMode, showLabel, hideWhenPlugged, hideWhenFull
m_upower, deviceSelector, warningThreshold, warningColor, displayMode, showLabel, hideWhenPlugged, hideWhenFull,
hideWhenIdle
);
widget->setContentScale(contentScale);
return widget;
Expand Down
10 changes: 7 additions & 3 deletions src/shell/bar/widgets/battery_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputArea>();
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/shell/bar/widgets/battery_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/shell/settings/widget_settings_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading