2024-06-28 14:08:13 +02:00
|
|
|
#include "ModeTilt.hpp"
|
2024-07-02 15:35:37 +02:00
|
|
|
#include "utils.hpp"
|
2024-07-03 00:38:50 +02:00
|
|
|
#include "../config/config.hpp"
|
2024-06-28 14:08:13 +02:00
|
|
|
#include <hyprland/src/Compositor.hpp>
|
|
|
|
|
|
|
|
EModeUpdate CModeTilt::strategy() {
|
|
|
|
return TICK;
|
|
|
|
}
|
|
|
|
|
2024-07-02 15:35:37 +02:00
|
|
|
SModeResult CModeTilt::update(Vector2D pos) {
|
2024-07-03 00:38:50 +02:00
|
|
|
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);
|
2024-06-28 14:08:13 +02:00
|
|
|
|
|
|
|
// create samples array
|
|
|
|
int max = g_pHyprRenderer->m_pMostHzMonitor->refreshRate / 10; // 100ms worth of history
|
2024-10-10 13:04:46 +02:00
|
|
|
samples.resize(max, pos);
|
2024-06-28 14:08:13 +02:00
|
|
|
|
|
|
|
// capture current sample
|
2024-10-10 13:04:46 +02:00
|
|
|
samples[samples_index] = pos;
|
2024-06-28 14:08:13 +02:00
|
|
|
int current = samples_index;
|
|
|
|
samples_index = (samples_index + 1) % max; // increase for next sample
|
|
|
|
int first = samples_index;
|
|
|
|
|
|
|
|
// calculate speed and tilt
|
|
|
|
double speed = (samples[current].x - samples[first].x) / 0.1;
|
|
|
|
|
2024-07-02 15:35:37 +02:00
|
|
|
auto result = SModeResult();
|
2024-07-03 00:38:50 +02:00
|
|
|
result.rotation = activation(function, limit, speed) * (PI / 3); // 120° in both directions
|
2024-07-02 15:35:37 +02:00
|
|
|
return result;
|
2024-06-28 14:08:13 +02:00
|
|
|
}
|
2024-08-25 22:58:55 +02:00
|
|
|
|
|
|
|
void CModeTilt::warp(Vector2D old, Vector2D pos) {
|
|
|
|
auto delta = pos - old;
|
|
|
|
|
|
|
|
for (auto& sample : samples)
|
|
|
|
sample += delta;
|
|
|
|
}
|
2024-10-10 13:04:46 +02:00
|
|
|
|
|
|
|
void CModeTilt::reset() {
|
|
|
|
samples.clear();
|
|
|
|
samples_index = 0;
|
|
|
|
}
|