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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user