mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-20 00:23:22 +02:00
feat: stretch mode
This commit is contained in:
parent
91c03dea2e
commit
5fee8c5545
18 changed files with 234 additions and 79 deletions
|
@ -1,43 +1,15 @@
|
|||
#include "ModeTilt.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "../globals.hpp"
|
||||
#include <hyprland/src/Compositor.hpp>
|
||||
|
||||
double function(double speed) {
|
||||
static auto const* PFUNCTION = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_FUNCTION)->getDataStaticPtr();
|
||||
static auto* const* PMASS = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MASS)->getDataStaticPtr();
|
||||
double mass = **PMASS;
|
||||
|
||||
double result = 0;
|
||||
if (!strcmp(*PFUNCTION, "linear")) {
|
||||
|
||||
result = speed / **PMASS;
|
||||
|
||||
} else if (!strcmp(*PFUNCTION, "quadratic")) {
|
||||
|
||||
|
||||
// (1 / m²) * x², is a quadratic function which will reach 1 at m
|
||||
result = (1.0 / (mass * mass)) * (speed * speed);
|
||||
result *= (speed > 0 ? 1 : -1);
|
||||
|
||||
} else if (!strcmp(*PFUNCTION, "negative_quadratic")) {
|
||||
|
||||
float x = std::abs(speed);
|
||||
// (-1 / m²) * (x - m)² + 1, is a quadratic function with the inverse curvature which will reach 1 at m
|
||||
result = (-1.0 / (mass * mass)) * ((x - mass) * (x - mass)) + 1;
|
||||
if (x > mass) result = 1; // need to clamp manually, as the function would decrease again
|
||||
|
||||
result *= (speed > 0 ? 1 : -1);
|
||||
} else
|
||||
Debug::log(WARN, "[dynamic-cursors] unknown air function specified");
|
||||
|
||||
return std::clamp(result, -1.0, 1.0);
|
||||
}
|
||||
|
||||
EModeUpdate CModeTilt::strategy() {
|
||||
return TICK;
|
||||
}
|
||||
|
||||
double CModeTilt::update(Vector2D pos) {
|
||||
SModeResult CModeTilt::update(Vector2D pos) {
|
||||
static auto const* PFUNCTION = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_FUNCTION)->getDataStaticPtr();
|
||||
static auto* const* PMASS = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MASS)->getDataStaticPtr();
|
||||
|
||||
// create samples array
|
||||
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
|
||||
|
@ -52,5 +24,7 @@ double CModeTilt::update(Vector2D pos) {
|
|||
// calculate speed and tilt
|
||||
double speed = (samples[current].x - samples[first].x) / 0.1;
|
||||
|
||||
return function(speed) * (PI / 3); // 120° in both directions
|
||||
auto result = SModeResult();
|
||||
result.rotation = activation(*PFUNCTION, **PMASS, speed) * (PI / 3); // 120° in both directions
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue