Compare commits
4
Commits
118b8f482a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90184bff58 | ||
|
|
abdde2450d | ||
|
|
fd05b3d4c4 | ||
|
|
9d8bde1413 |
@@ -14,9 +14,10 @@
|
||||
#include <hyprland/src/plugins/PluginAPI.hpp>
|
||||
#include <hyprland/src/render/OpenGL.hpp>
|
||||
#include <hyprland/src/render/Renderer.hpp>
|
||||
#include <hyprland/src/render/Context.hpp>
|
||||
#undef private
|
||||
|
||||
#include <hyprland/src/managers/EventManager.hpp>
|
||||
#include <hyprland/src/ipc/s2/S2.hpp>
|
||||
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
@@ -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<float, 3>& gain) {
|
||||
}
|
||||
|
||||
static CFunctionHook* g_pBeginHook = nullptr;
|
||||
using origBegin = void (*)(
|
||||
using origBegin = bool (*)(
|
||||
CHyprOpenGLImpl*,
|
||||
CRenderContext&,
|
||||
PHLMONITOR,
|
||||
const CRegion&,
|
||||
SP<IFramebuffer>,
|
||||
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() {
|
||||
auto* gl = g_pHyprOpenGL.get();
|
||||
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]);
|
||||
}
|
||||
|
||||
static void hkBegin(
|
||||
static bool hkBegin(
|
||||
CHyprOpenGLImpl* thisptr,
|
||||
CRenderContext& ctx,
|
||||
PHLMONITOR mon,
|
||||
const CRegion& damage,
|
||||
SP<IFramebuffer> fb,
|
||||
std::optional<CRegion> finalDamage) {
|
||||
(*reinterpret_cast<origBegin>(
|
||||
g_pBeginHook->m_original))(thisptr, mon, damage, fb, finalDamage);
|
||||
const bool ok = (*reinterpret_cast<origBegin>(
|
||||
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<float>(
|
||||
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<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 =
|
||||
HyprlandAPI::findFunctionsByName(PHANDLE, "begin");
|
||||
const SFunctionMatch* target =
|
||||
|
||||
@@ -545,7 +545,7 @@ def generate(
|
||||
except (PermissionError, OSError, BlockingIOError):
|
||||
pass
|
||||
|
||||
def smart_mode(image_path: Path) -> str:
|
||||
def smart_mode(image_path: Path | io.BytesIO) -> str:
|
||||
is_dark = ""
|
||||
|
||||
with Image.open(image_path) as img:
|
||||
@@ -739,7 +739,7 @@ def generate(
|
||||
|
||||
return rendered_outputs
|
||||
|
||||
def seed_from_image(image_path: Path) -> Hct:
|
||||
def seed_from_image(image_path: Path | io.BytesIO) -> Hct:
|
||||
image = Image.open(image_path)
|
||||
pixel_len = image.width * image.height
|
||||
image_data = image.getdata()
|
||||
@@ -837,11 +837,13 @@ def generate(
|
||||
image_path = image_path or Path(WALL_PATH)
|
||||
|
||||
blob = scheme_thumb_from_db(str(DB_PATH), str(image_path))
|
||||
if blob is not None:
|
||||
open_thumb = lambda: io.BytesIO(blob)
|
||||
else:
|
||||
thumb_path = generate_thumbnail(image_path, THUMB_DIR)
|
||||
open_thumb = lambda: thumb_path
|
||||
|
||||
def open_thumb():
|
||||
if blob is not None:
|
||||
return io.BytesIO(blob)
|
||||
else:
|
||||
thumb_path = generate_thumbnail(image_path, THUMB_DIR)
|
||||
return thumb_path
|
||||
|
||||
seed = seed_from_image(open_thumb())
|
||||
name = "dynamic"
|
||||
|
||||
Reference in New Issue
Block a user