mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
Add config for numbers instead of sliders
Currently doesn't affect the audio flyin. Implementation for https://github.com/scorpion-26/gBar/issues/35
This commit is contained in:
parent
c2c7395687
commit
1a25dbdec6
7 changed files with 121 additions and 29 deletions
|
@ -76,6 +76,10 @@ highlight {
|
||||||
color: #ffb86c;
|
color: #ffb86c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.audio-volume {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #ffb86c;
|
||||||
|
}
|
||||||
.audio-volume trough {
|
.audio-volume trough {
|
||||||
background-color: #44475a;
|
background-color: #44475a;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +95,10 @@ highlight {
|
||||||
color: #bd93f9;
|
color: #bd93f9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mic-volume {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #bd93f9;
|
||||||
|
}
|
||||||
.mic-volume trough {
|
.mic-volume trough {
|
||||||
background-color: #44475a;
|
background-color: #44475a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,9 @@ highlight {
|
||||||
highlight {
|
highlight {
|
||||||
background-color: $orange;
|
background-color: $orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
font-size: 16px;
|
||||||
|
color: $orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mic-icon {
|
.mic-icon {
|
||||||
|
@ -146,6 +149,9 @@ highlight {
|
||||||
highlight {
|
highlight {
|
||||||
background-color: $purple;
|
background-color: $purple;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
font-size: 16px;
|
||||||
|
color: $purple;
|
||||||
}
|
}
|
||||||
|
|
||||||
.package-outofdate {
|
.package-outofdate {
|
||||||
|
|
|
@ -69,6 +69,9 @@ AudioRevealer: false
|
||||||
# Sets the rate of change of the slider on each scroll. In Percent
|
# Sets the rate of change of the slider on each scroll. In Percent
|
||||||
AudioScrollSpeed: 5
|
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.
|
# 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.
|
# 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)
|
# Default value is applicable for Arch Linux. (See data/update.sh for a human-readable version)
|
||||||
|
|
|
@ -133,6 +133,11 @@ in {
|
||||||
default = 5;
|
default = 5;
|
||||||
description = "Sets the rate of change of the slider on each scroll. In Percent";
|
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 {
|
AudioMinVolume = mkOption {
|
||||||
type = types.nullOr types.int;
|
type = types.nullOr types.int;
|
||||||
default = 0;
|
default = 0;
|
||||||
|
|
87
src/Bar.cpp
87
src/Bar.cpp
|
@ -163,6 +163,10 @@ namespace Bar
|
||||||
return TimerResult::Ok;
|
return TimerResult::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget* audioSlider;
|
||||||
|
Widget* micSlider;
|
||||||
|
Text* audioIcon;
|
||||||
|
Text* micIcon;
|
||||||
void OnChangeVolumeSink(Slider&, double value)
|
void OnChangeVolumeSink(Slider&, double value)
|
||||||
{
|
{
|
||||||
System::SetVolumeSink(value);
|
System::SetVolumeSink(value);
|
||||||
|
@ -173,14 +177,35 @@ namespace Bar
|
||||||
System::SetVolumeSource(value);
|
System::SetVolumeSource(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Slider* audioSlider;
|
// For text
|
||||||
Slider* micSlider;
|
double audioVolume = 0;
|
||||||
Text* audioIcon;
|
void OnChangeVolumeSinkDelta(double delta)
|
||||||
Text* micIcon;
|
{
|
||||||
|
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&)
|
TimerResult UpdateAudio(Widget&)
|
||||||
{
|
{
|
||||||
System::AudioInfo info = System::GetAudioInfo();
|
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)
|
if (info.sinkMuted)
|
||||||
{
|
{
|
||||||
audioIcon->SetText("");
|
audioIcon->SetText("");
|
||||||
|
@ -191,7 +216,15 @@ namespace Bar
|
||||||
}
|
}
|
||||||
if (Config::Get().audioInput)
|
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)
|
if (info.sourceMuted)
|
||||||
{
|
{
|
||||||
micIcon->SetText("");
|
micIcon->SetText("");
|
||||||
|
@ -326,7 +359,40 @@ namespace Bar
|
||||||
Input,
|
Input,
|
||||||
Output
|
Output
|
||||||
};
|
};
|
||||||
auto widgetAudioSlider = [](Widget& parent, AudioType type)
|
auto widgetAudioVolume = [](Widget& parent, AudioType type)
|
||||||
|
{
|
||||||
|
if (Config::Get().audioNumbers)
|
||||||
|
{
|
||||||
|
auto eventBox = Widget::Create<EventBox>();
|
||||||
|
auto text = Widget::Create<Text>();
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
auto slider = Widget::Create<Slider>();
|
auto slider = Widget::Create<Slider>();
|
||||||
slider->SetOrientation(Utils::GetOrientation());
|
slider->SetOrientation(Utils::GetOrientation());
|
||||||
|
@ -349,9 +415,10 @@ namespace Bar
|
||||||
slider->SetScrollSpeed((double)Config::Get().audioScrollSpeed / 100.);
|
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>();
|
auto box = Widget::Create<Box>();
|
||||||
box->SetSpacing({8, false});
|
box->SetSpacing({8, false});
|
||||||
|
@ -387,7 +454,7 @@ namespace Bar
|
||||||
slideRevealer->SetRevealed(hovered);
|
slideRevealer->SetRevealed(hovered);
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
widgetAudioSlider(*revealer, type);
|
widgetAudioVolume(*revealer, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
box->AddChild(std::move(revealer));
|
box->AddChild(std::move(revealer));
|
||||||
|
@ -395,7 +462,7 @@ namespace Bar
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Straight forward
|
// Straight forward
|
||||||
widgetAudioSlider(*box, type);
|
widgetAudioVolume(*box, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
box->AddChild(std::move(icon));
|
box->AddChild(std::move(icon));
|
||||||
|
|
|
@ -187,6 +187,7 @@ void Config::Load()
|
||||||
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
|
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
|
||||||
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
|
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
|
||||||
AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty);
|
AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty);
|
||||||
|
AddConfigVar("AudioNumbers", config.audioNumbers, lineView, foundProperty);
|
||||||
AddConfigVar("NetworkWidget", config.networkWidget, lineView, foundProperty);
|
AddConfigVar("NetworkWidget", config.networkWidget, lineView, foundProperty);
|
||||||
AddConfigVar("WorkspaceScrollOnMonitor", config.workspaceScrollOnMonitor, lineView, foundProperty);
|
AddConfigVar("WorkspaceScrollOnMonitor", config.workspaceScrollOnMonitor, lineView, foundProperty);
|
||||||
AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty);
|
AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty);
|
||||||
|
|
|
@ -19,11 +19,13 @@ public:
|
||||||
|
|
||||||
// Script that returns how many packages are out-of-date. The script should only print a number!
|
// 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
|
// 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 centerTime = true;
|
||||||
bool audioRevealer = false;
|
bool audioRevealer = false;
|
||||||
bool audioInput = false;
|
bool audioInput = false;
|
||||||
|
bool audioNumbers = false; // Affects both audio sliders
|
||||||
bool networkWidget = true;
|
bool networkWidget = true;
|
||||||
bool workspaceScrollOnMonitor = true; // Scroll through workspaces on monitor instead of all
|
bool workspaceScrollOnMonitor = true; // Scroll through workspaces on monitor instead of all
|
||||||
bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1
|
bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1
|
||||||
|
|
Loading…
Reference in a new issue