1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 07:52:50 -05:00

Fix touchpad scrolling behavior (#1146)

* Fix touchpad scrolling behavior

* Make touchpad scroll smoothly
For a normal mouse wheel, adjusting by 5% per scroll makes sense. For a touchpad, however, it should adjust by the smallest increment possible for a smooth experience.
This commit is contained in:
Aaron Tulino
2025-12-24 14:12:34 -07:00
committed by GitHub
parent 10e81cfdd3
commit 8e76789119
2 changed files with 68 additions and 8 deletions

View File

@@ -48,19 +48,36 @@ BasePill {
return audioVizHeight + Theme.spacingXS + playButtonHeight;
}
property real scrollAccumulatorY: 0
property real touchpadThreshold: 100
onWheel: function (wheelEvent) {
wheelEvent.accepted = true;
if (!usePlayerVolume)
return;
const delta = wheelEvent.angleDelta.y;
const deltaY = wheelEvent.angleDelta.y;
const isMouseWheelY = Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0;
const currentVolume = activePlayer.volume * 100;
let newVolume;
if (delta > 0) {
newVolume = Math.min(100, currentVolume + 5);
let newVolume = currentVolume;
if (isMouseWheelY) {
if (deltaY > 0) {
newVolume = Math.min(100, currentVolume + 5);
} else if (deltaY < 0) {
newVolume = Math.max(0, currentVolume - 5);
}
} else {
newVolume = Math.max(0, currentVolume - 5);
scrollAccumulatorY += deltaY;
if (Math.abs(scrollAccumulatorY) >= touchpadThreshold) {
if (scrollAccumulatorY > 0) {
newVolume = Math.min(100, currentVolume + 1);
} else {
newVolume = Math.max(0, currentVolume - 1);
}
scrollAccumulatorY = 0;
}
}
activePlayer.volume = newVolume / 100;