From 4de1b711ea3ace6197cbfe426e0de49b5d2a00df Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 3 Mar 2024 15:55:51 +0700 Subject: [PATCH] osd: volume: show device --- .../ags/modules/indicators/indicatorvalues.js | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/.config/ags/modules/indicators/indicatorvalues.js b/.config/ags/modules/indicators/indicatorvalues.js index 9ea2deaf..ffc75ec7 100644 --- a/.config/ags/modules/indicators/indicatorvalues.js +++ b/.config/ags/modules/indicators/indicatorvalues.js @@ -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',