diff --git a/css/style.css b/css/style.css index 7ba9d42..5237b61 100644 --- a/css/style.css +++ b/css/style.css @@ -76,6 +76,10 @@ highlight { color: #ffb86c; } +.audio-volume { + font-size: 16px; + color: #ffb86c; +} .audio-volume trough { background-color: #44475a; } @@ -91,6 +95,10 @@ highlight { color: #bd93f9; } +.mic-volume { + font-size: 16px; + color: #bd93f9; +} .mic-volume trough { background-color: #44475a; } diff --git a/css/style.scss b/css/style.scss index fa6a9c5..66ea431 100644 --- a/css/style.scss +++ b/css/style.scss @@ -126,6 +126,9 @@ highlight { highlight { background-color: $orange; } + + font-size: 16px; + color: $orange; } .mic-icon { @@ -146,6 +149,9 @@ highlight { highlight { background-color: $purple; } + + font-size: 16px; + color: $purple; } .package-outofdate { diff --git a/data/config b/data/config index fc723fe..4b6aa37 100644 --- a/data/config +++ b/data/config @@ -69,6 +69,9 @@ AudioRevealer: false # Sets the rate of change of the slider on each scroll. In Percent AudioScrollSpeed: 5 +# Display numbers instead of a slider for the two audio widgets. Doesn't affect the audio flyin +AudioNumbers: false + # Command that is run to check if there are out-of-date packages. # The script should return *ONLY* a number. If it doesn't output a number, updates are no longer checked. # Default value is applicable for Arch Linux. (See data/update.sh for a human-readable version) diff --git a/module.nix b/module.nix index 81215b0..4596f44 100644 --- a/module.nix +++ b/module.nix @@ -133,6 +133,11 @@ in { default = 5; description = "Sets the rate of change of the slider on each scroll. In Percent"; }; + AudioNumbers = mkOption { + type = types.bool; + default = false; + description = "Display numbers instead of a slider for the two audio widgets. Doesn't affect the audio flyin" + }; AudioMinVolume = mkOption { type = types.nullOr types.int; default = 0; diff --git a/src/Bar.cpp b/src/Bar.cpp index e493353..883a179 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -163,6 +163,10 @@ namespace Bar return TimerResult::Ok; } + Widget* audioSlider; + Widget* micSlider; + Text* audioIcon; + Text* micIcon; void OnChangeVolumeSink(Slider&, double value) { System::SetVolumeSink(value); @@ -173,14 +177,35 @@ namespace Bar System::SetVolumeSource(value); } - Slider* audioSlider; - Slider* micSlider; - Text* audioIcon; - Text* micIcon; + // For text + double audioVolume = 0; + void OnChangeVolumeSinkDelta(double delta) + { + audioVolume += delta; + audioVolume = std::clamp(audioVolume, 0.0, 1.0); + System::SetVolumeSink(audioVolume); + } + + double micVolume = 0; + void OnChangeVolumeSourceDelta(double delta) + { + micVolume += delta; + micVolume = std::clamp(micVolume, 0.0, 1.0); + System::SetVolumeSource(micVolume); + } + TimerResult UpdateAudio(Widget&) { System::AudioInfo info = System::GetAudioInfo(); - audioSlider->SetValue(info.sinkVolume); + if (Config::Get().audioNumbers) + { + audioVolume = info.sinkVolume; + ((Text*)audioSlider)->SetText(Utils::ToStringPrecision(info.sinkVolume * 100, "%0.0f") + "%"); + } + else + { + ((Slider*)audioSlider)->SetValue(info.sinkVolume); + } if (info.sinkMuted) { audioIcon->SetText("󰝟"); @@ -191,7 +216,15 @@ namespace Bar } if (Config::Get().audioInput) { - micSlider->SetValue(info.sourceVolume); + if (Config::Get().audioNumbers) + { + micVolume = info.sourceVolume; + ((Text*)micSlider)->SetText(Utils::ToStringPrecision(info.sourceVolume * 100, "%0.0f") + "%"); + } + else + { + ((Slider*)micSlider)->SetValue(info.sinkVolume); + } if (info.sourceMuted) { micIcon->SetText("󰍭"); @@ -326,32 +359,66 @@ namespace Bar Input, Output }; - auto widgetAudioSlider = [](Widget& parent, AudioType type) + auto widgetAudioVolume = [](Widget& parent, AudioType type) { - auto slider = Widget::Create(); - slider->SetOrientation(Utils::GetOrientation()); - Utils::SetTransform(*slider, {100, true, Alignment::Fill}); - slider->SetInverted(true); - switch (type) + if (Config::Get().audioNumbers) { - case AudioType::Input: - slider->SetClass("mic-volume"); - slider->OnValueChange(DynCtx::OnChangeVolumeSource); - DynCtx::micSlider = slider.get(); - break; - case AudioType::Output: - slider->SetClass("audio-volume"); - slider->OnValueChange(DynCtx::OnChangeVolumeSink); - DynCtx::audioSlider = slider.get(); - break; + auto eventBox = Widget::Create(); + auto text = Widget::Create(); + text->SetAngle(Utils::GetAngle()); + Utils::SetTransform(*text, {-1, true, Alignment::Fill}); + switch (type) + { + case AudioType::Input: + text->SetClass("mic-volume"); + DynCtx::micSlider = text.get(); + break; + case AudioType::Output: + text->SetClass("audio-volume"); + DynCtx::audioSlider = text.get(); + break; + } + eventBox->SetScrollFn( + [type, text = text.get()](EventBox&, ScrollDirection direction) + { + double delta = (double)Config::Get().audioScrollSpeed / 100.; + delta *= direction == ScrollDirection::Down ? -1 : 1; + switch (type) + { + case AudioType::Input: DynCtx::OnChangeVolumeSourceDelta(delta); break; + case AudioType::Output: DynCtx::OnChangeVolumeSinkDelta(delta); break; + } + }); + eventBox->AddChild(std::move(text)); + parent.AddChild(std::move(eventBox)); } - slider->SetRange({0, 1, 0.01}); - slider->SetScrollSpeed((double)Config::Get().audioScrollSpeed / 100.); + else + { + auto slider = Widget::Create(); + slider->SetOrientation(Utils::GetOrientation()); + Utils::SetTransform(*slider, {100, true, Alignment::Fill}); + slider->SetInverted(true); + switch (type) + { + case AudioType::Input: + slider->SetClass("mic-volume"); + slider->OnValueChange(DynCtx::OnChangeVolumeSource); + DynCtx::micSlider = slider.get(); + break; + case AudioType::Output: + slider->SetClass("audio-volume"); + slider->OnValueChange(DynCtx::OnChangeVolumeSink); + DynCtx::audioSlider = slider.get(); + break; + } + slider->SetRange({0, 1, 0.01}); + slider->SetScrollSpeed((double)Config::Get().audioScrollSpeed / 100.); - parent.AddChild(std::move(slider)); + parent.AddChild(std::move(slider)); + } }; - auto widgetAudioBody = [&widgetAudioSlider](Widget& parent, AudioType type) + auto widgetAudioBody = [&widgetAudioVolume](Widget& parent, AudioType type) { auto box = Widget::Create(); box->SetSpacing({8, false}); @@ -387,7 +454,7 @@ namespace Bar slideRevealer->SetRevealed(hovered); }); { - widgetAudioSlider(*revealer, type); + widgetAudioVolume(*revealer, type); } box->AddChild(std::move(revealer)); @@ -395,7 +462,7 @@ namespace Bar else { // Straight forward - widgetAudioSlider(*box, type); + widgetAudioVolume(*box, type); } box->AddChild(std::move(icon)); diff --git a/src/Config.cpp b/src/Config.cpp index 412e1d0..66bfd3d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -187,6 +187,7 @@ void Config::Load() AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty); AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty); AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty); + AddConfigVar("AudioNumbers", config.audioNumbers, lineView, foundProperty); AddConfigVar("NetworkWidget", config.networkWidget, lineView, foundProperty); AddConfigVar("WorkspaceScrollOnMonitor", config.workspaceScrollOnMonitor, lineView, foundProperty); AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty); diff --git a/src/Config.h b/src/Config.h index b1fa6fe..26d82d3 100644 --- a/src/Config.h +++ b/src/Config.h @@ -19,11 +19,13 @@ public: // Script that returns how many packages are out-of-date. The script should only print a number! // See data/update.sh for a human-readable version - std::string checkPackagesCommand = "p=\"$(checkupdates)\"; e=$?; if [ $e -eq 127 ] ; then exit 127; fi; if [ $e -eq 2 ] ; then echo \"0\" && exit 0; fi; echo \"$p\" | wc -l"; + std::string checkPackagesCommand = + "p=\"$(checkupdates)\"; e=$?; if [ $e -eq 127 ] ; then exit 127; fi; if [ $e -eq 2 ] ; then echo \"0\" && exit 0; fi; echo \"$p\" | wc -l"; bool centerTime = true; bool audioRevealer = false; bool audioInput = false; + bool audioNumbers = false; // Affects both audio sliders bool networkWidget = true; bool workspaceScrollOnMonitor = true; // Scroll through workspaces on monitor instead of all bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1