mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
ALabel: add smooth-scrolling-threshold
This commit is contained in:
parent
ed4521d113
commit
ae397c8fa2
@ -36,6 +36,7 @@ class ALabel : public IModule {
|
||||
|
||||
private:
|
||||
std::vector<int> pid_;
|
||||
gdouble distance_scrolled_;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
@ -97,12 +97,24 @@ bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
|
||||
}
|
||||
if (e->direction == GDK_SCROLL_SMOOTH) {
|
||||
gdouble delta_x, delta_y;
|
||||
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent*>(e), &delta_x, &delta_y);
|
||||
if (delta_y < 0) {
|
||||
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent *>(e), &delta_x, &delta_y);
|
||||
distance_scrolled_ += delta_y;
|
||||
gdouble threshold = 0;
|
||||
if (config_["smooth-scrolling-threshold"].isNumeric()) {
|
||||
threshold = config_["smooth-scrolling-threshold"].asDouble();
|
||||
}
|
||||
|
||||
if (distance_scrolled_ < -threshold) {
|
||||
direction_up = true;
|
||||
} else if (delta_y > 0) {
|
||||
} else if (distance_scrolled_ > threshold) {
|
||||
direction_up = false;
|
||||
}
|
||||
if(abs(distance_scrolled_) > threshold) {
|
||||
distance_scrolled_ = 0;
|
||||
} else {
|
||||
// Don't execute the action if we haven't met the threshold!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (direction_up && config_["on-scroll-up"].isString()) {
|
||||
pid_.push_back(util::command::forkExec(config_["on-scroll-up"].asString()));
|
||||
|
Loading…
Reference in New Issue
Block a user