mirror of
https://github.com/danbulant/dots-hyprland
synced 2026-05-24 12:22:09 +00:00
osd: volume: show device
This commit is contained in:
parent
0f556381b4
commit
4de1b711ea
1 changed files with 29 additions and 10 deletions
|
|
@ -6,18 +6,18 @@ import { MarginRevealer } from '../.widgethacks/advancedrevealers.js';
|
|||
import Brightness from '../../services/brightness.js';
|
||||
import Indicator from '../../services/indicator.js';
|
||||
|
||||
const OsdValue = (name, labelSetup, progressSetup, props = {}) => {
|
||||
const OsdValue = ({ name, nameSetup = undefined, labelSetup, progressSetup, ...rest }) => {
|
||||
const valueName = Label({
|
||||
xalign: 0, yalign: 0, hexpand: true,
|
||||
className: 'osd-label',
|
||||
label: `${name}`,
|
||||
setup: nameSetup,
|
||||
});
|
||||
const valueNumber = Label({
|
||||
hexpand: false, className: 'osd-value-txt',
|
||||
setup: labelSetup,
|
||||
});
|
||||
return Box({ // Volume
|
||||
...props,
|
||||
vertical: true,
|
||||
hexpand: true,
|
||||
className: 'osd-bg osd-value',
|
||||
|
|
@ -41,29 +41,48 @@ const OsdValue = (name, labelSetup, progressSetup, props = {}) => {
|
|||
setup: progressSetup,
|
||||
})
|
||||
],
|
||||
...rest,
|
||||
});
|
||||
}
|
||||
|
||||
export default () => {
|
||||
const brightnessIndicator = OsdValue('Brightness',
|
||||
(self) => self.hook(Brightness, self => {
|
||||
const brightnessIndicator = OsdValue({
|
||||
name: 'Brightness',
|
||||
labelSetup: (self) => self.hook(Brightness, self => {
|
||||
self.label = `${Math.round(Brightness.screen_value * 100)}`;
|
||||
}, 'notify::screen-value'),
|
||||
(self) => self.hook(Brightness, (progress) => {
|
||||
progressSetup: (self) => self.hook(Brightness, (progress) => {
|
||||
const updateValue = Brightness.screen_value;
|
||||
progress.value = updateValue;
|
||||
}, 'notify::screen-value'),
|
||||
)
|
||||
});
|
||||
|
||||
const volumeIndicator = OsdValue('Volume',
|
||||
(self) => self.hook(Audio, (label) => {
|
||||
const volumeIndicator = OsdValue({
|
||||
name: 'Volume',
|
||||
attribute: {
|
||||
headphones: undefined,
|
||||
},
|
||||
nameSetup: (self) => Utils.timeout(1, () => {
|
||||
const updateAudioDevice = (self) => {
|
||||
const usingHeadphones = (Audio.speaker?.stream?.port)?.includes('Headphones');
|
||||
if (volumeIndicator.attribute.headphones === undefined ||
|
||||
volumeIndicator.attribute.headphones !== usingHeadphones) {
|
||||
volumeIndicator.attribute.headphones = usingHeadphones;
|
||||
self.label = usingHeadphones ? 'Headphones' : 'Speakers';
|
||||
Indicator.popup(1);
|
||||
}
|
||||
}
|
||||
self.hook(Audio, updateAudioDevice);
|
||||
Utils.timeout(1000, updateAudioDevice);
|
||||
}),
|
||||
labelSetup: (self) => self.hook(Audio, (label) => {
|
||||
label.label = `${Math.round(Audio.speaker?.volume * 100)}`;
|
||||
}),
|
||||
(self) => self.hook(Audio, (progress) => {
|
||||
progressSetup: (self) => self.hook(Audio, (progress) => {
|
||||
const updateValue = Audio.speaker?.volume;
|
||||
if (!isNaN(updateValue)) progress.value = updateValue;
|
||||
}),
|
||||
);
|
||||
});
|
||||
return MarginRevealer({
|
||||
transition: 'slide_down',
|
||||
showClass: 'osd-show',
|
||||
|
|
|
|||
Loading…
Reference in a new issue