Fix twitchy scrolling on touchpads (#381)
Fix twitchy scrolling on touchpads
This commit is contained in:
commit
11bbc3b24d
|
@ -36,6 +36,7 @@ class ALabel : public IModule {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<int> pid_;
|
std::vector<int> pid_;
|
||||||
|
gdouble distance_scrolled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
|
|
@ -41,6 +41,7 @@ class Workspaces : public IModule, public sigc::trackable {
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
bool scrolling_;
|
bool scrolling_;
|
||||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||||
|
gdouble distance_scrolled_;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
|
|
|
@ -97,12 +97,24 @@ bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
|
||||||
}
|
}
|
||||||
if (e->direction == GDK_SCROLL_SMOOTH) {
|
if (e->direction == GDK_SCROLL_SMOOTH) {
|
||||||
gdouble delta_x, delta_y;
|
gdouble delta_x, delta_y;
|
||||||
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent*>(e), &delta_x, &delta_y);
|
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent *>(e), &delta_x, &delta_y);
|
||||||
if (delta_y < 0) {
|
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;
|
direction_up = true;
|
||||||
} else if (delta_y > 0) {
|
} else if (distance_scrolled_ > threshold) {
|
||||||
direction_up = false;
|
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()) {
|
if (direction_up && config_["on-scroll-up"].isString()) {
|
||||||
pid_.push_back(util::command::forkExec(config_["on-scroll-up"].asString()));
|
pid_.push_back(util::command::forkExec(config_["on-scroll-up"].asString()));
|
||||||
|
|
|
@ -240,24 +240,42 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||||
}
|
}
|
||||||
switch (e->direction) {
|
switch (e->direction) {
|
||||||
case GDK_SCROLL_DOWN:
|
case GDK_SCROLL_DOWN:
|
||||||
case GDK_SCROLL_RIGHT:
|
case GDK_SCROLL_RIGHT: {
|
||||||
name = getCycleWorkspace(it, false);
|
name = getCycleWorkspace(it, false);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case GDK_SCROLL_UP:
|
case GDK_SCROLL_UP:
|
||||||
case GDK_SCROLL_LEFT:
|
case GDK_SCROLL_LEFT: {
|
||||||
name = getCycleWorkspace(it, true);
|
name = getCycleWorkspace(it, true);
|
||||||
break;
|
break;
|
||||||
case GDK_SCROLL_SMOOTH:
|
}
|
||||||
|
case GDK_SCROLL_SMOOTH: {
|
||||||
gdouble delta_x, delta_y;
|
gdouble delta_x, delta_y;
|
||||||
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent *>(e), &delta_x, &delta_y);
|
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent *>(e), &delta_x, &delta_y);
|
||||||
if (delta_y < 0) {
|
|
||||||
|
if (abs(delta_x) > abs(delta_y)) {
|
||||||
|
distance_scrolled_ += delta_x;
|
||||||
|
} else {
|
||||||
|
distance_scrolled_ += delta_y;
|
||||||
|
}
|
||||||
|
gdouble threshold = 0;
|
||||||
|
if (config_["smooth-scrolling-threshold"].isNumeric()) {
|
||||||
|
threshold = config_["smooth-scrolling-threshold"].asDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (distance_scrolled_ < -threshold) {
|
||||||
name = getCycleWorkspace(it, true);
|
name = getCycleWorkspace(it, true);
|
||||||
} else if (delta_y > 0) {
|
} else if (distance_scrolled_ > threshold) {
|
||||||
name = getCycleWorkspace(it, false);
|
name = getCycleWorkspace(it, false);
|
||||||
}
|
}
|
||||||
|
if(abs(distance_scrolled_) > threshold) {
|
||||||
|
distance_scrolled_ = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default: {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (name.empty() || name == (*it)["name"].asString()) {
|
if (name.empty() || name == (*it)["name"].asString()) {
|
||||||
scrolling_ = false;
|
scrolling_ = false;
|
||||||
|
|
Loading…
Reference in New Issue