From e382821ac67f4812d766982c3ec98cb6d026a311 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:51:19 +0200 Subject: [PATCH] fix: bandaid fix for jitter after shake --- src/other/Shake.cpp | 11 ++++++++++- src/other/Shake.hpp | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/other/Shake.cpp b/src/other/Shake.cpp index 3a62777..fc7958b 100644 --- a/src/other/Shake.cpp +++ b/src/other/Shake.cpp @@ -3,6 +3,7 @@ #include "src/managers/EventManager.hpp" #include "Shake.hpp" #include +#include double CShake::update(Vector2D pos) { static auto* const* PTHRESHOLD = (Hyprlang::FLOAT* const*) getConfig(CONFIG_SHAKE_THRESHOLD); @@ -35,7 +36,7 @@ double CShake::update(Vector2D pos) { } double diagonal = Vector2D{left, top}.distance(Vector2D(right, bottom)); - // discard when the diagonal is small, so we don't have issues with inaccuracies + // discard when the diagonal is small, return so we don't have issues with inaccuracies if (diagonal < 100) return 1.0; double zoom = ((trail / diagonal) - **PTHRESHOLD); @@ -56,6 +57,14 @@ double CShake::update(Vector2D pos) { } } + // fix jitter by allowing the diagonal to only grow, until we are below the threshold again + if (zoom > 0) { // larger than 0 because of factor + if (diagonal > this->diagonal) + this->diagonal = diagonal; + + zoom = ((trail / this->diagonal) - **PTHRESHOLD); + } else this->diagonal = 0; + // we want ipc to work with factor = 0, so we use it here return std::max(1.0, zoom * **PFACTOR); } diff --git a/src/other/Shake.hpp b/src/other/Shake.hpp index 27f6319..df097ef 100644 --- a/src/other/Shake.hpp +++ b/src/other/Shake.hpp @@ -16,6 +16,9 @@ class CShake { /* tracks whether the current shake has already been announced in the ipc */ bool ipc = false; + /* stores last measured diagonal */ + float diagonal = 0; + /* ringbuffer for last samples */ std::vector samples; /* we also store the distance for each sample to the last, so we do only compute this once */