From 359a66967c631e53a233628d85aa6f08be4d9269 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Thu, 27 Jun 2024 20:24:37 +0200 Subject: [PATCH] fix: properly calculate shaking with rotate --- README.md | 8 ++++---- src/cursor.cpp | 16 ++++++++-------- src/cursor.hpp | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cdd5ae4..440d4d8 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ This plugin makes your cursor more realistic by simulating how it would behave i Why did I implement this again? -Inspired by KDE, it also supports shake to find, to enlarge the cursor when it is shaken so it is easier to find it. +Inspired by KDE, it also supports shake to find, to enlarge the cursor when it is shaken so it is easier to find it. It can be enabled separately or together with one simulation mode. -### behaviour modes +### simulation modes The plugin supports two different modes, `rotate` and `tilt`. They both are customizable and have a different base behaviour. #### `rotate` @@ -14,12 +14,12 @@ In this mode, the cursor is simulated as a stick which is dragged across the scr https://github.com/VirtCode/hypr-dynamic-cursor/assets/41426325/ccd6d742-8e2b-4073-a35e-318c7e19705c #### `tilt` -In this mode, the cursor is tilted based on the X direction and speed it is moving at. It was intended to simulate how an object would be affected by air drag, but implemented is only a rough approximation. This mode can also be customized extensively with different activation functions, and is enabled by default. +In this mode, the cursor is tilted based on the `x` direction and speed it is moving at. It was intended to simulate how an object would be affected by air drag, but implemented is only a rough approximation. This mode can also be customized extensively with different activation functions, and is enabled by default. https://github.com/VirtCode/hypr-dynamic-cursors/assets/41426325/ae25415c-e77f-4c85-864c-2eedbfe432e3 ### shake to find -The plugin supports shake to find, akin to how KDE Plasma, MacOS, etc. do it. It is enabled by default. +The plugin supports shake to find, akin to how KDE Plasma, MacOS, etc. do it. It can also be extensively configured and is enabled by default. If you only want shake to find, and no weird cursor behaviour, you can disable the above modes with the mode `none`. https://github.com/VirtCode/hypr-dynamic-cursors/assets/41426325/9ff64a9b-64e5-4595-b721-dcb4d62bee18 diff --git a/src/cursor.cpp b/src/cursor.cpp index 0fca0cd..dbdf658 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -223,7 +223,7 @@ void CDynamicCursors::onCursorMoved(CPointerManager* pointers) { } static auto const* PMODE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MODE)->getDataStaticPtr(); - if (!strcmp(*PMODE, "rotate")) calculate(); + if (!strcmp(*PMODE, "rotate")) calculate(false); } /* @@ -233,17 +233,19 @@ void CDynamicCursors::onTick(CPointerManager* pointers) { static auto const* PMODE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_MODE)->getDataStaticPtr(); static auto* const* PSHAKE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_SHAKE)->getDataStaticPtr(); - if (!strcmp(*PMODE, "tilt") || **PSHAKE) calculate(); + if (!strcmp(*PMODE, "tilt") || **PSHAKE) calculate(true); } -void CDynamicCursors::calculate() { +void CDynamicCursors::calculate(bool tick) { 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(); static auto* const* PSHAKE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_SHAKE)->getDataStaticPtr(); static auto* const* PSHAKE_EFFECTS = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_SHAKE_EFFECTS)->getDataStaticPtr(); - double zoom = 1; - if (**PSHAKE) + // only calculate zoom on tick + // yes, a refactor of this whole file would be a godsent + double zoom = tick ? 1 : this->zoom; + if (**PSHAKE && tick) zoom = calculateShake(); double angle = 0; @@ -272,7 +274,7 @@ void CDynamicCursors::calculate() { } } - // we only consider the angle changed if it is larger than 1 degree + // we only consider the angle changed if it is larger than the threshold if (abs(this->angle - angle) > ((PI / 180) * **PTHRESHOLD) || abs(this->zoom - zoom) > 0.1 || (zoom == 1 && this->zoom != 1)) { this->angle = angle; this->zoom = zoom; @@ -373,8 +375,6 @@ double CDynamicCursors::calculateShake() { // discard when the diagonal is small, so we don't have issues with inaccuracies if (diagonal < 100) return 1.0; - std::cout << trail << " " << diagonal << " " << (trail / diagonal) << "\n"; - return std::max(1.0, ((trail / diagonal) - **PTHRESHOLD) * **PFACTOR); } diff --git a/src/cursor.hpp b/src/cursor.hpp index 937da91..571c081 100644 --- a/src/cursor.hpp +++ b/src/cursor.hpp @@ -31,7 +31,7 @@ class CDynamicCursors { bool software = false; // calculates the current angle of the cursor, and changes the cursor shape - void calculate(); + void calculate(bool tick); // calculate the angle of the cursor if stick double calculateStick();