diff --git a/modules/bar/battery/index.ts b/modules/bar/battery/index.ts index 42e9980..8d22ef7 100644 --- a/modules/bar/battery/index.ts +++ b/modules/bar/battery/index.ts @@ -7,7 +7,7 @@ import Button from 'types/widgets/button.js'; import { Attribute, Child } from 'lib/types/widget.js'; import { runAsyncCommand, throttledScrollHandler } from 'customModules/utils.js'; -const { label: show_label, rightClick, middleClick, scrollUp, scrollDown } = options.bar.battery; +const { label: show_label, rightClick, middleClick, scrollUp, scrollDown, hideLabelWhenFull } = options.bar.battery; const BatteryLabel = (): BarBoxChild => { const isVis = Variable(battery.available); @@ -59,29 +59,41 @@ const BatteryLabel = (): BarBoxChild => { ), visible: battery.bind('available'), tooltip_text: battery.bind('time_remaining').as((t) => t.toString()), - children: Utils.merge([battery.bind('available'), show_label.bind('value')], (batAvail, showLabel) => { - if (batAvail && showLabel) { - return [ - Widget.Icon({ - class_name: 'bar-button-icon battery', - icon: batIcon, - }), - Widget.Label({ - class_name: 'bar-button-label battery', - label: battery.bind('percent').as((p) => `${Math.floor(p)}%`), - }), - ]; - } else if (batAvail && !showLabel) { - return [ - Widget.Icon({ - class_name: 'bar-button-icon battery', - icon: batIcon, - }), - ]; - } else { - return []; - } - }), + children: Utils.merge( + [ + battery.bind('available'), + show_label.bind('value'), + battery.bind('charged'), + hideLabelWhenFull.bind('value'), + ], + (batAvail, showLabel, isCharged, hideWhenFull) => { + if (batAvail && showLabel) { + return [ + Widget.Icon({ + class_name: 'bar-button-icon battery', + icon: batIcon, + }), + ...(hideWhenFull && isCharged + ? [] + : [ + Widget.Label({ + class_name: 'bar-button-label battery', + label: battery.bind('percent').as((p) => `${Math.floor(p)}%`), + }), + ]), + ]; + } else if (batAvail && !showLabel) { + return [ + Widget.Icon({ + class_name: 'bar-button-icon battery', + icon: batIcon, + }), + ]; + } else { + return []; + } + }, + ), setup: (self) => { self.hook(battery, () => { if (battery.available) { diff --git a/options.ts b/options.ts index a79f7cc..d763510 100644 --- a/options.ts +++ b/options.ts @@ -912,6 +912,7 @@ const options = mkOptions(OPTIONS, { }, battery: { label: opt(true), + hideLabelWhenFull: opt(false), rightClick: opt(''), middleClick: opt(''), scrollUp: opt(''), diff --git a/scss/style/bar/battery.scss b/scss/style/bar/battery.scss index 7f1df89..f1b449a 100644 --- a/scss/style/bar/battery.scss +++ b/scss/style/bar/battery.scss @@ -25,6 +25,10 @@ $bar-buttons-radius * 0.4, $bar-buttons-radius ); + + &:last-child { + border-radius: $bar-buttons-radius; + } } .bar-button-label.battery { @@ -56,3 +60,4 @@ 0em ); } + diff --git a/widget/settings/pages/config/bar/index.ts b/widget/settings/pages/config/bar/index.ts index 713679d..00a2408 100644 --- a/widget/settings/pages/config/bar/index.ts +++ b/widget/settings/pages/config/bar/index.ts @@ -559,6 +559,11 @@ export const BarSettings = (): Scrollable => { title: 'Show Battery Percentage', type: 'boolean', }), + Option({ + opt: options.bar.battery.hideLabelWhenFull, + title: 'Hide Battery Percentage When Full', + type: 'boolean', + }), Option({ opt: options.theme.bar.buttons.battery.spacing, title: 'Inner Spacing',