diff --git a/README.md b/README.md index 6376d8d..d6cc388 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,10 @@ plugin:dynamic-cursors { # negative_quadratic - negative version of the quadratic one, feels more aggressive # see `activation` in `src/mode/utils.cpp` for how exactly the calculation is done function = negative_quadratic + + # time window (ms) over which the speed is calculated + # higher values will make slow motions smoother but more delayed + window = 100 } # for mode = stretch @@ -158,6 +162,10 @@ plugin:dynamic-cursors { # negative_quadratic - negative version of the quadratic one, feels more aggressive # see `activation` in `src/mode/utils.cpp` for how exactly the calculation is done function = quadratic + + # time window (ms) over which the speed is calculated + # higher values will make slow motions smoother but more delayed + window = 100 } # configure shake to find @@ -227,7 +235,7 @@ plugin:dynamic-cursors { ### shape rules Shape Rules can be used to override the mode or its behaviour on a per-shape basis. They can be defined with the keyword `shaperule` in the config file, preferably in the `plugin:dynamic-cursors` section. -**Note:** Shape rules only apply to server side cursor shapes. Sadly, not everyone supports server side cursors yet, which means shape rules won't work with apps using toolkits like e.g. GTK. +**Note:** Shape rules only apply to server side cursor shapes. Sadly, not everyone supports server side cursors yet, which means shape rules won't work in some applications. A shape rule usually consists of three parts: ``` diff --git a/src/config/config.hpp b/src/config/config.hpp index 572a070..90b95b5 100644 --- a/src/config/config.hpp +++ b/src/config/config.hpp @@ -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" diff --git a/src/main.cpp b/src/main.cpp index ab26036..d467a54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/mode/ModeStretch.cpp b/src/mode/ModeStretch.cpp index 9eb1203..f6b0fa4 100644 --- a/src/mode/ModeStretch.cpp +++ b/src/mode/ModeStretch.cpp @@ -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; diff --git a/src/mode/ModeTilt.cpp b/src/mode/ModeTilt.cpp index 07cc2ba..671e763 100644 --- a/src/mode/ModeTilt.cpp +++ b/src/mode/ModeTilt.cpp @@ -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