From 9d8bde1413aa1a4055ec2eab45bfe5b47b1eb3c6 Mon Sep 17 00:00:00 2001 From: zach Date: Thu, 29 Oct 2026 11:59:50 +0100 Subject: [PATCH] fix: update for hyprland 0.57 --- Plugins/ZShell/HyprPlugins/main.cpp | 73 ++++++++--------------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/Plugins/ZShell/HyprPlugins/main.cpp b/Plugins/ZShell/HyprPlugins/main.cpp index 8e8f2e4..c7d96cb 100644 --- a/Plugins/ZShell/HyprPlugins/main.cpp +++ b/Plugins/ZShell/HyprPlugins/main.cpp @@ -14,9 +14,10 @@ #include #include #include +#include #undef private -#include +#include extern "C" { #include @@ -27,6 +28,7 @@ extern "C" { using ZShell::services::kelvinToGain; +using Render::CRenderContext; using Render::IFramebuffer; using Render::GL::CHyprOpenGLImpl; using Render::GL::g_pHyprOpenGL; @@ -149,25 +151,14 @@ static bool gainIsNeutral(const std::array& gain) { } static CFunctionHook* g_pBeginHook = nullptr; -using origBegin = void (*)( +using origBegin = bool (*)( CHyprOpenGLImpl*, + CRenderContext&, PHLMONITOR, const CRegion&, SP, std::optional); -static CFunctionHook* g_pSaveMirrorHook = nullptr; -using origSaveMirror = bool (*)(CHyprOpenGLImpl*, const CBox&); - -static bool hkSaveBufferForMirror(CHyprOpenGLImpl* thisptr, const CBox& box) { - const bool saved = thisptr->m_applyFinalShader; - thisptr->m_applyFinalShader = false; - const bool result = (*reinterpret_cast( - g_pSaveMirrorHook->m_original))(thisptr, box); - thisptr->m_applyFinalShader = saved; - return result; -} - static void installShader() { auto* gl = g_pHyprOpenGL.get(); if (!gl) return; @@ -198,34 +189,33 @@ static void setUniformGain(const std::array& gain) { shader->setUniformFloat3(SHADER_TINT, gain[0], gain[1], gain[2]); } -static void hkBegin( +static bool hkBegin( CHyprOpenGLImpl* thisptr, + CRenderContext& ctx, PHLMONITOR mon, const CRegion& damage, SP fb, std::optional finalDamage) { - (*reinterpret_cast( - g_pBeginHook->m_original))(thisptr, mon, damage, fb, finalDamage); + const bool ok = (*reinterpret_cast( + g_pBeginHook->m_original))(thisptr, ctx, mon, damage, fb, finalDamage); + if (!ok) return false; - if (fb) { - auto* renderer = g_pHyprRenderer.get(); - if (renderer) renderer->m_renderData.blockScreenShader = true; - } + if (fb) ctx.m_data.blockScreenShader = true; - if (!g_active) return; + if (!g_active) return true; auto* gl = g_pHyprOpenGL.get(); - if (!gl) return; + if (!gl) return true; if (gl->m_finalScreenShader.get() && gl->m_finalScreenShader->program() < 1) installShader(); if (!gl->m_finalScreenShader.get() || gl->m_finalScreenShader->program() < 1) - return; + return true; if (g_transition.active) { auto* monPtr = mon.get(); - if (!monPtr) return; + if (!monPtr) return true; const float elapsed = std::chrono::duration( std::chrono::steady_clock::now() - g_transition.start) @@ -265,6 +255,7 @@ static void hkBegin( } else if (g_uniformMode) { setUniformGain(g_currentGain); } + return true; } static constexpr int KELVIN_MIN = 2000; @@ -333,9 +324,10 @@ static int luaNightlightState(lua_State* L) { } static void postStateEvent(bool enabled, bool animating) { - if (!g_pEventManager) return; - g_pEventManager->postEvent( - SHyprIPCEvent{ + auto& sock = IPC::Socket2::sock(); + if (!sock) return; + sock->postEvent( + IPC::Socket2::SEvent{ .event = "zshell-nightlight", .data = std::format( "{},{},{},{}", @@ -377,31 +369,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { throw std::runtime_error("[zshell-nightlight] version mismatch"); } - static const auto SAVEMIRROR_METHODS = - HyprlandAPI::findFunctionsByName(PHANDLE, "saveBufferForMirror"); - const SFunctionMatch* saveMirrorTarget = findExactMethod( - SAVEMIRROR_METHODS, - manglePrefix("CHyprOpenGLImpl", "saveBufferForMirror")); - - if (saveMirrorTarget) { - g_pSaveMirrorHook = HyprlandAPI::createFunctionHook( - PHANDLE, - saveMirrorTarget->address, - reinterpret_cast(&hkSaveBufferForMirror)); - if (g_pSaveMirrorHook && g_pSaveMirrorHook->hook()) - dlog( - "saveBufferForMirror hook installed: " + - saveMirrorTarget->signature); - } - - if (!g_pSaveMirrorHook) - HyprlandAPI::addNotification( - PHANDLE, - "[zshell-nightlight] WARNING: couldn't hook saveBufferForMirror — " - "captures may still show the nightlight", - CHyprColor{1.f, 0.6f, 0.2f, 1.f}, - 8000); - static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "begin"); const SFunctionMatch* target =