feat: unregister windows upon closing

This commit is contained in:
Matias 2025-07-16 22:00:42 +02:00
parent fd86b84cdf
commit d78fda606f
No known key found for this signature in database
GPG Key ID: ED35A6AC65A06B69

View File

@ -1,6 +1,7 @@
#include "globals.hpp" #include "globals.hpp"
#include <GLES3/gl32.h> #include <GLES3/gl32.h>
#include <any>
#include <cmath> #include <cmath>
#include <hyprgraphics/color/Color.hpp> #include <hyprgraphics/color/Color.hpp>
// version.hpp will be generated by meson // version.hpp will be generated by meson
@ -285,12 +286,16 @@ class CRenderWobblyWindowPassElement final: public IPassElement {
PHLWINDOWREF m_pWindow; PHLWINDOWREF m_pWindow;
}; };
// TODO: unregister on close
void registerWindow(PHLWINDOW pWindow) { void registerWindow(PHLWINDOW pWindow) {
g_windowPositions[pWindow] = pWindow->m_realPosition->value(); g_windowPositions[pWindow] = pWindow->m_realPosition->value();
} }
void unregisterWindow(PHLWINDOW pWindow) {
g_windowPositions.erase(PHLWINDOWREF {pWindow});
}
static SP<HOOK_CALLBACK_FN> g_openWindow = nullptr; static SP<HOOK_CALLBACK_FN> g_openWindow = nullptr;
static SP<HOOK_CALLBACK_FN> g_closeWindow = nullptr;
inline CFunctionHook* g_pRenderWindowHook = nullptr; inline CFunctionHook* g_pRenderWindowHook = nullptr;
typedef void (*origRenderWindow)( typedef void (*origRenderWindow)(
@ -518,6 +523,14 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
} }
); );
g_closeWindow = HyprlandAPI::registerCallbackDynamic(
PHANDLE,
"closeWindow",
[](void* self, SCallbackInfo& info, std::any data) {
unregisterWindow(std::any_cast<PHLWINDOW>(data));
}
);
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);