nixos-configs/config/ags/js/bar/brightness.js

47 lines
1 KiB
JavaScript
Raw Normal View History

2023-09-08 15:15:04 -04:00
const { Label, Icon, Stack, ProgressBar, Overlay, Box } = ags.Widget;
import { Separator } from '../common.js';
const { exec } = ags.Utils;
const Indicator = props => Icon({
2023-09-08 15:15:04 -04:00
...props,
size: 28,
style: 'margin-left: -5px',
icon: 'display-brightness-symbolic',
2023-09-08 15:15:04 -04:00
});
const LevelLabel = props => Label({
...props,
className: 'label',
connections: [[200, label => label.label = `${Math.floor(exec('brightnessctl get') / 2.55)}%`]],
2023-09-08 15:15:04 -04:00
});
const BrightnessModule = () => Overlay({
child: ProgressBar({
className: 'toggle-off brightness',
connections: [
[ 200, progress => {
let br = exec('brightnessctl get') / 255;
if (br > 0.33) {
progress.value = br;
}
else {
progress.value = 0.33;
}
}]
],
}),
overlays: [
Box({
className: 'battery',
style: 'color: #CBA6F7;',
children: [
Indicator(),
Separator(2),
LevelLabel(),
],
}),
2023-09-08 15:15:04 -04:00
],
});
export const Brightness = BrightnessModule();