From ed4521d1138cc3d9a660d8e7fac840fd2867cd53 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Tue, 11 Jun 2019 16:19:11 +0200 Subject: [PATCH 1/3] Workspaces: fix twitchy scrolling on touchpads Previously, any and all scroll events were interpreted as reason to switch workspaces. This resulted in twitchy behaviour, where the scrolling was practically unusable. Now, we pool all scroll values, and only scroll if the value is larger than the new config option "smooth-scrolling-threshold". If this option is not set, the behaviour is unchanged. --- include/modules/sway/workspaces.hpp | 1 + src/modules/sway/workspaces.cpp | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index b7632de1..33789df4 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -41,6 +41,7 @@ class Workspaces : public IModule, public sigc::trackable { util::JsonParser parser_; bool scrolling_; std::unordered_map buttons_; + gdouble distance_scrolled_; util::SleeperThread thread_; Ipc ipc_; diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 94a5e03e..3da550e8 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -234,24 +234,37 @@ bool Workspaces::handleScroll(GdkEventScroll *e) { } switch (e->direction) { case GDK_SCROLL_DOWN: - case GDK_SCROLL_RIGHT: + case GDK_SCROLL_RIGHT: { name = getCycleWorkspace(it, false); break; + } case GDK_SCROLL_UP: - case GDK_SCROLL_LEFT: + case GDK_SCROLL_LEFT: { name = getCycleWorkspace(it, true); break; - case GDK_SCROLL_SMOOTH: + } + case GDK_SCROLL_SMOOTH: { gdouble delta_x, delta_y; gdk_event_get_scroll_deltas(reinterpret_cast(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) { name = getCycleWorkspace(it, true); - } else if (delta_y > 0) { + } else if (distance_scrolled_ > threshold) { name = getCycleWorkspace(it, false); } + if(abs(distance_scrolled_) > threshold) { + distance_scrolled_ = 0; + } break; - default: + } + default: { break; + } } if (name.empty() || name == (*it)["name"].asString()) { scrolling_ = false; From ae397c8fa20cb1450bc2483cca1a32a8a137e5a1 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Tue, 11 Jun 2019 17:56:10 +0200 Subject: [PATCH 2/3] ALabel: add smooth-scrolling-threshold --- include/ALabel.hpp | 1 + src/ALabel.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 33903787..5e664d66 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -36,6 +36,7 @@ class ALabel : public IModule { private: std::vector pid_; + gdouble distance_scrolled_; }; } // namespace waybar diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 41ccd298..792e7955 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -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(e), &delta_x, &delta_y); - if (delta_y < 0) { + gdk_event_get_scroll_deltas(reinterpret_cast(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())); From 396f7d45255d981c686715b49855029482facea2 Mon Sep 17 00:00:00 2001 From: Patrick Hilhorst Date: Tue, 11 Jun 2019 18:44:54 +0200 Subject: [PATCH 3/3] Workspaces: implement horizontal continuous scrolling --- src/modules/sway/workspaces.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 3da550e8..fd24555e 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -246,7 +246,12 @@ bool Workspaces::handleScroll(GdkEventScroll *e) { case GDK_SCROLL_SMOOTH: { gdouble delta_x, delta_y; gdk_event_get_scroll_deltas(reinterpret_cast(e), &delta_x, &delta_y); - distance_scrolled_ += delta_y; + + 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();