feat: make speed sampling window configurable

close #87
This commit is contained in:
Virt 2025-06-25 16:41:27 +02:00
commit 0e0e58ca95
5 changed files with 21 additions and 5 deletions

View file

@ -29,9 +29,11 @@
#define CONFIG_TILT_LIMIT "tilt:limit"
#define CONFIG_TILT_FUNCTION "tilt:function"
#define CONFIG_TILT_WINDOW "tilt:window"
#define CONFIG_STRETCH_LIMIT "stretch:limit"
#define CONFIG_STRETCH_FUNCTION "stretch:function"
#define CONFIG_STRETCH_WINDOW "stretch:window"
#define CONFIG_HIGHRES_ENABLED "hyprcursor:enabled"
#define CONFIG_HIGHRES_NEAREST "hyprcursor:nearest"

View file

@ -135,9 +135,11 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
addShapeConfig(CONFIG_TILT_FUNCTION, "negative_quadratic");
addShapeConfig(CONFIG_TILT_LIMIT, 5000);
addShapeConfig(CONFIG_TILT_WINDOW, 100);
addShapeConfig(CONFIG_STRETCH_FUNCTION, "negative_quadratic");
addShapeConfig(CONFIG_STRETCH_LIMIT, 3000);
addShapeConfig(CONFIG_STRETCH_WINDOW, 100);
addShapeConfig(CONFIG_ROTATE_LENGTH, 20);
addShapeConfig(CONFIG_ROTATE_OFFSET, 0.0f);

View file

@ -11,11 +11,13 @@ EModeUpdate CModeStretch::strategy() {
SModeResult CModeStretch::update(Vector2D pos) {
static auto const* PFUNCTION = (Hyprlang::STRING const*) getConfig(CONFIG_STRETCH_FUNCTION);
static auto* const* PLIMIT = (Hyprlang::INT* const*) getConfig(CONFIG_STRETCH_LIMIT);
static auto* const* PWINDOW = (Hyprlang::INT* const*) getConfig(CONFIG_STRETCH_WINDOW);
auto function = g_pShapeRuleHandler->getStringOr(CONFIG_STRETCH_FUNCTION, *PFUNCTION);
auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_STRETCH_LIMIT, **PLIMIT);
auto window = g_pShapeRuleHandler->getIntOr(CONFIG_STRETCH_WINDOW, **PWINDOW);
// create samples array
int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 10)); // 100ms worth of history, avoiding divide by 0
int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 1000 * window)); // [window]ms worth of history, avoiding divide by 0
samples.resize(max, pos);
samples_index = std::min(samples_index, max - 1);
@ -26,7 +28,7 @@ SModeResult CModeStretch::update(Vector2D pos) {
int first = samples_index;
// calculate speed and tilt
Vector2D speed = (samples[current] - samples[first]) / 0.1;
Vector2D speed = (samples[current] - samples[first]) / window * 1000;
double mag = speed.size();
double angle = -std::atan(speed.x / speed.y) + PI;

View file

@ -11,11 +11,13 @@ EModeUpdate CModeTilt::strategy() {
SModeResult CModeTilt::update(Vector2D pos) {
static auto const* PFUNCTION = (Hyprlang::STRING const*) getConfig(CONFIG_TILT_FUNCTION);
static auto* const* PLIMIT = (Hyprlang::INT* const*) getConfig(CONFIG_TILT_LIMIT);
static auto* const* PWINDOW = (Hyprlang::INT* const*) getConfig(CONFIG_TILT_WINDOW);
auto function = g_pShapeRuleHandler->getStringOr(CONFIG_TILT_FUNCTION, *PFUNCTION);
auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_TILT_LIMIT, **PLIMIT);
auto window = g_pShapeRuleHandler->getIntOr(CONFIG_TILT_WINDOW, **PWINDOW);
// create samples array
int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 10)); // 100ms worth of history, avoiding divide by 0
int max = std::max(1, (int)(g_pHyprRenderer->m_mostHzMonitor->m_refreshRate / 1000 * window)); // [window]ms worth of history, avoiding divide by 0
samples.resize(max, pos);
samples_index = std::min(samples_index, max - 1);
@ -26,7 +28,7 @@ SModeResult CModeTilt::update(Vector2D pos) {
int first = samples_index;
// calculate speed and tilt
double speed = (samples[current].x - samples[first].x) / 0.1;
double speed = (samples[current].x - samples[first].x) / window * 1000;
auto result = SModeResult();
result.rotation = activation(function, limit, speed) * (PI / 3); // 120° in both directions