last 7 months of qs changes

This commit is contained in:
outfoxxed 2025-01-06 00:13:19 -08:00
parent 2c64563ade
commit 4b90113a54
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
103 changed files with 3467 additions and 1415 deletions

View file

@ -0,0 +1,90 @@
import QtQuick
import Quickshell
Scope {
id: root
required property MouseArea target;
property real velocityX: 0;
property real velocityY: 0;
signal flickStarted();
signal flickCompleted();
property real dragStartX: 0;
property real dragStartY: 0;
property real dragDeltaX: 0;
property real dragDeltaY: 0;
property real dragEndX: 0;
property real dragEndY: 0;
property var sampleIdx: -1
property var tSamples: []
property var xSamples: []
property var ySamples: []
ElapsedTimer { id: velocityTimer }
function resetSamples() {
velocityTimer.restart();
sampleIdx = -1;
tSamples = [];
xSamples = [];
ySamples = [];
}
function sample() {
const deltaT = velocityTimer.elapsed();
sampleIdx++;
if (sampleIdx > 5) {
sampleIdx = 0;
}
tSamples[sampleIdx] = deltaT;
xSamples[sampleIdx] = dragDeltaX;
ySamples[sampleIdx] = dragDeltaY;
}
function updateVelocity() {
let firstIdx = sampleIdx + 1;
if (firstIdx > tSamples.length - 1) firstIdx = 0;
const deltaT = tSamples[sampleIdx] - tSamples[firstIdx];
const deltaX = xSamples[sampleIdx] - xSamples[firstIdx];
const deltaY = ySamples[sampleIdx] - ySamples[firstIdx];
root.velocityX = deltaX / deltaT;
root.velocityY = deltaY / deltaT;
}
Connections {
target: root.target;
function onPressed(event: MouseEvent) {
root.resetSamples();
root.dragDeltaX = 0;
root.dragDeltaY = 0;
root.dragStartX = event.x;
root.dragStartY = event.y;
root.flickStarted();
}
function onReleased(event: MouseEvent) {
root.dragDeltaX = event.x - root.dragStartX;
root.dragDeltaY = event.y - root.dragStartY;
root.dragEndX = event.x;
root.dragEndY = event.y;
root.sample();
root.updateVelocity();
root.flickCompleted();
}
function onPositionChanged(event: MouseEvent) {
root.dragDeltaX = event.x - root.dragStartX;
root.dragDeltaY = event.y - root.dragStartY;
root.sample();
}
}
}