Author SHA1 Message Date
zach 9d8bde1413 fix: update for hyprland 0.57 2026-10-29 11:59:50 +01:00
+20 -53
View File
@@ -14,9 +14,10 @@
#include <hyprland/src/plugins/PluginAPI.hpp> #include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/render/OpenGL.hpp> #include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/render/Renderer.hpp> #include <hyprland/src/render/Renderer.hpp>
#include <hyprland/src/render/Context.hpp>
#undef private #undef private
#include <hyprland/src/managers/EventManager.hpp> #include <hyprland/src/ipc/s2/S2.hpp>
extern "C" { extern "C" {
#include <lua.h> #include <lua.h>
@@ -27,6 +28,7 @@ extern "C" {
using ZShell::services::kelvinToGain; using ZShell::services::kelvinToGain;
using Render::CRenderContext;
using Render::IFramebuffer; using Render::IFramebuffer;
using Render::GL::CHyprOpenGLImpl; using Render::GL::CHyprOpenGLImpl;
using Render::GL::g_pHyprOpenGL; using Render::GL::g_pHyprOpenGL;
@@ -149,25 +151,14 @@ static bool gainIsNeutral(const std::array<float, 3>& gain) {
} }
static CFunctionHook* g_pBeginHook = nullptr; static CFunctionHook* g_pBeginHook = nullptr;
using origBegin = void (*)( using origBegin = bool (*)(
CHyprOpenGLImpl*, CHyprOpenGLImpl*,
CRenderContext&,
PHLMONITOR, PHLMONITOR,
const CRegion&, const CRegion&,
SP<IFramebuffer>, SP<IFramebuffer>,
std::optional<CRegion>); std::optional<CRegion>);
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<origSaveMirror>(
g_pSaveMirrorHook->m_original))(thisptr, box);
thisptr->m_applyFinalShader = saved;
return result;
}
static void installShader() { static void installShader() {
auto* gl = g_pHyprOpenGL.get(); auto* gl = g_pHyprOpenGL.get();
if (!gl) return; if (!gl) return;
@@ -198,34 +189,33 @@ static void setUniformGain(const std::array<float, 3>& gain) {
shader->setUniformFloat3(SHADER_TINT, gain[0], gain[1], gain[2]); shader->setUniformFloat3(SHADER_TINT, gain[0], gain[1], gain[2]);
} }
static void hkBegin( static bool hkBegin(
CHyprOpenGLImpl* thisptr, CHyprOpenGLImpl* thisptr,
CRenderContext& ctx,
PHLMONITOR mon, PHLMONITOR mon,
const CRegion& damage, const CRegion& damage,
SP<IFramebuffer> fb, SP<IFramebuffer> fb,
std::optional<CRegion> finalDamage) { std::optional<CRegion> finalDamage) {
(*reinterpret_cast<origBegin>( const bool ok = (*reinterpret_cast<origBegin>(
g_pBeginHook->m_original))(thisptr, mon, damage, fb, finalDamage); g_pBeginHook->m_original))(thisptr, ctx, mon, damage, fb, finalDamage);
if (!ok) return false;
if (fb) { if (fb) ctx.m_data.blockScreenShader = true;
auto* renderer = g_pHyprRenderer.get();
if (renderer) renderer->m_renderData.blockScreenShader = true;
}
if (!g_active) return; if (!g_active) return true;
auto* gl = g_pHyprOpenGL.get(); auto* gl = g_pHyprOpenGL.get();
if (!gl) return; if (!gl) return true;
if (gl->m_finalScreenShader.get() && gl->m_finalScreenShader->program() < 1) if (gl->m_finalScreenShader.get() && gl->m_finalScreenShader->program() < 1)
installShader(); installShader();
if (!gl->m_finalScreenShader.get() || if (!gl->m_finalScreenShader.get() ||
gl->m_finalScreenShader->program() < 1) gl->m_finalScreenShader->program() < 1)
return; return true;
if (g_transition.active) { if (g_transition.active) {
auto* monPtr = mon.get(); auto* monPtr = mon.get();
if (!monPtr) return; if (!monPtr) return true;
const float elapsed = const float elapsed =
std::chrono::duration<float>( std::chrono::duration<float>(
std::chrono::steady_clock::now() - g_transition.start) std::chrono::steady_clock::now() - g_transition.start)
@@ -265,6 +255,7 @@ static void hkBegin(
} else if (g_uniformMode) { } else if (g_uniformMode) {
setUniformGain(g_currentGain); setUniformGain(g_currentGain);
} }
return true;
} }
static constexpr int KELVIN_MIN = 2000; static constexpr int KELVIN_MIN = 2000;
@@ -333,9 +324,10 @@ static int luaNightlightState(lua_State* L) {
} }
static void postStateEvent(bool enabled, bool animating) { static void postStateEvent(bool enabled, bool animating) {
if (!g_pEventManager) return; auto& sock = IPC::Socket2::sock();
g_pEventManager->postEvent( if (!sock) return;
SHyprIPCEvent{ sock->postEvent(
IPC::Socket2::SEvent{
.event = "zshell-nightlight", .event = "zshell-nightlight",
.data = std::format( .data = std::format(
"{},{},{},{}", "{},{},{},{}",
@@ -377,31 +369,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
throw std::runtime_error("[zshell-nightlight] version mismatch"); 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<void*>(&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 = static const auto METHODS =
HyprlandAPI::findFunctionsByName(PHANDLE, "begin"); HyprlandAPI::findFunctionsByName(PHANDLE, "begin");
const SFunctionMatch* target = const SFunctionMatch* target =