mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-19 16:13:21 +02:00
parent
80750df211
commit
fcb4c2b87b
5 changed files with 34 additions and 3 deletions
|
@ -10,6 +10,7 @@
|
|||
#define CONFIG_SHAKE_THRESHOLD "plugin:dynamic-cursors:shake:threshold"
|
||||
#define CONFIG_SHAKE_FACTOR "plugin:dynamic-cursors:shake:factor"
|
||||
#define CONFIG_SHAKE_EFFECTS "plugin:dynamic-cursors:shake:effects"
|
||||
#define CONFIG_SHAKE_IPC "plugin:dynamic-cursors:shake:ipc"
|
||||
#define CONFIG_LENGTH "plugin:dynamic-cursors:rotate:length"
|
||||
#define CONFIG_MASS "plugin:dynamic-cursors:tilt:limit"
|
||||
#define CONFIG_FUNCTION "plugin:dynamic-cursors:tilt:function"
|
||||
|
|
|
@ -112,6 +112,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
|||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_SHAKE, Hyprlang::INT{1});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_SHAKE_NEAREST, Hyprlang::INT{1});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_SHAKE_EFFECTS, Hyprlang::INT{0});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_SHAKE_IPC, Hyprlang::INT{0});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_SHAKE_THRESHOLD, Hyprlang::FLOAT{4});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_SHAKE_FACTOR, Hyprlang::FLOAT{1.5});
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#include "../globals.hpp"
|
||||
#include "src/managers/EventManager.hpp"
|
||||
#include "Shake.hpp"
|
||||
#include <hyprland/src/Compositor.hpp>
|
||||
|
||||
double CShake::update(Vector2D pos) {
|
||||
static auto* const* PTHRESHOLD = (Hyprlang::FLOAT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_SHAKE_THRESHOLD)->getDataStaticPtr();
|
||||
static auto* const* PFACTOR = (Hyprlang::FLOAT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_SHAKE_FACTOR)->getDataStaticPtr();
|
||||
static auto* const* PIPC = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_SHAKE_IPC)->getDataStaticPtr();
|
||||
|
||||
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate; // 1s worth of history
|
||||
samples.resize(max);
|
||||
|
@ -35,5 +37,24 @@ double CShake::update(Vector2D pos) {
|
|||
// discard when the diagonal is small, so we don't have issues with inaccuracies
|
||||
if (diagonal < 100) return 1.0;
|
||||
|
||||
return std::max(1.0, ((trail / diagonal) - **PTHRESHOLD) * **PFACTOR);
|
||||
double zoom = ((trail / diagonal) - **PTHRESHOLD);
|
||||
|
||||
if (**PIPC) {
|
||||
if (zoom > 1) {
|
||||
if (!ipc) {
|
||||
g_pEventManager->postEvent(SHyprIPCEvent { IPC_SHAKE_START });
|
||||
ipc = true;
|
||||
}
|
||||
|
||||
g_pEventManager->postEvent(SHyprIPCEvent { IPC_SHAKE_UPDATE, std::format("{},{},{},{}", (int) pos.x, (int) pos.y, trail, diagonal) });
|
||||
} else {
|
||||
if (ipc) {
|
||||
g_pEventManager->postEvent(SHyprIPCEvent { IPC_SHAKE_END });
|
||||
ipc = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we want ipc to work with factor = 0, so we use it here
|
||||
return std::max(1.0, zoom * **PFACTOR);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#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;
|
||||
|
||||
class CShake {
|
||||
|
@ -9,8 +13,8 @@ class CShake {
|
|||
double update(Vector2D pos);
|
||||
|
||||
private:
|
||||
/* tracks the global software lock issued by cursor shaking */
|
||||
bool software = false;
|
||||
/* tracks whether the current shake has already been announced in the ipc */
|
||||
bool ipc = false;
|
||||
|
||||
/* ringbuffer for last samples */
|
||||
std::vector<Vector2D> samples;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue