feat: add option to hide label when battery is full (#350)

* feat: add option to hide label when battery is full

* feat: add option to hide label when battery is full

* feat: add option to hide label when battery is full

* Update modules/bar/battery/index.ts

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>

* fix: battery css

---------

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
Rubin Bhandari
2024-10-21 14:31:47 +05:45
committed by GitHub
parent ca664e3e78
commit c265697adc
4 changed files with 47 additions and 24 deletions

View File

@@ -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) {

View File

@@ -912,6 +912,7 @@ const options = mkOptions(OPTIONS, {
},
battery: {
label: opt(true),
hideLabelWhenFull: opt(false),
rightClick: opt(''),
middleClick: opt(''),
scrollUp: opt(''),

View File

@@ -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
);
}

View File

@@ -559,6 +559,11 @@ export const BarSettings = (): Scrollable<Gtk.Widget, Gtk.Widget> => {
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',