From c9bc79c956467155f8446e158588c75d202f350d Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Tue, 26 Mar 2024 22:09:38 +0100 Subject: [PATCH] Toggle audio sink/source on icon click A click on the mic/speaker icon now mutes/unmutes the sink/source. Implements https://github.com/scorpion-26/gBar/issues/81 --- src/Bar.cpp | 22 ++++++++++++++++++---- src/PulseAudio.h | 28 ++++++++++++++++++++++++++++ src/System.cpp | 9 +++++++++ src/System.h | 2 ++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/Bar.cpp b/src/Bar.cpp index 3c06d9d..3283d6c 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -286,8 +286,8 @@ namespace Bar Widget* audioSlider; Widget* micSlider; - Text* audioIcon; - Text* micIcon; + Button* audioIcon; + Button* micIcon; void OnChangeVolumeSink(Slider&, double value) { System::SetVolumeSink(value); @@ -315,6 +315,18 @@ namespace Bar System::SetVolumeSource(micVolume); } + void OnToggleSink(Button& button) + { + System::AudioInfo info = System::GetAudioInfo(); + System::SetMutedSink(!info.sinkMuted); + } + + void OnToggleSource(Button& button) + { + System::AudioInfo info = System::GetAudioInfo(); + System::SetMutedSource(!info.sourceMuted); + } + TimerResult UpdateAudio(Widget&) { System::AudioInfo info = System::GetAudioInfo(); @@ -344,7 +356,7 @@ namespace Bar } else { - ((Slider*)micSlider)->SetValue(info.sinkVolume); + ((Slider*)micSlider)->SetValue(info.sourceVolume); } if (info.sourceMuted) { @@ -605,18 +617,20 @@ namespace Bar Utils::SetTransform(*box, {-1, false, SideToAlignment(side)}); box->SetOrientation(Utils::GetOrientation()); { - auto icon = Widget::Create(); + auto icon = Widget::Create