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 Brightness from '../../services/brightness.js';
|
||||||
import Indicator from '../../services/indicator.js';
|
import Indicator from '../../services/indicator.js';
|
||||||
|
|
||||||
const OsdValue = (name, labelSetup, progressSetup, props = {}) => {
|
const OsdValue = ({ name, nameSetup = undefined, labelSetup, progressSetup, ...rest }) => {
|
||||||
const valueName = Label({
|
const valueName = Label({
|
||||||
xalign: 0, yalign: 0, hexpand: true,
|
xalign: 0, yalign: 0, hexpand: true,
|
||||||
className: 'osd-label',
|
className: 'osd-label',
|
||||||
label: `${name}`,
|
label: `${name}`,
|
||||||
|
setup: nameSetup,
|
||||||
});
|
});
|
||||||
const valueNumber = Label({
|
const valueNumber = Label({
|
||||||
hexpand: false, className: 'osd-value-txt',
|
hexpand: false, className: 'osd-value-txt',
|
||||||
setup: labelSetup,
|
setup: labelSetup,
|
||||||
});
|
});
|
||||||
return Box({ // Volume
|
return Box({ // Volume
|
||||||
...props,
|
|
||||||
vertical: true,
|
vertical: true,
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
className: 'osd-bg osd-value',
|
className: 'osd-bg osd-value',
|
||||||
|
|
@ -41,29 +41,48 @@ const OsdValue = (name, labelSetup, progressSetup, props = {}) => {
|
||||||
setup: progressSetup,
|
setup: progressSetup,
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
...rest,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const brightnessIndicator = OsdValue('Brightness',
|
const brightnessIndicator = OsdValue({
|
||||||
(self) => self.hook(Brightness, self => {
|
name: 'Brightness',
|
||||||
|
labelSetup: (self) => self.hook(Brightness, self => {
|
||||||
self.label = `${Math.round(Brightness.screen_value * 100)}`;
|
self.label = `${Math.round(Brightness.screen_value * 100)}`;
|
||||||
}, 'notify::screen-value'),
|
}, 'notify::screen-value'),
|
||||||
(self) => self.hook(Brightness, (progress) => {
|
progressSetup: (self) => self.hook(Brightness, (progress) => {
|
||||||
const updateValue = Brightness.screen_value;
|
const updateValue = Brightness.screen_value;
|
||||||
progress.value = updateValue;
|
progress.value = updateValue;
|
||||||
}, 'notify::screen-value'),
|
}, 'notify::screen-value'),
|
||||||
)
|
});
|
||||||
|
|
||||||
const volumeIndicator = OsdValue('Volume',
|
const volumeIndicator = OsdValue({
|
||||||
(self) => self.hook(Audio, (label) => {
|
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)}`;
|
label.label = `${Math.round(Audio.speaker?.volume * 100)}`;
|
||||||
}),
|
}),
|
||||||
(self) => self.hook(Audio, (progress) => {
|
progressSetup: (self) => self.hook(Audio, (progress) => {
|
||||||
const updateValue = Audio.speaker?.volume;
|
const updateValue = Audio.speaker?.volume;
|
||||||
if (!isNaN(updateValue)) progress.value = updateValue;
|
if (!isNaN(updateValue)) progress.value = updateValue;
|
||||||
}),
|
}),
|
||||||
);
|
});
|
||||||
return MarginRevealer({
|
return MarginRevealer({
|
||||||
transition: 'slide_down',
|
transition: 'slide_down',
|
||||||
showClass: 'osd-show',
|
showClass: 'osd-show',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue