mirror of
https://git.allpurposem.at/mat/WiggleWobble.git
synced 2025-12-23 21:11:29 +01:00
feat: move to tick callback
This commit is contained in:
parent
e0475aa880
commit
1b7edd84f3
25
src/main.cpp
25
src/main.cpp
@ -4,6 +4,7 @@
|
|||||||
#include "wobblywindow.h"
|
#include "wobblywindow.h"
|
||||||
|
|
||||||
#include <any>
|
#include <any>
|
||||||
|
#include <hyprland/src/helpers/time/Time.hpp>
|
||||||
#include <hyprland/src/managers/input/InputManager.hpp>
|
#include <hyprland/src/managers/input/InputManager.hpp>
|
||||||
#include <hyprland/src/render/Renderer.hpp>
|
#include <hyprland/src/render/Renderer.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -25,8 +26,18 @@ void unregisterWindow(PHLWINDOW pWindow) {
|
|||||||
g_windowPositions.erase(PHLWINDOWREF {pWindow});
|
g_windowPositions.erase(PHLWINDOWREF {pWindow});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tick() {
|
||||||
|
const auto now = Time::steadyNow();
|
||||||
|
std::erase_if(g_wobblyWindows, [&now](auto&& wobble) {
|
||||||
|
const bool shouldErase = wobble.second.step(now);
|
||||||
|
|
||||||
|
return shouldErase;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static SP<HOOK_CALLBACK_FN> g_openWindow = nullptr;
|
static SP<HOOK_CALLBACK_FN> g_openWindow = nullptr;
|
||||||
static SP<HOOK_CALLBACK_FN> g_closeWindow = nullptr;
|
static SP<HOOK_CALLBACK_FN> g_closeWindow = nullptr;
|
||||||
|
static SP<HOOK_CALLBACK_FN> g_tick = nullptr;
|
||||||
inline CFunctionHook* g_pRenderWindowHook = nullptr;
|
inline CFunctionHook* g_pRenderWindowHook = nullptr;
|
||||||
|
|
||||||
typedef void (*origRenderWindow)(
|
typedef void (*origRenderWindow)(
|
||||||
@ -119,12 +130,6 @@ void hkRenderWindow(
|
|||||||
if (shouldWobble) {
|
if (shouldWobble) {
|
||||||
pWindow->m_floatingOffset += Vector2D {windowBox.x, windowBox.y};
|
pWindow->m_floatingOffset += Vector2D {windowBox.x, windowBox.y};
|
||||||
|
|
||||||
std::erase_if(g_wobblyWindows, [&](auto&& wobble) {
|
|
||||||
const bool shouldErase = g_wobblyWindows[pWindow].step(time);
|
|
||||||
|
|
||||||
return shouldErase;
|
|
||||||
});
|
|
||||||
|
|
||||||
pRenderer->m_renderPass.add(
|
pRenderer->m_renderPass.add(
|
||||||
makeUnique<CRenderWobblyWindowPassElement>(pOldFramebuffer, pWindow)
|
makeUnique<CRenderWobblyWindowPassElement>(pOldFramebuffer, pWindow)
|
||||||
);
|
);
|
||||||
@ -169,6 +174,12 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
g_tick = HyprlandAPI::registerCallbackDynamic(
|
||||||
|
PHANDLE,
|
||||||
|
"tick",
|
||||||
|
[](void* self, SCallbackInfo& info, std::any data) { tick(); }
|
||||||
|
);
|
||||||
|
|
||||||
static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "renderWindow");
|
static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "renderWindow");
|
||||||
g_pRenderWindowHook =
|
g_pRenderWindowHook =
|
||||||
HyprlandAPI::createFunctionHook(handle, METHODS[0].address, (void*)&hkRenderWindow);
|
HyprlandAPI::createFunctionHook(handle, METHODS[0].address, (void*)&hkRenderWindow);
|
||||||
@ -190,4 +201,6 @@ APICALL EXPORT void PLUGIN_EXIT() {
|
|||||||
CRenderWobblyWindowPassElement::deinitGPUObjects();
|
CRenderWobblyWindowPassElement::deinitGPUObjects();
|
||||||
g_pRenderWindowHook = nullptr;
|
g_pRenderWindowHook = nullptr;
|
||||||
g_openWindow = nullptr;
|
g_openWindow = nullptr;
|
||||||
|
g_closeWindow = nullptr;
|
||||||
|
g_tick = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user