ae011bbd0732dc7b2afba9a775cb9bb9a043c77e

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

replace SelectionHook with layout render hints

Diff

  1diff --git a/CMakeLists.txt b/CMakeLists.txt
  2index 12d2a4b0c5818b99a402a945ec4ae3db9eb4787c..83b0bbdb494dcdd07197679d2bc2d573849b9ac2 100644
  3--- a/CMakeLists.txt
  4+++ b/CMakeLists.txt
  5@@ -19,7 +19,6 @@ add_library(hy3 SHARED
  6 	src/Hy3Layout.cpp
  7 	src/Hy3Node.cpp
  8 	src/TabGroup.cpp
  9-	src/SelectionHook.cpp
 10 	src/shaders.cpp
 11 	src/render.cpp
 12 )
 13diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 14index aeddbf1c5e3c272d58fce62e5ba98faa10b22998..1b8f4aa3908b6654ad45ee04d10ea7537f768364 100644
 15--- a/src/Hy3Layout.cpp
 16+++ b/src/Hy3Layout.cpp
 17@@ -20,7 +20,6 @@
 18 
 19 #include "Hy3Layout.hpp"
 20 #include "Hy3Node.hpp"
 21-#include "SelectionHook.hpp"
 22 #include "TabGroup.hpp"
 23 #include "globals.hpp"
 24 #include "src/SharedDefs.hpp"
 25@@ -585,7 +584,17 @@ std::any Hy3Layout::layoutMessage(SLayoutMessageHeader header, std::string conte
 26 	return "";
 27 }
 28 
 29-SWindowRenderLayoutHints Hy3Layout::requestRenderHints(PHLWINDOW window) { return {}; }
 30+SWindowRenderLayoutHints Hy3Layout::requestRenderHints(PHLWINDOW window) {
 31+	if (this->shouldRenderSelected(window.get())) {
 32+    static auto active_color = CConfigValue<Hyprlang::CUSTOMTYPE>("general:col.active_border");
 33+		return {
 34+			.isBorderGradient = true,
 35+			.borderGradient = static_cast<CGradientValueData*>((active_color.ptr())->getData()),
 36+		};
 37+	}
 38+
 39+	return {};
 40+}
 41 
 42 void Hy3Layout::switchWindows(PHLWINDOW pWindowA, PHLWINDOW pWindowB) {
 43 	// todo
 44@@ -692,8 +701,6 @@ void Hy3Layout::onEnable() {
 45 
 46 	mouseButtonPtr =
 47 	    HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseButton", &Hy3Layout::mouseButtonHook);
 48-
 49-	selection_hook::enable();
 50 }
 51 
 52 void Hy3Layout::onDisable() {
 53@@ -702,7 +709,6 @@ void Hy3Layout::onDisable() {
 54 	urgentHookPtr.reset();
 55 	tickHookPtr.reset();
 56 	mouseButtonPtr.reset();
 57-	selection_hook::disable();
 58 
 59 	for (auto& node: this->nodes) {
 60 		if (node.data.is_window()) {
 61diff --git a/src/SelectionHook.cpp b/src/SelectionHook.cpp
 62deleted file mode 100644
 63index a726e58e4b3e7ff359ecd924cb31759388491472..0000000000000000000000000000000000000000
 64--- a/src/SelectionHook.cpp
 65+++ /dev/null
 66@@ -1,71 +0,0 @@
 67-#include <hyprland/src/Compositor.hpp>
 68-#include <hyprland/src/plugins/PluginAPI.hpp>
 69-
 70-#include "globals.hpp"
 71-
 72-namespace selection_hook {
 73-inline CFunctionHook* g_LastSelectionHook = nullptr;
 74-
 75-void hook_updateDecos(void* thisptr) {
 76-	auto* window = static_cast<CWindow*>(thisptr);
 77-	bool explicitly_selected = g_Hy3Layout->shouldRenderSelected(window);
 78-
 79-	auto lastWindow = g_pCompositor->m_lastWindow;
 80-	if (explicitly_selected) {
 81-		g_pCompositor->m_lastWindow = window->m_self;
 82-	}
 83-
 84-	((void (*)(void*)) g_LastSelectionHook->m_original)(thisptr);
 85-
 86-	if (explicitly_selected) {
 87-		g_pCompositor->m_lastWindow = lastWindow;
 88-	}
 89-}
 90-
 91-void init() {
 92-	static const auto decoUpdateCandidates =
 93-	    HyprlandAPI::findFunctionsByName(PHANDLE, "updateDecorationValues");
 94-
 95-	if (decoUpdateCandidates.size() != 1) {
 96-		g_LastSelectionHook = nullptr;
 97-
 98-		hy3_log(
 99-		    ERR,
100-		    "expected one matching function to hook for"
101-		    "\"updateDecorationValues\", found {}",
102-		    decoUpdateCandidates.size()
103-		);
104-
105-		HyprlandAPI::addNotificationV2(
106-		    PHANDLE,
107-		    {
108-		        {"text",
109-		         "Failed to load function hooks: "
110-		         "\"updateDecorationValues\""},
111-		        {"time", (uint64_t) 10000},
112-		        {"color", CHyprColor(1.0, 0.0, 0.0, 1.0)},
113-		        {"icon", ICON_ERROR},
114-		    }
115-		);
116-		return;
117-	}
118-
119-	g_LastSelectionHook = HyprlandAPI::createFunctionHook(
120-	    PHANDLE,
121-	    decoUpdateCandidates[0].address,
122-	    (void*) &hook_updateDecos
123-	);
124-}
125-
126-void enable() {
127-	if (g_LastSelectionHook != nullptr) {
128-		g_LastSelectionHook->hook();
129-	}
130-}
131-
132-void disable() {
133-	if (g_LastSelectionHook != nullptr) {
134-		g_LastSelectionHook->unhook();
135-	}
136-}
137-} // namespace selection_hook
138diff --git a/src/SelectionHook.hpp b/src/SelectionHook.hpp
139deleted file mode 100644
140index 6040bdb6558626daae4a15dd30d31c44ab37af3f..0000000000000000000000000000000000000000
141--- a/src/SelectionHook.hpp
142+++ /dev/null
143@@ -1,7 +0,0 @@
144-#pragma once
145-
146-namespace selection_hook {
147-void init();
148-void enable();
149-void disable();
150-} // namespace selection_hook
151diff --git a/src/main.cpp b/src/main.cpp
152index f7f1f752fa2f62d58f5b3b4a07b7af8deb15eb59..d935b2f416adce697bed7e80e01838943681f04a 100644
153--- a/src/main.cpp
154+++ b/src/main.cpp
155@@ -4,7 +4,6 @@
156 #include <hyprland/src/version.h>
157 #include <hyprlang.hpp>
158 
159-#include "SelectionHook.hpp"
160 #include "dispatchers.hpp"
161 #include "globals.hpp"
162 
163@@ -29,8 +28,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
164 	}
165 #endif
166 
167-	selection_hook::init();
168-
169 #define CONF(NAME, TYPE, VALUE)                                                                    \
170 	HyprlandAPI::addConfigValue(PHANDLE, "plugin:hy3:" NAME, Hyprlang::CConfigValue((TYPE) VALUE))
171