From e01d1721a650101d723b0e044dfb63c092d37e02 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Fri, 15 Dec 2023 09:17:03 -0500
Subject: [PATCH] fix(ags osd): only show speaker osd when using keys

---
 devices/wim/config/ags/js/osd/osds.js | 10 ++++++++--
 modules/hyprland/default.nix          |  6 +++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/devices/wim/config/ags/js/osd/osds.js b/devices/wim/config/ags/js/osd/osds.js
index 822c4036..d4262ad9 100644
--- a/devices/wim/config/ags/js/osd/osds.js
+++ b/devices/wim/config/ags/js/osd/osds.js
@@ -1,4 +1,5 @@
 import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
+import Variable from 'resource:///com/github/Aylur/ags/variable.js';
 
 import { Label } from 'resource:///com/github/Aylur/ags/widget.js';
 import OSD from './ctor.js';
@@ -10,12 +11,17 @@ import { MicIcon } from '../misc/audio-icons.js';
 const AUDIO_MAX = 1.5;
 
 
+const ShowSpeaker = Variable(true);
+
+globalThis.showSpeaker = () => {
+    ShowSpeaker.value = !ShowSpeaker.value;
+};
+
 export const SpeakerOSD = (stack) => OSD({
     stack,
     icon: { binds: [['icon', SpeakerIcon, 'value']] },
     info: {
-        mod: Audio,
-        signal: 'speaker-changed',
+        mod: ShowSpeaker,
         logic: (self) => {
             if (!Audio.speaker) {
                 return;
diff --git a/modules/hyprland/default.nix b/modules/hyprland/default.nix
index a343930c..97a2a4b8 100644
--- a/modules/hyprland/default.nix
+++ b/modules/hyprland/default.nix
@@ -182,13 +182,13 @@ in {
           ",Print, exec, grim -g \"$(slurp)\" - | swappy -f -"
           "$mainMod SHIFT, C, exec, wl-color-picker"
 
-          ",XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle"
+          ",XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle & ags -r 'showSpeaker()' &"
           ",XF86AudioMicMute, exec, pactl set-source-mute @DEFAULT_SOURCE@ toggle"
         ];
 
         binde = [
-          ",XF86AudioRaiseVolume, exec, wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+"
-          ",XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"
+          ",XF86AudioRaiseVolume, exec, wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ & ags -r 'showSpeaker()' &"
+          ",XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- & ags -r 'showSpeaker()' &"
         ];
 
         # Mouse Binds