1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 13:32: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

@@ -21,6 +21,10 @@ BasePill {
property bool showMicIcon: widgetData?.showMicIcon !== undefined ? widgetData.showMicIcon : SettingsData.controlCenterShowMicIcon
property bool showBatteryIcon: widgetData?.showBatteryIcon !== undefined ? widgetData.showBatteryIcon : SettingsData.controlCenterShowBatteryIcon
property bool showPrinterIcon: widgetData?.showPrinterIcon !== undefined ? widgetData.showPrinterIcon : SettingsData.controlCenterShowPrinterIcon
property real touchpadThreshold: 100
property real micAccumulator: 0
property real volumeAccumulator: 0
property real brightnessAccumulator: 0
Loader {
active: root.showPrinterIcon
@@ -116,8 +120,21 @@ BasePill {
function handleVolumeWheel(delta) {
if (!AudioService.sink?.audio)
return;
var step = 5;
const isMouseWheel = Math.abs(delta) >= 120 && (Math.abs(delta) % 120) === 0;
if (!isMouseWheel) {
step = 1;
volumeAccumulator += delta;
if (Math.abs(volumeAccumulator) < touchpadThreshold)
return;
delta = volumeAccumulator;
volumeAccumulator = 0;
}
const currentVolume = AudioService.sink.audio.volume * 100;
const newVolume = delta > 0 ? Math.min(100, currentVolume + 5) : Math.max(0, currentVolume - 5);
const newVolume = delta > 0 ? Math.min(100, currentVolume + step) : Math.max(0, currentVolume - step);
AudioService.sink.audio.muted = false;
AudioService.sink.audio.volume = newVolume / 100;
AudioService.playVolumeChangeSoundIfEnabled();
@@ -126,8 +143,21 @@ BasePill {
function handleMicWheel(delta) {
if (!AudioService.source?.audio)
return;
var step = 5;
const isMouseWheel = Math.abs(delta) >= 120 && (Math.abs(delta) % 120) === 0;
if (!isMouseWheel) {
step = 1;
micAccumulator += delta;
if (Math.abs(micAccumulator) < touchpadThreshold)
return;
delta = micAccumulator;
micAccumulator = 0;
}
const currentVolume = AudioService.source.audio.volume * 100;
const newVolume = delta > 0 ? Math.min(100, currentVolume + 5) : Math.max(0, currentVolume - 5);
const newVolume = delta > 0 ? Math.min(100, currentVolume + step) : Math.max(0, currentVolume - step);
AudioService.source.audio.muted = false;
AudioService.source.audio.volume = newVolume / 100;
}
@@ -137,8 +167,21 @@ BasePill {
if (!deviceName) {
return;
}
var step = 5;
const isMouseWheel = Math.abs(delta) >= 120 && (Math.abs(delta) % 120) === 0;
if (!isMouseWheel) {
step = 1;
brightnessAccumulator += delta;
if (Math.abs(brightnessAccumulator) < touchpadThreshold)
return;
delta = brightnessAccumulator;
brightnessAccumulator = 0;
}
const currentBrightness = DisplayService.getDeviceBrightness(deviceName);
const newBrightness = delta > 0 ? Math.min(100, currentBrightness + 5) : Math.max(1, currentBrightness - 5);
const newBrightness = delta > 0 ? Math.min(100, currentBrightness + step) : Math.max(1, currentBrightness - step);
DisplayService.setBrightness(newBrightness, deviceName);
}

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;