diff --git a/CMakeLists.txt b/CMakeLists.txt index 12d2a4b..83b0bbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index aeddbf1..1b8f4aa 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -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("general:col.active_border"); + return { + .isBorderGradient = true, + .borderGradient = static_cast((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()) { diff --git a/src/SelectionHook.cpp b/src/SelectionHook.cpp deleted file mode 100644 index a726e58..0000000 --- a/src/SelectionHook.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include - -#include "globals.hpp" - -namespace selection_hook { -inline CFunctionHook* g_LastSelectionHook = nullptr; - -void hook_updateDecos(void* thisptr) { - auto* window = static_cast(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 diff --git a/src/SelectionHook.hpp b/src/SelectionHook.hpp deleted file mode 100644 index 6040bdb..0000000 --- a/src/SelectionHook.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace selection_hook { -void init(); -void enable(); -void disable(); -} // namespace selection_hook diff --git a/src/main.cpp b/src/main.cpp index f7f1f75..d935b2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,6 @@ #include #include -#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))