mirror of
https://git.allpurposem.at/mat/WiggleWobble.git
synced 2025-12-23 13:01:28 +01:00
fix: switch to own ticking system
This commit is contained in:
parent
aae62208d6
commit
1351590ece
73
src/main.cpp
73
src/main.cpp
@ -6,6 +6,7 @@
|
|||||||
#include <any>
|
#include <any>
|
||||||
#include <hyprland/src/Compositor.hpp>
|
#include <hyprland/src/Compositor.hpp>
|
||||||
#include <hyprland/src/helpers/time/Time.hpp>
|
#include <hyprland/src/helpers/time/Time.hpp>
|
||||||
|
#include <hyprland/src/managers/eventLoop/EventLoopManager.hpp>
|
||||||
#include <hyprland/src/managers/input/InputManager.hpp>
|
#include <hyprland/src/managers/input/InputManager.hpp>
|
||||||
#include <hyprland/src/plugins/HookSystem.hpp>
|
#include <hyprland/src/plugins/HookSystem.hpp>
|
||||||
#include <hyprland/src/render/Renderer.hpp>
|
#include <hyprland/src/render/Renderer.hpp>
|
||||||
@ -33,25 +34,65 @@ void unregisterWindow(PHLWINDOW pWindow) {
|
|||||||
g_wobblyWindows.erase(winref);
|
g_wobblyWindows.erase(winref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick() {
|
SP<CEventLoopTimer> g_wobbleTickTimer;
|
||||||
|
bool g_tickScheduled = false;
|
||||||
|
|
||||||
|
void scheduleTick() {
|
||||||
|
if (g_tickScheduled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_tickScheduled = true;
|
||||||
|
|
||||||
|
const auto PMOSTHZ = g_pHyprRenderer->m_mostHzMonitor;
|
||||||
|
|
||||||
|
if (!PMOSTHZ) {
|
||||||
|
g_wobbleTickTimer->updateTimeout(std::chrono::milliseconds(16));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float refreshDelayMs = std::floor(1000.f / PMOSTHZ->m_refreshRate);
|
||||||
|
|
||||||
|
const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||||
|
Time::steadyNow() - PMOSTHZ->m_lastPresentationTimer.chrono()
|
||||||
|
)
|
||||||
|
.count()
|
||||||
|
/ 1000.F;
|
||||||
|
|
||||||
|
const auto TOPRES = std::clamp(
|
||||||
|
refreshDelayMs - SINCEPRES,
|
||||||
|
1.1f,
|
||||||
|
1000.f
|
||||||
|
); // we can't send 0, that will disarm it
|
||||||
|
|
||||||
|
g_wobbleTickTimer->updateTimeout(std::chrono::milliseconds((int)std::floor(TOPRES)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick(SP<CEventLoopTimer> self, void* data) {
|
||||||
|
g_tickScheduled = false;
|
||||||
|
|
||||||
const auto now = Time::steadyNow();
|
const auto now = Time::steadyNow();
|
||||||
std::erase_if(g_wobblyWindows, [&now](auto&& element) {
|
std::erase_if(g_wobblyWindows, [&now](auto&& element) {
|
||||||
auto&& [window, wobble] = element;
|
auto&& [window, wobble] = element;
|
||||||
|
|
||||||
const bool shouldErase = window->m_fadingOut or wobble.step(now);
|
const bool shouldErase = window->m_fadingOut or wobble.step(now);
|
||||||
|
|
||||||
const CBox windowBox = window->getFullWindowBoundingBox();
|
if (not shouldErase) {
|
||||||
const CBox wobbleBox = wobble.getBox();
|
const CBox windowBox = window->getFullWindowBoundingBox();
|
||||||
|
const CBox wobbleBox = wobble.getBox();
|
||||||
|
|
||||||
g_pHyprRenderer->damageBox(CBox(
|
g_pHyprRenderer->damageBox(CBox(
|
||||||
windowBox.x + windowBox.width * wobbleBox.x,
|
windowBox.x + windowBox.width * wobbleBox.x,
|
||||||
windowBox.y + windowBox.height * wobbleBox.y,
|
windowBox.y + windowBox.height * wobbleBox.y,
|
||||||
windowBox.width * wobbleBox.width,
|
windowBox.width * wobbleBox.width,
|
||||||
windowBox.height * wobbleBox.height
|
windowBox.height * wobbleBox.height
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
return shouldErase;
|
return shouldErase;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (not g_wobblyWindows.empty())
|
||||||
|
scheduleTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
static SP<HOOK_CALLBACK_FN> g_openWindow = nullptr;
|
static SP<HOOK_CALLBACK_FN> g_openWindow = nullptr;
|
||||||
@ -121,6 +162,9 @@ void hkRenderWindow(
|
|||||||
const auto windowBox = pWindow->getFullWindowBoundingBox();
|
const auto windowBox = pWindow->getFullWindowBoundingBox();
|
||||||
|
|
||||||
if (shouldWobble) {
|
if (shouldWobble) {
|
||||||
|
if (not g_tickScheduled)
|
||||||
|
scheduleTick();
|
||||||
|
|
||||||
PHLWINDOWREF ref {pWindow};
|
PHLWINDOWREF ref {pWindow};
|
||||||
|
|
||||||
// create it if not exists
|
// create it if not exists
|
||||||
@ -195,11 +239,9 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
g_tick = HyprlandAPI::registerCallbackDynamic(
|
g_wobbleTickTimer =
|
||||||
PHANDLE,
|
SP<CEventLoopTimer>(new CEventLoopTimer(std::chrono::microseconds(500), tick, nullptr));
|
||||||
"tick",
|
g_pEventLoopManager->addTimer(g_wobbleTickTimer);
|
||||||
[](void* self, SCallbackInfo& info, std::any data) { tick(); }
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "renderWindow");
|
static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "renderWindow");
|
||||||
@ -218,5 +260,6 @@ APICALL EXPORT void PLUGIN_EXIT() {
|
|||||||
g_pRenderWindowHook = nullptr;
|
g_pRenderWindowHook = nullptr;
|
||||||
g_closeWindow = nullptr;
|
g_closeWindow = nullptr;
|
||||||
g_openWindow = nullptr;
|
g_openWindow = nullptr;
|
||||||
g_tick = nullptr;
|
|
||||||
|
g_pEventLoopManager->removeTimer(g_wobbleTickTimer);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user