aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/WheelScroll.qml
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-29 09:44:41 +0100
committerDanilo M. <danix@danix.xyz>2026-11-29 09:44:41 +0100
commit61467b2d35c9b78b352908f8236c0afea45cf635 (patch)
treefbc534f0e63ab9a8cd15b4a656dba742a03a5899 /desktop/WheelScroll.qml
parent50e3f941050ce0a3e588adaad8a575ed3a71ba41 (diff)
downloadquickshell-61467b2d35c9b78b352908f8236c0afea45cf635.tar.gz
quickshell-61467b2d35c9b78b352908f8236c0afea45cf635.zip
feat(settings): a fixed, animated distance per wheel notch
Settings scrolled in jerks and a long list took dozens of notches. Two causes. The 8000/4000 velocity and deceleration pair from 474ddd0 cut each notch's flick short, so the page moved in steps rather than gliding. And under Wayland a mouse notch arrives as angleDelta 120 with pixelDelta 15, on a device Qt types as a touchpad (measured with a logged WheelEvent): Flickable trusts the pixel delta, so every notch moved 15px whatever the velocity settings said. The wallpaper list had its own handler that jumped a whole row per notch, unanimated, which read as stutter too. WheelScroll.qml replaces all of it: a MouseArea taking no buttons that turns angleDelta into a fixed step per notch and animates contentY there over 180ms, notches mid-animation extending the end point. Pages step 150px, the sidebar 120px, the wallpaper list one thumbnail row. On a page it sits beneath the content, in the MouseArea that already focused the page for the paging keys, so an inner slider or list keeps its own wheel. The velocity pair is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/WheelScroll.qml')
-rw-r--r--desktop/WheelScroll.qml55
1 files changed, 55 insertions, 0 deletions
diff --git a/desktop/WheelScroll.qml b/desktop/WheelScroll.qml
new file mode 100644
index 0000000..845a8ff
--- /dev/null
+++ b/desktop/WheelScroll.qml
@@ -0,0 +1,55 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+import QtQuick
+
+// Mouse wheel scrolling for a Flickable: a fixed distance per notch,
+// animated, the same up and down. Qt's own wheel handling took a long
+// list dozens of notches whatever maximumFlickVelocity said. Notches that arrive mid-animation add to its
+// end point, so a fast spin travels further.
+//
+// angleDelta only. Under Wayland a mouse notch arrives as angleDelta 120
+// with pixelDelta 15 and a device typed touchpad (measured), so trusting
+// a non-zero pixelDelta, as Flickable does, scrolled 15px a notch.
+// ponytail: a real touchpad then scrolls by step too; tell the two apart
+// (e.g. pixelDelta != angleDelta / 8) if one is ever used here.
+//
+// Takes no buttons, so clicks reach what is under it; wheel events that
+// an inner item (a slider, a nested list) accepts never reach it.
+MouseArea {
+ id: ws
+ property Flickable flick
+ // Pixels per notch.
+ property real step: 150
+
+ acceptedButtons: Qt.NoButton
+
+ function clamp(y) {
+ return Math.max(flick.originY, Math.min(y,
+ flick.originY + Math.max(0, flick.contentHeight - flick.height)));
+ }
+
+ NumberAnimation {
+ id: anim
+ target: ws.flick
+ property: "contentY"
+ duration: 180
+ easing.type: Easing.OutCubic
+ }
+
+ onWheel: wheel => {
+ flick.cancelFlick();
+ const from = anim.running ? anim.to : flick.contentY;
+ anim.stop();
+ anim.to = clamp(from - wheel.angleDelta.y / 120 * step);
+ anim.start();
+ }
+}