mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-28 07:22:50 -05:00
workspace: update scroll accumulator logic
This commit is contained in:
@@ -666,9 +666,10 @@ PanelWindow {
|
|||||||
propagateComposedEvents: true
|
propagateComposedEvents: true
|
||||||
z: -1
|
z: -1
|
||||||
|
|
||||||
property real scrollAccumulatorY: 0
|
property real touchpadAccumulatorY: 0
|
||||||
property real scrollAccumulatorX: 0
|
property real touchpadAccumulatorX: 0
|
||||||
property real touchpadThreshold: 500
|
property real mouseAccumulatorY: 0
|
||||||
|
property real mouseAccumulatorX: 0
|
||||||
property bool actionInProgress: false
|
property bool actionInProgress: false
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -696,44 +697,39 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onWheel: wheel => {
|
onWheel: wheel => {
|
||||||
if (!(barConfig?.scrollEnabled ?? true)) {
|
if (!(barConfig?.scrollEnabled ?? true) || actionInProgress) {
|
||||||
wheel.accepted = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actionInProgress) {
|
|
||||||
wheel.accepted = false;
|
wheel.accepted = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const deltaY = wheel.angleDelta.y;
|
const deltaY = wheel.angleDelta.y;
|
||||||
const deltaX = wheel.angleDelta.x;
|
const deltaX = wheel.angleDelta.x;
|
||||||
const hasPixelY = wheel.pixelDelta && wheel.pixelDelta.y !== 0;
|
const isTouchpadY = wheel.pixelDelta && wheel.pixelDelta.y !== 0;
|
||||||
const hasPixelX = wheel.pixelDelta && wheel.pixelDelta.x !== 0;
|
const isTouchpadX = wheel.pixelDelta && wheel.pixelDelta.x !== 0;
|
||||||
const xBehavior = barConfig?.scrollXBehavior ?? "column";
|
const xBehavior = barConfig?.scrollXBehavior ?? "column";
|
||||||
const yBehavior = barConfig?.scrollYBehavior ?? "workspace";
|
const yBehavior = barConfig?.scrollYBehavior ?? "workspace";
|
||||||
|
const reverse = SettingsData.reverseScrolling ? -1 : 1;
|
||||||
|
|
||||||
if (CompositorService.isNiri && xBehavior !== "none" && Math.abs(deltaX) > Math.abs(deltaY)) {
|
if (CompositorService.isNiri && xBehavior !== "none" && Math.abs(deltaX) > Math.abs(deltaY)) {
|
||||||
const isTraditionalMouse = !hasPixelX && Math.abs(deltaX) >= 120 && (Math.abs(deltaX) % 120) === 0;
|
if (isTouchpadX) {
|
||||||
const isHighDpiMouse = !hasPixelX && !isTraditionalMouse && deltaX !== 0;
|
touchpadAccumulatorX += deltaX;
|
||||||
const reverse = SettingsData.reverseScrolling ? -1 : 1;
|
if (Math.abs(touchpadAccumulatorX) >= 500) {
|
||||||
const direction = deltaX * reverse < 0 ? 1 : -1;
|
const direction = touchpadAccumulatorX * reverse < 0 ? 1 : -1;
|
||||||
|
if (handleScrollAction(xBehavior, direction)) {
|
||||||
if (isTraditionalMouse || isHighDpiMouse) {
|
|
||||||
if (handleScrollAction(xBehavior, direction)) {
|
|
||||||
actionInProgress = true;
|
|
||||||
cooldownTimer.restart();
|
|
||||||
scrollAccumulatorX = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
scrollAccumulatorX += deltaX;
|
|
||||||
if (Math.abs(scrollAccumulatorX) >= touchpadThreshold) {
|
|
||||||
const touchDirection = scrollAccumulatorX < 0 ? 1 : -1;
|
|
||||||
if (handleScrollAction(xBehavior, touchDirection)) {
|
|
||||||
actionInProgress = true;
|
actionInProgress = true;
|
||||||
cooldownTimer.restart();
|
cooldownTimer.restart();
|
||||||
}
|
}
|
||||||
scrollAccumulatorX = 0;
|
touchpadAccumulatorX = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mouseAccumulatorX += deltaX;
|
||||||
|
if (Math.abs(mouseAccumulatorX) >= 120) {
|
||||||
|
const direction = mouseAccumulatorX * reverse < 0 ? 1 : -1;
|
||||||
|
if (handleScrollAction(xBehavior, direction)) {
|
||||||
|
actionInProgress = true;
|
||||||
|
cooldownTimer.restart();
|
||||||
|
}
|
||||||
|
mouseAccumulatorX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wheel.accepted = false;
|
wheel.accepted = false;
|
||||||
@@ -745,26 +741,25 @@ PanelWindow {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTraditionalMouse = !hasPixelY && Math.abs(deltaY) >= 120 && (Math.abs(deltaY) % 120) === 0;
|
if (isTouchpadY) {
|
||||||
const isHighDpiMouse = !hasPixelY && !isTraditionalMouse && deltaY !== 0;
|
touchpadAccumulatorY += deltaY;
|
||||||
const reverse = SettingsData.reverseScrolling ? -1 : 1;
|
if (Math.abs(touchpadAccumulatorY) >= 500) {
|
||||||
const direction = deltaY * reverse < 0 ? 1 : -1;
|
const direction = touchpadAccumulatorY * reverse < 0 ? 1 : -1;
|
||||||
|
if (handleScrollAction(yBehavior, direction)) {
|
||||||
if (isTraditionalMouse || isHighDpiMouse) {
|
|
||||||
if (handleScrollAction(yBehavior, direction)) {
|
|
||||||
actionInProgress = true;
|
|
||||||
cooldownTimer.restart();
|
|
||||||
scrollAccumulatorY = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
scrollAccumulatorY += deltaY;
|
|
||||||
if (Math.abs(scrollAccumulatorY) >= touchpadThreshold) {
|
|
||||||
const touchDirection = scrollAccumulatorY < 0 ? 1 : -1;
|
|
||||||
if (handleScrollAction(yBehavior, touchDirection)) {
|
|
||||||
actionInProgress = true;
|
actionInProgress = true;
|
||||||
cooldownTimer.restart();
|
cooldownTimer.restart();
|
||||||
}
|
}
|
||||||
scrollAccumulatorY = 0;
|
touchpadAccumulatorY = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mouseAccumulatorY += deltaY;
|
||||||
|
if (Math.abs(mouseAccumulatorY) >= 120) {
|
||||||
|
const direction = mouseAccumulatorY * reverse < 0 ? 1 : -1;
|
||||||
|
if (handleScrollAction(yBehavior, direction)) {
|
||||||
|
actionInProgress = true;
|
||||||
|
cooldownTimer.restart();
|
||||||
|
}
|
||||||
|
mouseAccumulatorY = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -649,8 +649,8 @@ Item {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
|
|
||||||
property real scrollAccumulator: 0
|
property real touchpadAccumulator: 0
|
||||||
property real touchpadThreshold: 500
|
property real mouseAccumulator: 0
|
||||||
property bool scrollInProgress: false
|
property bool scrollInProgress: false
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -674,28 +674,29 @@ Item {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const delta = wheel.angleDelta.y;
|
const delta = wheel.angleDelta.y;
|
||||||
const hasPixel = wheel.pixelDelta && wheel.pixelDelta.y !== 0;
|
const isTouchpad = wheel.pixelDelta && wheel.pixelDelta.y !== 0;
|
||||||
const isTraditionalMouse = !hasPixel && Math.abs(delta) >= 120 && (Math.abs(delta) % 120) === 0;
|
|
||||||
const isHighDpiMouse = !hasPixel && !isTraditionalMouse && delta !== 0;
|
|
||||||
const reverse = SettingsData.reverseScrolling ? -1 : 1;
|
const reverse = SettingsData.reverseScrolling ? -1 : 1;
|
||||||
const direction = delta * reverse < 0 ? 1 : -1;
|
|
||||||
|
|
||||||
if (isTraditionalMouse || isHighDpiMouse) {
|
if (isTouchpad) {
|
||||||
|
touchpadAccumulator += delta;
|
||||||
|
if (Math.abs(touchpadAccumulator) < 500)
|
||||||
|
return;
|
||||||
|
const direction = touchpadAccumulator * reverse < 0 ? 1 : -1;
|
||||||
root.switchWorkspace(direction);
|
root.switchWorkspace(direction);
|
||||||
scrollInProgress = true;
|
scrollInProgress = true;
|
||||||
scrollCooldown.restart();
|
scrollCooldown.restart();
|
||||||
scrollAccumulator = 0;
|
touchpadAccumulator = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollAccumulator += delta;
|
mouseAccumulator += delta;
|
||||||
if (Math.abs(scrollAccumulator) >= touchpadThreshold) {
|
if (Math.abs(mouseAccumulator) < 120)
|
||||||
const touchDirection = scrollAccumulator < 0 ? 1 : -1;
|
return;
|
||||||
root.switchWorkspace(touchDirection);
|
const direction = mouseAccumulator * reverse < 0 ? 1 : -1;
|
||||||
scrollInProgress = true;
|
root.switchWorkspace(direction);
|
||||||
scrollCooldown.restart();
|
scrollInProgress = true;
|
||||||
scrollAccumulator = 0;
|
scrollCooldown.restart();
|
||||||
}
|
mouseAccumulator = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user