feat: implemented shaperules

This commit is contained in:
Virt 2024-07-03 00:38:50 +02:00
commit 9fd1b6a1c2
13 changed files with 448 additions and 95 deletions

View file

@ -1,6 +1,6 @@
#include "ModeTilt.hpp"
#include "utils.hpp"
#include "../globals.hpp"
#include "../config/config.hpp"
#include <hyprland/src/Compositor.hpp>
EModeUpdate CModeTilt::strategy() {
@ -8,8 +8,10 @@ EModeUpdate CModeTilt::strategy() {
}
SModeResult CModeTilt::update(Vector2D pos) {
static auto const* PFUNCTION = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_TILT_FUNCTION)->getDataStaticPtr();
static auto* const* PMASS = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_TILT_LIMIT)->getDataStaticPtr();
static auto const* PFUNCTION = (Hyprlang::STRING const*) getConfig(CONFIG_TILT_FUNCTION);
static auto* const* PLIMIT = (Hyprlang::INT* const*) getConfig(CONFIG_TILT_LIMIT);
auto function = g_pShapeRuleHandler->getStringOr(CONFIG_TILT_FUNCTION, *PFUNCTION);
auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_TILT_LIMIT, **PLIMIT);
// create samples array
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
@ -25,6 +27,6 @@ SModeResult CModeTilt::update(Vector2D pos) {
double speed = (samples[current].x - samples[first].x) / 0.1;
auto result = SModeResult();
result.rotation = activation(*PFUNCTION, **PMASS, speed) * (PI / 3); // 120° in both directions
result.rotation = activation(function, limit, speed) * (PI / 3); // 120° in both directions
return result;
}