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,4 +1,6 @@
#include "../globals.hpp"
#include "../config/config.hpp"
#include "src/macros.hpp"
#include <cmath>
#include "ModeRotate.hpp"
EModeUpdate CModeRotate::strategy() {
@ -6,8 +8,10 @@ EModeUpdate CModeRotate::strategy() {
}
SModeResult CModeRotate::update(Vector2D pos) {
static auto* const* PLENGTH = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_ROTATE_LENGTH)->getDataStaticPtr();
static auto* const* POFFSET = (Hyprlang::FLOAT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_ROTATE_OFFSET)->getDataStaticPtr();
static auto* const* PLENGTH = (Hyprlang::INT* const*) getConfig(CONFIG_ROTATE_LENGTH);
static auto* const* POFFSET = (Hyprlang::FLOAT* const*) getConfig(CONFIG_ROTATE_OFFSET);
auto length = g_pShapeRuleHandler->getIntOr(CONFIG_ROTATE_LENGTH, **PLENGTH);
auto offset = g_pShapeRuleHandler->getFloatOr(CONFIG_ROTATE_OFFSET, **POFFSET);
// translate to origin
end.x -= pos.x;
@ -19,14 +23,14 @@ SModeResult CModeRotate::update(Vector2D pos) {
end.y /= size;
// scale to length
end.x *= **PLENGTH;
end.y *= **PLENGTH;
end.x *= length;
end.y *= length;
// calculate angle
double angle = -std::atan(end.x / end.y);
if (end.y > 0) angle += PI;
angle += PI;
angle += **POFFSET * ((2 * PI) / 360); // convert to radiants
angle += offset * ((2 * PI) / 360); // convert to radiants
// translate back
end.x += pos.x;

View file

@ -1,6 +1,6 @@
#include "ModeStretch.hpp"
#include "utils.hpp"
#include "../globals.hpp"
#include "../config/config.hpp"
#include <hyprland/src/Compositor.hpp>
EModeUpdate CModeStretch::strategy() {
@ -8,8 +8,10 @@ EModeUpdate CModeStretch::strategy() {
}
SModeResult CModeStretch::update(Vector2D pos) {
static auto const* PFUNCTION = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_STRETCH_FUNCTION)->getDataStaticPtr();
static auto* const* PLIMIT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_STRETCH_LIMIT)->getDataStaticPtr();
static auto const* PFUNCTION = (Hyprlang::STRING const*) getConfig(CONFIG_STRETCH_FUNCTION);
static auto* const* PLIMIT = (Hyprlang::INT* const*) getConfig(CONFIG_STRETCH_LIMIT);
auto function = g_pShapeRuleHandler->getStringOr(CONFIG_STRETCH_FUNCTION, *PFUNCTION);
auto limit = g_pShapeRuleHandler->getIntOr(CONFIG_STRETCH_LIMIT, **PLIMIT);
// create samples array
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
@ -29,7 +31,7 @@ SModeResult CModeStretch::update(Vector2D pos) {
if (speed.y > 0) angle += PI;
if (mag == 0) angle = 0;
double scale = activation(*PFUNCTION, **PLIMIT, mag);
double scale = activation(function, limit, mag);
auto result = SModeResult();
result.stretch.angle = angle;

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;
}