Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

ultra fast scrolling when using touchpad. #333

Closed
maxmitti opened this issue Apr 26, 2015 · 13 comments
Closed

ultra fast scrolling when using touchpad. #333

maxmitti opened this issue Apr 26, 2015 · 13 comments

Comments

@maxmitti
Copy link

In the playback history and the playlist, scrolling is way too fast when I use my touchpad.
When I use my mouse it's working normally.
Touchpad-scrolling is working normally in other applications.

@maxmitti
Copy link
Author

The same behaviour can also be seen when scrolling to adjust the volume/amplification.

I tried to fix this issue.
I found a solution for the MainWindow part.
I also tried to fix it in the QML part, though it's the first time I am using QML.
So i fixed the problem, although the animated/smooth scrolling is disabled by this fix.
I implemented scrolling on the ScrollBar itself in the same way.
Hera are the 3 patches so you may or may not include them: http://www.filedropper.com/scrollingpatches

@bylee20
Copy link
Owner

bylee20 commented Apr 27, 2015

list.contentY -= wheel.angleDelta.y * 0.75
What is the multiplier 0.75 based on?

@maxmitti
Copy link
Author

I just tried different multipliers and this one felt right. Though, I think the original scrolling distance would be achieved when using 1 as multiplier. But I am not sure.

@bylee20
Copy link
Owner

bylee20 commented Apr 27, 2015

Is it adjusted for your touchpad then?
It seems that the scroll speed is slow a bit here.
Btw, do you happen to use macbook?

@maxmitti
Copy link
Author

No, I have a normal laptop using arch linux with plasma 5.
There is no special adjustment for the touchpad, but by using angleDelta to determine the scroll distance, the speed should be appropriate. At least with my touchpad it feels normal now.

@bylee20
Copy link
Owner

bylee20 commented Apr 27, 2015

Can you do me a favor?
Please check wheel.pixelDelta.y returns in your laptop.
This value is supposed to be used for fine-grained touchpad.
I've tried my laptop but it returns zero and my laptop does not show your 'ultra-fast scrolling' problem.

If this provide proper value for you, it would be better use this value to calculate velocity instead of disabling animation.
You can print the value using console.log(...), that is, in the mouse area which accepts wheel scroll,

           onWheel: {
                console.log(wheel.pixelDelta.y)
            }

This will print wheel.pixelDelta.y into stdout.

@bylee20
Copy link
Owner

bylee20 commented Apr 27, 2015

Also, there's a property so-called maximumFlickVelocity which defines maximum flicking velocity as it is.
Can you test to find proper value for maximumFlickVelocity your case without overriding wheel event?

@maxmitti
Copy link
Author

Here is the output of the log of pixelDelta, i also logged angleDelta for comparison:
In the first part, where pixelDelta is 0 i used my mouse, in the second part i used my touchpad.

console.log("pixelDelta: ", wheel.pixelDelta.y, ", angleDelta: ", wheel.angleDelta.y)

https://gist.github.com/maxmitti/d857d9f4a420bd8e8041

@maxmitti
Copy link
Author

Can you test to find proper value for maximumFlickVelocity your case without overriding wheel event?

I tried some values and 2000 is somewhat usable, but it feels very unresponsive compared to the method I used in my patch

If this provide proper value for you, it would be better use this value to calculate velocity instead of disabling animation.

I already wanted to set the velocity instead of contentY but i didnt know how i should do it, because verticalVelocity is read-only. Maybe you have a tip how I could set the velocity?

Also, I dont know how to test if the "Invert direction of mouse wheel scroll" in QML to implement that correctly.

@bylee20
Copy link
Owner

bylee20 commented Apr 27, 2015

Can you test this patch?

diff --git a/src/bomi/imports/bomi/ModelView.qml b/src/bomi/imports/bomi/ModelView.qml
index f4c324a..34621a7 100644
--- a/src/bomi/imports/bomi/ModelView.qml
+++ b/src/bomi/imports/bomi/ModelView.qml
@@ -292,7 +292,41 @@ Item {
             }
         }

+        property real tsWheel: -1
+
+        function calcVelocity(angle, pixel, smooth, pos, min, max, dt) {
+            var v = 0
+            if (pixel != 0)
+                v = pixel / dt
+            else
+                v = angle
+            if (v > 0 && pos > min) {
+                if (v == Number.POSITIVE_INFINITY)
+                    v = 0
+                return Math.max(v - smooth, maximumFlickVelocity / 4)
+            } else if (v < 0 && pos < max) {
+                if (v == Number.NEGATIVE_INFINITY)
+                    v = 0
+                return Math.min(v - smooth, -maximumFlickVelocity / 4)
+            }
+            return 0
+        }
+
+        function wheelScroll(angle, pixel) {
+            if (tsWheel < 0)
+                tsWheel = new Date().getTime() / 1000
+            var current = new Date().getTime() / 1000
+            var dt = current - tsWheel
+            var vx = calcVelocity(angle.x, pixel.x, horizontalVelocity, contentX,
+                                  0, contentWidth - list.width, dt)
+            var vy = calcVelocity(angle.y, pixel.y, verticalVelocity, contentY,
+                                  -headerItem.height, contentHeight - list.height - footerItem.height, dt)
+            flick(vx, vy)
+            tsWheel = current
+        }
+
         MouseArea {
+            id: mouseArea
             z: -1
             anchors.fill: parent
             onPressed: {
@@ -305,6 +339,7 @@ Item {
                 if (index !== -1)
                     view.activated(index)
             }
+            onWheel: list.wheelScroll(wheel.angleDelta, wheel.pixelDelta)
         }

@bylee20
Copy link
Owner

bylee20 commented Apr 27, 2015

Also, try this one, too:

diff --git a/src/bomi/imports/bomi/ModelView.qml b/src/bomi/imports/bomi/ModelView.qml
index f4c324a..f2b1693 100644
--- a/src/bomi/imports/bomi/ModelView.qml
+++ b/src/bomi/imports/bomi/ModelView.qml
@@ -291,6 +291,28 @@ Item {
                 positionViewAtIndex(idx, ListView.Visible)
             }
         }
+        function calcVelocity(angle, smooth, pos, min, max) {
+            var v = angle
+            if (v > 0 && pos > min)
+                return Math.max(v - smooth, maximumFlickVelocity / 4)
+            else if (v < 0 && pos < max)
+                return Math.min(v - smooth, -maximumFlickVelocity / 4)
+            return 0
+        }
+
+        function wheelScroll(angle, pixel) {
+            if (pixel.x != 0 || pixel.y != 0) {
+                contentX -= pixel.x
+                contentY -= pixel.y
+                returnToBounds()
+            } else {
+                var vx = calcVelocity(angle.x, horizontalVelocity, contentX,
+                                      0, contentWidth - list.width)
+                var vy = calcVelocity(angle.y, verticalVelocity, contentY,
+                                      -headerItem.height, contentHeight - list.height - footerItem.height)
+                flick(vx, vy)
+            }
+        }

         MouseArea {
             z: -1
@@ -305,6 +327,7 @@ Item {
                 if (index !== -1)
                     view.activated(index)
             }
+            onWheel: list.wheelScroll(wheel.angleDelta, wheel.pixelDelta)
         }

And which one do you think is better?

@maxmitti
Copy link
Author

The first one is still too fast in my opinion.
But I like the second one.
Because I like how you can feel the direct interaction.

@bylee20
Copy link
Owner

bylee20 commented Apr 27, 2015

Fixed. Thank you!

@bylee20 bylee20 closed this as completed Apr 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants