mirror of
https://github.com/Trensa-Organization/hy3.git
synced 2025-03-15 18:53:40 +01:00
Fix selection hook segfaulting on reload
This commit is contained in:
parent
e41c3cb256
commit
136c910c5a
4 changed files with 37 additions and 27 deletions
|
@ -1017,11 +1017,11 @@ void Hy3Layout::onEnable() {
|
|||
this->onWindowCreatedTiling(window.get());
|
||||
}
|
||||
|
||||
setup_selection_hook();
|
||||
selection_hook::enable();
|
||||
}
|
||||
|
||||
void Hy3Layout::onDisable() {
|
||||
disable_selection_hook();
|
||||
selection_hook::disable();
|
||||
this->nodes.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,29 +2,30 @@
|
|||
#include <hyprland/src/plugins/PluginAPI.hpp>
|
||||
#include <hyprland/src/Compositor.hpp>
|
||||
|
||||
inline CFunctionHook* g_LastSelectionHook = nullptr;
|
||||
namespace selection_hook {
|
||||
inline CFunctionHook* g_LastSelectionHook = nullptr;
|
||||
|
||||
void hook_update_decos(void* thisptr, CWindow* window) {
|
||||
bool explicitly_selected = g_Hy3Layout->shouldRenderSelected(window);
|
||||
Debug::log(LOG, "update decos for %p - selected: %d", window, explicitly_selected);
|
||||
void hook_updateDecos(void* thisptr, CWindow* window) {
|
||||
bool explicitly_selected = g_Hy3Layout->shouldRenderSelected(window);
|
||||
Debug::log(LOG, "update decos for %p - selected: %d", window, explicitly_selected);
|
||||
|
||||
auto* lastWindow = g_pCompositor->m_pLastWindow;
|
||||
if (explicitly_selected) {
|
||||
g_pCompositor->m_pLastWindow = window;
|
||||
auto* lastWindow = g_pCompositor->m_pLastWindow;
|
||||
if (explicitly_selected) {
|
||||
g_pCompositor->m_pLastWindow = window;
|
||||
}
|
||||
|
||||
((void (*)(void*, CWindow*)) g_LastSelectionHook->m_pOriginal)(thisptr, window);
|
||||
|
||||
if (explicitly_selected) {
|
||||
g_pCompositor->m_pLastWindow = lastWindow;
|
||||
}
|
||||
}
|
||||
|
||||
((void (*)(void*, CWindow*)) g_LastSelectionHook->m_pOriginal)(thisptr, window);
|
||||
|
||||
if (explicitly_selected) {
|
||||
g_pCompositor->m_pLastWindow = lastWindow;
|
||||
}
|
||||
}
|
||||
|
||||
void setup_selection_hook() {
|
||||
if (g_LastSelectionHook == nullptr) {
|
||||
void init() {
|
||||
static const auto decoUpdateCandidates = HyprlandAPI::findFunctionsByName(PHANDLE, "updateWindowAnimatedDecorationValues");
|
||||
|
||||
if (decoUpdateCandidates.size() != 1) {
|
||||
g_LastSelectionHook = nullptr;
|
||||
Debug::log(ERR, "Expected one matching function to hook for \"updateWindowAnimatedDecorationValues\", found %d", decoUpdateCandidates.size());
|
||||
HyprlandAPI::addNotificationV2(PHANDLE, {
|
||||
{"text", "Failed to load function hooks: \"updateWindowAnimatedDecorationValues\""},
|
||||
|
@ -35,14 +36,18 @@ void setup_selection_hook() {
|
|||
return;
|
||||
}
|
||||
|
||||
g_LastSelectionHook = HyprlandAPI::createFunctionHook(PHANDLE, decoUpdateCandidates[0].address, (void*)&hook_update_decos);
|
||||
g_LastSelectionHook = HyprlandAPI::createFunctionHook(PHANDLE, decoUpdateCandidates[0].address, (void*)&hook_updateDecos);
|
||||
}
|
||||
|
||||
g_LastSelectionHook->hook();
|
||||
}
|
||||
void enable() {
|
||||
if (g_LastSelectionHook != nullptr) {
|
||||
g_LastSelectionHook->hook();
|
||||
}
|
||||
}
|
||||
|
||||
void disable_selection_hook() {
|
||||
if (g_LastSelectionHook != nullptr) {
|
||||
g_LastSelectionHook->unhook();
|
||||
void disable() {
|
||||
if (g_LastSelectionHook != nullptr) {
|
||||
g_LastSelectionHook->unhook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
void setup_selection_hook();
|
||||
void disable_selection_hook();
|
||||
namespace selection_hook {
|
||||
void init();
|
||||
void enable();
|
||||
void disable();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <hyprland/src/Compositor.hpp>
|
||||
|
||||
#include "globals.hpp"
|
||||
|
||||
#include "SelectionHook.hpp"
|
||||
|
||||
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
||||
return HYPRLAND_API_VERSION;
|
||||
|
@ -98,6 +98,8 @@ void dispatch_debug(std::string arg) {
|
|||
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
||||
PHANDLE = handle;
|
||||
|
||||
selection_hook::init();
|
||||
|
||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hy3:no_gaps_when_only", SConfigValue{.intValue = 0});
|
||||
|
||||
g_Hy3Layout = std::make_unique<Hy3Layout>();
|
||||
|
|
Loading…
Add table
Reference in a new issue