hypr-dynamic-cursors/src/other/Shake.hpp

36 lines
1,002 B
C++
Raw Normal View History

2024-08-25 20:00:16 +02:00
#include "src/helpers/AnimatedVariable.hpp"
#include <hyprutils/math/Vector2D.hpp>
#include <vector>
#define IPC_SHAKE_START "shakestart"
#define IPC_SHAKE_UPDATE "shakeupdate"
#define IPC_SHAKE_END "shakeend"
using namespace Hyprutils::Math;
2024-08-25 20:00:16 +02:00
using namespace std::chrono;
class CShake {
public:
2024-08-25 20:00:16 +02:00
CShake();
~CShake();
/* calculates the new zoom factor for the current pos */
double update(Vector2D pos);
2024-08-25 22:58:55 +02:00
/* called when a cursor warp has happened (to avoid magnifying on warps) */
void warp(Vector2D old, Vector2D pos);
private:
/* tracks whether the current shake has already been announced in the ipc */
bool ipc = false;
2024-08-25 20:00:16 +02:00
bool started = false;
CAnimatedVariable<float> zoom;
steady_clock::time_point end;
/* ringbuffer for last samples */
std::vector<Vector2D> samples;
/* we also store the distance for each sample to the last, so we do only compute this once */
std::vector<double> samples_distance;
int samples_index = 0;
};