all: chase hyprland

fixes #87
This commit is contained in:
Vaxry 2024-03-01 13:44:29 +00:00
parent f99822818e
commit 755e47790c
2 changed files with 18 additions and 14 deletions

View file

@ -65,8 +65,8 @@ void hkSurfaceDamage(wlr_surface* surface, pixman_region32_t* damage) {
const auto SURF = CWLSurface::surfaceFromWlr(surface); const auto SURF = CWLSurface::surfaceFromWlr(surface);
if (SURF && SURF->exists() && SURF->m_pOwner && SURF->m_pOwner->m_szInitialClass == *PCLASS) if (SURF && SURF->exists() && SURF->getWindow() && SURF->getWindow()->m_szInitialClass == *PCLASS)
g_pHyprRenderer->damageWindow(SURF->m_pOwner); g_pHyprRenderer->damageWindow(SURF->getWindow());
} }
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {

View file

@ -21,9 +21,9 @@ APICALL EXPORT std::string PLUGIN_API_VERSION() {
} }
// hooks // hooks
inline CFunctionHook* damageHook = nullptr; inline CFunctionHook* subsurfaceHook = nullptr;
inline CFunctionHook* commitHook = nullptr; inline CFunctionHook* commitHook = nullptr;
typedef void (*origDamage)(void* owner, void* data); typedef void (*origCommitSubsurface)(CSubsurface* thisptr);
typedef void (*origCommit)(void* owner, void* data); typedef void (*origCommit)(void* owner, void* data);
std::vector<CWindow*> bgWindows; std::vector<CWindow*> bgWindows;
@ -85,18 +85,18 @@ void onRenderStage(eRenderStage stage) {
} }
} }
void onDamage(void* owner, void* data) { void onCommitSubsurface(CSubsurface* thisptr) {
const auto PWINDOW = (CWindow*)owner; const auto PWINDOW = thisptr->m_sWLSurface.getWindow();
if (std::find(bgWindows.begin(), bgWindows.end(), PWINDOW) == bgWindows.end()) { if (!PWINDOW || std::find(bgWindows.begin(), bgWindows.end(), PWINDOW) == bgWindows.end()) {
((origDamage)damageHook->m_pOriginal)(owner, data); ((origCommitSubsurface)subsurfaceHook->m_pOriginal)(thisptr);
return; return;
} }
// cant use setHidden cuz that sends suspended and shit too that would be laggy // cant use setHidden cuz that sends suspended and shit too that would be laggy
PWINDOW->m_bHidden = false; PWINDOW->m_bHidden = false;
((origDamage)damageHook->m_pOriginal)(owner, data); ((origCommitSubsurface)subsurfaceHook->m_pOriginal)(thisptr);
PWINDOW->m_bHidden = true; PWINDOW->m_bHidden = true;
} }
@ -139,17 +139,21 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::registerCallbackDynamic(PHANDLE, "render", [&](void* self, SCallbackInfo& info, std::any data) { onRenderStage(std::any_cast<eRenderStage>(data)); }); HyprlandAPI::registerCallbackDynamic(PHANDLE, "render", [&](void* self, SCallbackInfo& info, std::any data) { onRenderStage(std::any_cast<eRenderStage>(data)); });
HyprlandAPI::registerCallbackDynamic(PHANDLE, "configReloaded", [&](void* self, SCallbackInfo& info, std::any data) { onConfigReloaded(); }); HyprlandAPI::registerCallbackDynamic(PHANDLE, "configReloaded", [&](void* self, SCallbackInfo& info, std::any data) { onConfigReloaded(); });
auto fns = HyprlandAPI::findFunctionsByName(PHANDLE, "listener_commitSubsurface"); auto fns = HyprlandAPI::findFunctionsByName(PHANDLE, "onCommit");
if (fns.size() < 1) if (fns.size() < 1)
throw std::runtime_error("hyprwinwrap: listener_commitSubsurface not found"); throw std::runtime_error("hyprwinwrap: onCommit not found");
damageHook = HyprlandAPI::createFunctionHook(PHANDLE, fns[0].address, (void*)&onDamage); for (auto& fn : fns) {
if (!fn.demangled.contains("CSubsurface"))
continue;
subsurfaceHook = HyprlandAPI::createFunctionHook(PHANDLE, fns[0].address, (void*)&onCommitSubsurface);
}
fns = HyprlandAPI::findFunctionsByName(PHANDLE, "listener_commitWindow"); fns = HyprlandAPI::findFunctionsByName(PHANDLE, "listener_commitWindow");
if (fns.size() < 1) if (fns.size() < 1)
throw std::runtime_error("hyprwinwrap: listener_commitWindow not found"); throw std::runtime_error("hyprwinwrap: listener_commitWindow not found");
commitHook = HyprlandAPI::createFunctionHook(PHANDLE, fns[0].address, (void*)&onCommit); commitHook = HyprlandAPI::createFunctionHook(PHANDLE, fns[0].address, (void*)&onCommit);
bool hkResult = damageHook->hook(); bool hkResult = subsurfaceHook->hook();
hkResult = hkResult && commitHook->hook(); hkResult = hkResult && commitHook->hook();
if (!hkResult) if (!hkResult)