Merge pull request #389 from Synthetica9/x-scroll

AModule: handle X axis scrolling
This commit is contained in:
Alex 2019-06-16 14:54:53 +02:00 committed by GitHub
commit cda6282277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -33,7 +33,8 @@ class AModule : public IModule {
private: private:
std::vector<int> pid_; std::vector<int> pid_;
gdouble distance_scrolled_; gdouble distance_scrolled_y_;
gdouble distance_scrolled_x_;
}; };
} // namespace waybar } // namespace waybar

View File

@ -65,23 +65,28 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
} else if (e->direction == GDK_SCROLL_SMOOTH) { } else 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);
distance_scrolled_ += delta_y; distance_scrolled_y_ += delta_y;
// TODO: handle X axis distance_scrolled_x_ += delta_x;
gdouble threshold = 0; gdouble threshold = 0;
if (config_["smooth-scrolling-threshold"].isNumeric()) { if (config_["smooth-scrolling-threshold"].isNumeric()) {
threshold = config_["smooth-scrolling-threshold"].asDouble(); threshold = config_["smooth-scrolling-threshold"].asDouble();
} }
if (distance_scrolled_ < -threshold) { if (distance_scrolled_y_ < -threshold) {
dir = SCROLL_DIR::UP; dir = SCROLL_DIR::UP;
} else if (distance_scrolled_ > threshold) { } else if (distance_scrolled_y_ > threshold) {
dir = SCROLL_DIR::DOWN; dir = SCROLL_DIR::DOWN;
} else if (distance_scrolled_x_ > threshold) {
dir = SCROLL_DIR::RIGHT;
} else if (distance_scrolled_x_ < -threshold) {
dir = SCROLL_DIR::LEFT;
} }
if (abs(distance_scrolled_) > threshold) {
distance_scrolled_ = 0; if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::DOWN) {
} else { distance_scrolled_y_ = 0;
// Don't execute the action if we haven't met the threshold! } else if (dir == SCROLL_DIR::LEFT || dir == SCROLL_DIR::RIGHT) {
return SCROLL_DIR::NONE; distance_scrolled_x_ = 0;
} }
} }
return dir; return dir;