This repository has been archived on 2024-04-14. You can view files and clone it, but cannot push or open issues or pull requests.
nixos-dotfiles/user/configs/wayland/ags/ags-config/js/panel/widgets/volume.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-10-15 00:16:19 +01:00
import { Box, Button, Icon, Label, Stack } from 'resource:///com/github/Aylur/ags/widget.js';
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
2023-12-12 12:20:55 +00:00
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
2023-10-15 00:16:19 +01:00
export default () => Button({
2023-10-12 20:52:06 +01:00
className: 'volume',
2023-10-15 00:16:19 +01:00
onScrollUp: () => execAsync('pamixer -i 10'),
onScrollDown: () => execAsync('pamixer -d 10'),
child: Box({
2023-10-12 20:52:06 +01:00
children: [
2023-10-15 00:16:19 +01:00
Stack({
2023-10-12 20:52:06 +01:00
items: [
// tuples of [string, Widget]
2023-10-15 00:16:19 +01:00
['67', Icon('audio-volume-high-symbolic')],
['34', Icon('audio-volume-medium-symbolic')],
['1', Icon('audio-volume-low-symbolic')],
['0', Icon('audio-volume-muted-symbolic')],
2023-10-12 20:52:06 +01:00
],
2023-10-15 00:16:19 +01:00
connections: [
[Audio, stack => {
if (!Audio.speaker)
return;
2023-10-12 20:52:06 +01:00
2023-10-15 00:16:19 +01:00
if (Audio.speaker.isMuted) {
stack.shown = '0';
return;
}
2023-10-12 20:52:06 +01:00
2023-10-15 00:16:19 +01:00
const show = [101, 67, 34, 1, 0].find(
threshold => threshold <= Audio.speaker.volume * 100);
2023-10-12 20:52:06 +01:00
2023-10-15 00:16:19 +01:00
stack.shown = `${show}`;
}, 'speaker-changed']
],
2023-10-12 20:52:06 +01:00
}),
2023-10-15 00:16:19 +01:00
Label({
connections: [
[Audio, label => {
if (!Audio.speaker)
return;
2023-10-12 20:52:06 +01:00
2023-12-21 17:33:57 +00:00
label.label = ` ${Math.floor((Audio.speaker.volume * 100) / 5) * 5}%`; // round down to nearest 5
2023-10-15 00:16:19 +01:00
}, 'speaker-changed']
],
2023-10-12 20:52:06 +01:00
}),
],
}),
});