replace SelectionHook with layout render hints

This commit is contained in:
outfoxxed
2025-11-29 15:35:52 -08:00
parent 43790aaa92
commit ae011bbd07
5 changed files with 11 additions and 87 deletions

View File

@@ -19,7 +19,6 @@ add_library(hy3 SHARED
src/Hy3Layout.cpp
src/Hy3Node.cpp
src/TabGroup.cpp
src/SelectionHook.cpp
src/shaders.cpp
src/render.cpp
)

View File

@@ -20,7 +20,6 @@
#include "Hy3Layout.hpp"
#include "Hy3Node.hpp"
#include "SelectionHook.hpp"
#include "TabGroup.hpp"
#include "globals.hpp"
#include "src/SharedDefs.hpp"
@@ -585,7 +584,17 @@ std::any Hy3Layout::layoutMessage(SLayoutMessageHeader header, std::string conte
return "";
}
SWindowRenderLayoutHints Hy3Layout::requestRenderHints(PHLWINDOW window) { return {}; }
SWindowRenderLayoutHints Hy3Layout::requestRenderHints(PHLWINDOW window) {
if (this->shouldRenderSelected(window.get())) {
static auto active_color = CConfigValue<Hyprlang::CUSTOMTYPE>("general:col.active_border");
return {
.isBorderGradient = true,
.borderGradient = static_cast<CGradientValueData*>((active_color.ptr())->getData()),
};
}
return {};
}
void Hy3Layout::switchWindows(PHLWINDOW pWindowA, PHLWINDOW pWindowB) {
// todo
@@ -692,8 +701,6 @@ void Hy3Layout::onEnable() {
mouseButtonPtr =
HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseButton", &Hy3Layout::mouseButtonHook);
selection_hook::enable();
}
void Hy3Layout::onDisable() {
@@ -702,7 +709,6 @@ void Hy3Layout::onDisable() {
urgentHookPtr.reset();
tickHookPtr.reset();
mouseButtonPtr.reset();
selection_hook::disable();
for (auto& node: this->nodes) {
if (node.data.is_window()) {

View File

@@ -1,71 +0,0 @@
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include "globals.hpp"
namespace selection_hook {
inline CFunctionHook* g_LastSelectionHook = nullptr;
void hook_updateDecos(void* thisptr) {
auto* window = static_cast<CWindow*>(thisptr);
bool explicitly_selected = g_Hy3Layout->shouldRenderSelected(window);
auto lastWindow = g_pCompositor->m_lastWindow;
if (explicitly_selected) {
g_pCompositor->m_lastWindow = window->m_self;
}
((void (*)(void*)) g_LastSelectionHook->m_original)(thisptr);
if (explicitly_selected) {
g_pCompositor->m_lastWindow = lastWindow;
}
}
void init() {
static const auto decoUpdateCandidates =
HyprlandAPI::findFunctionsByName(PHANDLE, "updateDecorationValues");
if (decoUpdateCandidates.size() != 1) {
g_LastSelectionHook = nullptr;
hy3_log(
ERR,
"expected one matching function to hook for"
"\"updateDecorationValues\", found {}",
decoUpdateCandidates.size()
);
HyprlandAPI::addNotificationV2(
PHANDLE,
{
{"text",
"Failed to load function hooks: "
"\"updateDecorationValues\""},
{"time", (uint64_t) 10000},
{"color", CHyprColor(1.0, 0.0, 0.0, 1.0)},
{"icon", ICON_ERROR},
}
);
return;
}
g_LastSelectionHook = HyprlandAPI::createFunctionHook(
PHANDLE,
decoUpdateCandidates[0].address,
(void*) &hook_updateDecos
);
}
void enable() {
if (g_LastSelectionHook != nullptr) {
g_LastSelectionHook->hook();
}
}
void disable() {
if (g_LastSelectionHook != nullptr) {
g_LastSelectionHook->unhook();
}
}
} // namespace selection_hook

View File

@@ -1,7 +0,0 @@
#pragma once
namespace selection_hook {
void init();
void enable();
void disable();
} // namespace selection_hook

View File

@@ -4,7 +4,6 @@
#include <hyprland/src/version.h>
#include <hyprlang.hpp>
#include "SelectionHook.hpp"
#include "dispatchers.hpp"
#include "globals.hpp"
@@ -29,8 +28,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
}
#endif
selection_hook::init();
#define CONF(NAME, TYPE, VALUE) \
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hy3:" NAME, Hyprlang::CConfigValue((TYPE) VALUE))