diff --git a/src/main.cpp b/src/main.cpp index 5d92967..8bce790 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,9 +4,12 @@ #include "wobblywindow.h" #include +#include #include #include +#include #include +#include #include // Do NOT change this function. @@ -23,13 +26,29 @@ void registerWindow(PHLWINDOW pWindow) { } void unregisterWindow(PHLWINDOW pWindow) { - g_windowPositions.erase(PHLWINDOWREF {pWindow}); + const auto winref = PHLWINDOWREF {pWindow}; + + g_windowPositions.erase(winref); + g_windowFramebuffers.erase(winref); + g_wobblyWindows.erase(winref); } void tick() { const auto now = Time::steadyNow(); - std::erase_if(g_wobblyWindows, [&now](auto&& wobble) { - const bool shouldErase = wobble.second.step(now); + std::erase_if(g_wobblyWindows, [&now](auto&& element) { + auto&& [window, wobble] = element; + + const bool shouldErase = window->m_fadingOut or wobble.step(now); + + const CBox windowBox = window->getFullWindowBoundingBox(); + const CBox wobbleBox = wobble.getBox(); + + g_pHyprRenderer->damageBox(CBox( + windowBox.x + windowBox.width * wobbleBox.x, + windowBox.y + windowBox.height * wobbleBox.y, + windowBox.width * wobbleBox.width, + windowBox.height * wobbleBox.height + )); return shouldErase; }); @@ -68,6 +87,11 @@ void hkRenderWindow( return false; } + // window is closing + if (pWindow->m_fadingOut) { + return false; + } + // did the window move if (const auto pos = pWindow->m_realPosition->value(); pos != g_windowPositions[pWindow]) { auto&& wobble = g_wobblyWindows[pWindow]; @@ -97,9 +121,6 @@ void hkRenderWindow( const auto windowBox = pWindow->getFullWindowBoundingBox(); if (shouldWobble) { - // HACK: this should only damage the wobbly bbox - // g_pHyprRenderer->damageMonitor(g_pHyprOpenGL->m_renderData.pMonitor.lock()); - PHLWINDOWREF ref {pWindow}; // create it if not exists @@ -180,10 +201,12 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { [](void* self, SCallbackInfo& info, std::any data) { tick(); } ); - static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "renderWindow"); - g_pRenderWindowHook = - HyprlandAPI::createFunctionHook(handle, METHODS[0].address, (void*)&hkRenderWindow); - g_pRenderWindowHook->hook(); + { + static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "renderWindow"); + g_pRenderWindowHook = + HyprlandAPI::createFunctionHook(handle, METHODS[0].address, (void*)&hkRenderWindow); + g_pRenderWindowHook->hook(); + } HyprlandAPI::reloadConfig(); @@ -193,7 +216,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { APICALL EXPORT void PLUGIN_EXIT() { CRenderWobblyWindowPassElement::deinitGPUObjects(); g_pRenderWindowHook = nullptr; - g_openWindow = nullptr; g_closeWindow = nullptr; + g_openWindow = nullptr; g_tick = nullptr; }