mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-19 16:13:21 +02:00
feat: clearer config naming and docs
This commit is contained in:
parent
416f6efc2f
commit
086c9a8c48
4 changed files with 80 additions and 45 deletions
|
@ -198,22 +198,6 @@ bool CDynamicCursors::setHardware(CPointerManager* pointers, SP<CPointerManager:
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Should the cursor be updated after move?
|
||||
*/
|
||||
bool shouldMove() {
|
||||
static auto const* PMODE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MODE)->getDataStaticPtr();
|
||||
return !strcmp(*PMODE, "stick");
|
||||
}
|
||||
|
||||
/*
|
||||
Should the cursor be updated after tick?
|
||||
*/
|
||||
bool shouldUpdate() {
|
||||
static auto const* PMODE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MODE)->getDataStaticPtr();
|
||||
return !strcmp(*PMODE, "air");
|
||||
}
|
||||
|
||||
/*
|
||||
Handles cursor move events.
|
||||
*/
|
||||
|
@ -233,24 +217,33 @@ void CDynamicCursors::onCursorMoved(CPointerManager* pointers) {
|
|||
m->output->impl->move_cursor(m->output, CURSORPOS.x, CURSORPOS.y);
|
||||
}
|
||||
|
||||
if (shouldMove()) calculate();
|
||||
static auto const* PMODE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MODE)->getDataStaticPtr();
|
||||
if (!strcmp(*PMODE, "rotate")) calculate();
|
||||
}
|
||||
|
||||
/*
|
||||
Handle cursor tick events.
|
||||
*/
|
||||
void CDynamicCursors::onTick(CPointerManager* pointers) {
|
||||
if (shouldUpdate()) calculate();
|
||||
static auto const* PMODE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MODE)->getDataStaticPtr();
|
||||
|
||||
if (!strcmp(*PMODE, "tilt")) calculate();
|
||||
}
|
||||
|
||||
void CDynamicCursors::calculate() {
|
||||
static auto const* PMODE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MODE)->getDataStaticPtr();
|
||||
static auto* const* PTHRESHOLD = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_THRESHOLD)->getDataStaticPtr();
|
||||
|
||||
double angle = 0;
|
||||
if (!strcmp(*PMODE, "stick"))
|
||||
if (!strcmp(*PMODE, "rotate"))
|
||||
angle = calculateStick();
|
||||
else if (!strcmp(*PMODE, "air"))
|
||||
else if (!strcmp(*PMODE, "tilt"))
|
||||
angle = calculateAir();
|
||||
else
|
||||
Debug::log(WARN, "[dynamic-cursors] unknown mode specified");
|
||||
|
||||
// we only consider the angle changed if it is larger than 1 degree
|
||||
if (abs(this->angle - angle) > (PI / 180)) {
|
||||
if (abs(this->angle - angle) > ((PI / 180) * **PTHRESHOLD)) {
|
||||
this->angle = angle;
|
||||
|
||||
// damage software and change hardware cursor shape
|
||||
|
@ -291,9 +284,8 @@ double airFunction(double speed) {
|
|||
if (x > mass) result = 1; // need to clamp manually, as the function would decrease again
|
||||
|
||||
result *= (speed > 0 ? 1 : -1);
|
||||
} else {
|
||||
} else
|
||||
Debug::log(WARN, "[dynamic-cursors] unknown air function specified");
|
||||
}
|
||||
|
||||
return std::clamp(result, -1.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
#include <hyprland/src/plugins/PluginAPI.hpp>
|
||||
|
||||
#define CONFIG_ENABLED "plugin:dynamic-cursors:enabled"
|
||||
#define CONFIG_LENGTH "plugin:dynamic-cursors:length"
|
||||
#define CONFIG_MODE "plugin:dynamic-cursors:mode"
|
||||
#define CONFIG_MASS "plugin:dynamic-cursors:mass"
|
||||
#define CONFIG_FUNCTION "plugin:dynamic-cursors:function"
|
||||
#define CONFIG_ENABLED "plugin:dynamic-cursors:enabled"
|
||||
#define CONFIG_MODE "plugin:dynamic-cursors:mode"
|
||||
#define CONFIG_THRESHOLD "plugin:dynamic-cursors:threshold"
|
||||
#define CONFIG_LENGTH "plugin:dynamic-cursors:rotate:length"
|
||||
#define CONFIG_MASS "plugin:dynamic-cursors:tilt:limit"
|
||||
#define CONFIG_FUNCTION "plugin:dynamic-cursors:tilt:function"
|
||||
|
||||
#define CONFIG_HW_DEBUG "plugin:dynamic-cursors:hw_debug"
|
||||
|
||||
inline HANDLE PHANDLE = nullptr;
|
||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -108,12 +108,16 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
|||
wl_event_source_timer_update(tick, 1);
|
||||
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_ENABLED, Hyprlang::INT{1});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_MODE, Hyprlang::STRING{"air"});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_MODE, Hyprlang::STRING{"tilt"});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_THRESHOLD, Hyprlang::INT{2});
|
||||
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_FUNCTION, Hyprlang::STRING{"negative_quadratic"});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_LENGTH, Hyprlang::INT{20});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_HW_DEBUG, Hyprlang::INT{0});
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_MASS, Hyprlang::INT{5000});
|
||||
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_LENGTH, Hyprlang::INT{20});
|
||||
|
||||
HyprlandAPI::addConfigValue(PHANDLE, CONFIG_HW_DEBUG, Hyprlang::INT{0});
|
||||
|
||||
HyprlandAPI::reloadConfig();
|
||||
|
||||
return {"dynamic-cursors", "make your cursor more realistic", "Virt", "0.1"};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue