mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-19 16:13:21 +02:00
fix: bandaid fix for jitter after shake
This commit is contained in:
parent
d7c1fdf5f8
commit
e382821ac6
2 changed files with 13 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "src/managers/EventManager.hpp"
|
#include "src/managers/EventManager.hpp"
|
||||||
#include "Shake.hpp"
|
#include "Shake.hpp"
|
||||||
#include <hyprland/src/Compositor.hpp>
|
#include <hyprland/src/Compositor.hpp>
|
||||||
|
#include <hyprland/src/debug/Log.hpp>
|
||||||
|
|
||||||
double CShake::update(Vector2D pos) {
|
double CShake::update(Vector2D pos) {
|
||||||
static auto* const* PTHRESHOLD = (Hyprlang::FLOAT* const*) getConfig(CONFIG_SHAKE_THRESHOLD);
|
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));
|
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;
|
if (diagonal < 100) return 1.0;
|
||||||
|
|
||||||
double zoom = ((trail / diagonal) - **PTHRESHOLD);
|
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
|
// we want ipc to work with factor = 0, so we use it here
|
||||||
return std::max(1.0, zoom * **PFACTOR);
|
return std::max(1.0, zoom * **PFACTOR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ class CShake {
|
||||||
/* tracks whether the current shake has already been announced in the ipc */
|
/* tracks whether the current shake has already been announced in the ipc */
|
||||||
bool ipc = false;
|
bool ipc = false;
|
||||||
|
|
||||||
|
/* stores last measured diagonal */
|
||||||
|
float diagonal = 0;
|
||||||
|
|
||||||
/* ringbuffer for last samples */
|
/* ringbuffer for last samples */
|
||||||
std::vector<Vector2D> samples;
|
std::vector<Vector2D> samples;
|
||||||
/* we also store the distance for each sample to the last, so we do only compute this once */
|
/* we also store the distance for each sample to the last, so we do only compute this once */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue