mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-24 20:22:10 +00:00
AudioSlider: Add option for scroll speed
There seems to be a floating point error somewhere though, since sometimes it goes up by AudioScrollSpeed - 1 instead of AudioScrollSpeed... For the ping https://github.com/scorpion-26/gBar/issues/5
This commit is contained in:
parent
906a1259c3
commit
a12cb9af5d
6 changed files with 39 additions and 1 deletions
|
@ -41,6 +41,9 @@ CenterTime: true
|
||||||
# Sets the audio slider to be on reveal (Just like the sensors) when true. Only affects the bar.
|
# Sets the audio slider to be on reveal (Just like the sensors) when true. Only affects the bar.
|
||||||
AudioRevealer: false
|
AudioRevealer: false
|
||||||
|
|
||||||
|
# Sets the rate of change of the slider on each scroll. In Percent
|
||||||
|
AudioScrollSpeed: 5
|
||||||
|
|
||||||
# The network adapter to use. You can query /sys/class/net for all possible values
|
# The network adapter to use. You can query /sys/class/net for all possible values
|
||||||
NetworkAdapter: eno1
|
NetworkAdapter: eno1
|
||||||
|
|
||||||
|
|
|
@ -268,6 +268,7 @@ namespace Bar
|
||||||
slider->AddTimer<Slider>(DynCtx::UpdateAudio, DynCtx::updateTimeFast);
|
slider->AddTimer<Slider>(DynCtx::UpdateAudio, DynCtx::updateTimeFast);
|
||||||
slider->OnValueChange(DynCtx::OnChangeVolume);
|
slider->OnValueChange(DynCtx::OnChangeVolume);
|
||||||
slider->SetRange({0, 1, 0.01});
|
slider->SetRange({0, 1, 0.01});
|
||||||
|
slider->SetScrollSpeed((double)Config::Get().audioScrollSpeed / 100.);
|
||||||
|
|
||||||
parent.AddChild(std::move(slider));
|
parent.AddChild(std::move(slider));
|
||||||
};
|
};
|
||||||
|
|
|
@ -142,6 +142,8 @@ void Config::Load()
|
||||||
AddConfigVar("MinDownloadBytes", config.minDownloadBytes, lineView, foundProperty);
|
AddConfigVar("MinDownloadBytes", config.minDownloadBytes, lineView, foundProperty);
|
||||||
AddConfigVar("MaxDownloadBytes", config.maxDownloadBytes, lineView, foundProperty);
|
AddConfigVar("MaxDownloadBytes", config.maxDownloadBytes, lineView, foundProperty);
|
||||||
|
|
||||||
|
AddConfigVar("AudioScrollSpeed", config.audioScrollSpeed, lineView, foundProperty);
|
||||||
|
|
||||||
if (foundProperty == false)
|
if (foundProperty == false)
|
||||||
{
|
{
|
||||||
LOG("Warning: unknown config var: " << lineView);
|
LOG("Warning: unknown config var: " << lineView);
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
uint32_t minDownloadBytes = 0; // Bottom limit of the network widgets download. Everything above it is considered "under"
|
uint32_t minDownloadBytes = 0; // Bottom limit of the network widgets download. Everything above it is considered "under"
|
||||||
uint32_t maxDownloadBytes = 10 * 1024 * 1024; // 10 MiB Top limit of the network widgets download. Everything above it is considered "over"
|
uint32_t maxDownloadBytes = 10 * 1024 * 1024; // 10 MiB Top limit of the network widgets download. Everything above it is considered "over"
|
||||||
|
|
||||||
|
uint32_t audioScrollSpeed = 5; // 5% each scroll
|
||||||
|
|
||||||
static void Load();
|
static void Load();
|
||||||
static const Config& Get();
|
static const Config& Get();
|
||||||
};
|
};
|
||||||
|
|
|
@ -550,6 +550,11 @@ void Slider::SetInverted(bool inverted)
|
||||||
m_Inverted = inverted;
|
m_Inverted = inverted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Slider::SetScrollSpeed(double speed)
|
||||||
|
{
|
||||||
|
m_ScrollSpeed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
void Slider::Create()
|
void Slider::Create()
|
||||||
{
|
{
|
||||||
m_Widget = gtk_scale_new_with_range(Utils::ToGtkOrientation(m_Orientation), m_Range.min, m_Range.max, m_Range.step);
|
m_Widget = gtk_scale_new_with_range(Utils::ToGtkOrientation(m_Orientation), m_Range.min, m_Range.max, m_Range.step);
|
||||||
|
@ -564,6 +569,29 @@ void Slider::Create()
|
||||||
};
|
};
|
||||||
g_signal_connect(m_Widget, "change-value", G_CALLBACK(+changedFn), this);
|
g_signal_connect(m_Widget, "change-value", G_CALLBACK(+changedFn), this);
|
||||||
|
|
||||||
|
auto scroll = [](GtkWidget*, GdkEventScroll* event, void* data) -> gboolean
|
||||||
|
{
|
||||||
|
Slider* slider = (Slider*)data;
|
||||||
|
double value = gtk_range_get_value((GtkRange*)slider->m_Widget);
|
||||||
|
// Range generates a 'smooth' event.
|
||||||
|
if (event->delta_y >= 0)
|
||||||
|
{
|
||||||
|
value -= slider->m_ScrollSpeed;
|
||||||
|
slider->SetValue(value);
|
||||||
|
if (slider->m_OnValueChange)
|
||||||
|
slider->m_OnValueChange(*slider, value);
|
||||||
|
}
|
||||||
|
else if (event->delta_y <= 0)
|
||||||
|
{
|
||||||
|
value += slider->m_ScrollSpeed;
|
||||||
|
slider->SetValue(value);
|
||||||
|
if (slider->m_OnValueChange)
|
||||||
|
slider->m_OnValueChange(*slider, value);
|
||||||
|
}
|
||||||
|
return GDK_EVENT_STOP;
|
||||||
|
};
|
||||||
|
g_signal_connect(m_Widget, "scroll-event", G_CALLBACK(+scroll), this);
|
||||||
|
|
||||||
// Propagate events to any parent eventboxes
|
// Propagate events to any parent eventboxes
|
||||||
auto propagate = [](GtkWidget*, GdkEventCrossing* data, gpointer widget) -> gboolean
|
auto propagate = [](GtkWidget*, GdkEventCrossing* data, gpointer widget) -> gboolean
|
||||||
{
|
{
|
||||||
|
@ -573,7 +601,7 @@ void Slider::Create()
|
||||||
slider->PropagateToParent((GdkEvent*)data);
|
slider->PropagateToParent((GdkEvent*)data);
|
||||||
return GDK_EVENT_PROPAGATE;
|
return GDK_EVENT_PROPAGATE;
|
||||||
};
|
};
|
||||||
gtk_widget_set_events(m_Widget, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
|
gtk_widget_set_events(m_Widget, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK);
|
||||||
g_signal_connect(m_Widget, "enter-notify-event", G_CALLBACK(+propagate), this);
|
g_signal_connect(m_Widget, "enter-notify-event", G_CALLBACK(+propagate), this);
|
||||||
g_signal_connect(m_Widget, "leave-notify-event", G_CALLBACK(+propagate), this);
|
g_signal_connect(m_Widget, "leave-notify-event", G_CALLBACK(+propagate), this);
|
||||||
ApplyPropertiesToWidget();
|
ApplyPropertiesToWidget();
|
||||||
|
|
|
@ -314,6 +314,7 @@ public:
|
||||||
void SetOrientation(Orientation orientation);
|
void SetOrientation(Orientation orientation);
|
||||||
void SetInverted(bool flipped);
|
void SetInverted(bool flipped);
|
||||||
void SetRange(SliderRange range);
|
void SetRange(SliderRange range);
|
||||||
|
void SetScrollSpeed(double speed);
|
||||||
|
|
||||||
void OnValueChange(std::function<void(Slider&, double)>&& callback);
|
void OnValueChange(std::function<void(Slider&, double)>&& callback);
|
||||||
|
|
||||||
|
@ -323,5 +324,6 @@ private:
|
||||||
Orientation m_Orientation = Orientation::Horizontal;
|
Orientation m_Orientation = Orientation::Horizontal;
|
||||||
SliderRange m_Range;
|
SliderRange m_Range;
|
||||||
bool m_Inverted = false;
|
bool m_Inverted = false;
|
||||||
|
double m_ScrollSpeed = 5. / 100.; // 5%
|
||||||
std::function<void(Slider&, double)> m_OnValueChange;
|
std::function<void(Slider&, double)> m_OnValueChange;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue