From 1ae25556a171bc3a205c13ba4c305919869df93d Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Mon, 4 Nov 2024 20:34:17 +0100 Subject: [PATCH] fix: only update if hyprland is done initializing We check whether the most hz monitor is non-null, as a measure to whether hyprland is intialized. This is nessecary as plugins loaded with `plugin =` otherwise cause a ton of weird crashes. --- src/config/config.cpp | 7 +++++++ src/config/config.hpp | 3 +++ src/cursor.cpp | 4 +--- src/main.cpp | 5 ----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index 664e128..1c3403b 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -1,10 +1,17 @@ #include "../globals.hpp" +#include "../cursor.hpp" +#include "src/render/Renderer.hpp" #include "config.hpp" #include #include #include #include +bool isEnabled() { + static auto* const* PENABLED = (Hyprlang::INT* const*) getConfig(CONFIG_ENABLED); + return **PENABLED && g_pHyprRenderer->m_pMostHzMonitor && g_pDynamicCursors; // make sure the compositor is properly initialized +} + Hyprlang::CConfigValue toHyprlang(std::variant value) { if (std::holds_alternative(value)) diff --git a/src/config/config.hpp b/src/config/config.hpp index 95f07ad..e9e955e 100644 --- a/src/config/config.hpp +++ b/src/config/config.hpp @@ -33,6 +33,9 @@ #define CONFIG_SHAPERULE "shaperule" +/* is the plugin enabled */ +bool isEnabled(); + /* initializes stuff so config can be set up */ void startConfig(); /* finishes config setup */ diff --git a/src/cursor.cpp b/src/cursor.cpp index dc9ac61..c853c2f 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -24,9 +24,7 @@ #include "renderer.hpp" void tickRaw(SP self, void* data) { - static auto* const* PENABLED = (Hyprlang::INT* const*) getConfig(CONFIG_ENABLED); - - if (**PENABLED && g_pDynamicCursors) + if (isEnabled()) g_pDynamicCursors->onTick(g_pPointerManager.get()); const int TIMEOUT = g_pHyprRenderer->m_pMostHzMonitor ? 1000.0 / g_pHyprRenderer->m_pMostHzMonitor->refreshRate : 16; diff --git a/src/main.cpp b/src/main.cpp index 593f480..97dc886 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,11 +13,6 @@ #include "src/managers/PointerManager.hpp" #include "src/version.h" -bool isEnabled() { - static auto* const* PENABLED = (Hyprlang::INT* const*) getConfig(CONFIG_ENABLED); - return **PENABLED; -} - typedef void (*origRenderSofwareCursorsFor)(void*, SP, timespec*, CRegion&, std::optional); inline CFunctionHook* g_pRenderSoftwareCursorsForHook = nullptr; void hkRenderSoftwareCursorsFor(void* thisptr, SP pMonitor, timespec* now, CRegion& damage, std::optional overridePos) {