mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-19 08:03:21 +02:00
parent
98c006aeae
commit
3ff4c2a053
9 changed files with 37 additions and 5 deletions
|
@ -405,9 +405,14 @@ void CDynamicCursors::calculate(EModeUpdate type) {
|
||||||
|
|
||||||
// calculate angle and zoom
|
// calculate angle and zoom
|
||||||
if (mode) {
|
if (mode) {
|
||||||
|
// reset mode if it has changed
|
||||||
|
if (mode != lastMode) mode->reset();
|
||||||
|
|
||||||
if (mode->strategy() == type) resultMode = mode->update(g_pPointerManager->pointerPos);
|
if (mode->strategy() == type) resultMode = mode->update(g_pPointerManager->pointerPos);
|
||||||
} else resultMode = SModeResult();
|
} else resultMode = SModeResult();
|
||||||
|
|
||||||
|
lastMode = mode;
|
||||||
|
|
||||||
if (**PSHAKE) {
|
if (**PSHAKE) {
|
||||||
if (type == TICK) resultShake = shake.update(g_pPointerManager->pointerPos);
|
if (type == TICK) resultShake = shake.update(g_pPointerManager->pointerPos);
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,10 @@ class CDynamicCursors {
|
||||||
CModeRotate rotate;
|
CModeRotate rotate;
|
||||||
CModeTilt tilt;
|
CModeTilt tilt;
|
||||||
CModeStretch stretch;
|
CModeStretch stretch;
|
||||||
|
|
||||||
/* returns the current mode, nullptr if none is selected */
|
/* returns the current mode, nullptr if none is selected */
|
||||||
IMode* currentMode();
|
IMode* currentMode();
|
||||||
|
IMode* lastMode; // used to reset the mode if it was switched (to prune stale data)
|
||||||
|
|
||||||
// shake
|
// shake
|
||||||
CShake shake;
|
CShake shake;
|
||||||
|
|
|
@ -9,8 +9,10 @@ class IMode {
|
||||||
public:
|
public:
|
||||||
/* returns the desired updating strategy for the given mode */
|
/* returns the desired updating strategy for the given mode */
|
||||||
virtual EModeUpdate strategy() = 0;
|
virtual EModeUpdate strategy() = 0;
|
||||||
/* updates the calculations and returns the new angle */
|
/* updates the calculations and returns the new result */
|
||||||
virtual SModeResult update(Vector2D pos) = 0;
|
virtual SModeResult update(Vector2D pos) = 0;
|
||||||
|
/* reset the internal stuff of the mode */
|
||||||
|
virtual void reset() = 0;
|
||||||
/* called on warp, an update will be sent afterwards (probably) */
|
/* called on warp, an update will be sent afterwards (probably) */
|
||||||
virtual void warp(Vector2D old, Vector2D pos) = 0;
|
virtual void warp(Vector2D old, Vector2D pos) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,6 +13,12 @@ SModeResult CModeRotate::update(Vector2D pos) {
|
||||||
auto length = g_pShapeRuleHandler->getIntOr(CONFIG_ROTATE_LENGTH, **PLENGTH);
|
auto length = g_pShapeRuleHandler->getIntOr(CONFIG_ROTATE_LENGTH, **PLENGTH);
|
||||||
auto offset = g_pShapeRuleHandler->getFloatOr(CONFIG_ROTATE_OFFSET, **POFFSET);
|
auto offset = g_pShapeRuleHandler->getFloatOr(CONFIG_ROTATE_OFFSET, **POFFSET);
|
||||||
|
|
||||||
|
// this mode has just started, start at upright orientation
|
||||||
|
if (end.y == 0 && end.x == 0) {
|
||||||
|
end.x = pos.x;
|
||||||
|
end.y = pos.y + length;
|
||||||
|
}
|
||||||
|
|
||||||
// translate to origin
|
// translate to origin
|
||||||
end.x -= pos.x;
|
end.x -= pos.x;
|
||||||
end.y -= pos.y;
|
end.y -= pos.y;
|
||||||
|
@ -49,3 +55,7 @@ SModeResult CModeRotate::update(Vector2D pos) {
|
||||||
void CModeRotate::warp(Vector2D old, Vector2D pos) {
|
void CModeRotate::warp(Vector2D old, Vector2D pos) {
|
||||||
end += (pos - old);
|
end += (pos - old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModeRotate::reset() {
|
||||||
|
end = {0, 0};
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ class CModeRotate : public IMode {
|
||||||
public:
|
public:
|
||||||
virtual EModeUpdate strategy();
|
virtual EModeUpdate strategy();
|
||||||
virtual SModeResult update(Vector2D pos);
|
virtual SModeResult update(Vector2D pos);
|
||||||
|
virtual void reset();
|
||||||
virtual void warp(Vector2D old, Vector2D pos);
|
virtual void warp(Vector2D old, Vector2D pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,10 +15,10 @@ SModeResult CModeStretch::update(Vector2D pos) {
|
||||||
|
|
||||||
// create samples array
|
// create samples array
|
||||||
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
|
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
|
||||||
samples.resize(max);
|
samples.resize(max, pos);
|
||||||
|
|
||||||
// capture current sample
|
// capture current sample
|
||||||
samples[samples_index] = Vector2D{pos};
|
samples[samples_index] = pos;
|
||||||
int current = samples_index;
|
int current = samples_index;
|
||||||
samples_index = (samples_index + 1) % max; // increase for next sample
|
samples_index = (samples_index + 1) % max; // increase for next sample
|
||||||
int first = samples_index;
|
int first = samples_index;
|
||||||
|
@ -47,3 +47,8 @@ void CModeStretch::warp(Vector2D old, Vector2D pos) {
|
||||||
for (auto& sample : samples)
|
for (auto& sample : samples)
|
||||||
sample += delta;
|
sample += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModeStretch::reset() {
|
||||||
|
samples.clear();
|
||||||
|
samples_index = 0;
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ class CModeStretch : public IMode {
|
||||||
public:
|
public:
|
||||||
virtual EModeUpdate strategy();
|
virtual EModeUpdate strategy();
|
||||||
virtual SModeResult update(Vector2D pos);
|
virtual SModeResult update(Vector2D pos);
|
||||||
|
virtual void reset();
|
||||||
virtual void warp(Vector2D old, Vector2D pos);
|
virtual void warp(Vector2D old, Vector2D pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,10 +15,10 @@ SModeResult CModeTilt::update(Vector2D pos) {
|
||||||
|
|
||||||
// create samples array
|
// create samples array
|
||||||
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
|
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
|
||||||
samples.resize(max);
|
samples.resize(max, pos);
|
||||||
|
|
||||||
// capture current sample
|
// capture current sample
|
||||||
samples[samples_index] = Vector2D{pos};
|
samples[samples_index] = pos;
|
||||||
int current = samples_index;
|
int current = samples_index;
|
||||||
samples_index = (samples_index + 1) % max; // increase for next sample
|
samples_index = (samples_index + 1) % max; // increase for next sample
|
||||||
int first = samples_index;
|
int first = samples_index;
|
||||||
|
@ -37,3 +37,8 @@ void CModeTilt::warp(Vector2D old, Vector2D pos) {
|
||||||
for (auto& sample : samples)
|
for (auto& sample : samples)
|
||||||
sample += delta;
|
sample += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModeTilt::reset() {
|
||||||
|
samples.clear();
|
||||||
|
samples_index = 0;
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ class CModeTilt : public IMode {
|
||||||
public:
|
public:
|
||||||
virtual EModeUpdate strategy();
|
virtual EModeUpdate strategy();
|
||||||
virtual SModeResult update(Vector2D pos);
|
virtual SModeResult update(Vector2D pos);
|
||||||
|
virtual void reset();
|
||||||
virtual void warp(Vector2D old, Vector2D pos);
|
virtual void warp(Vector2D old, Vector2D pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue