event: refactor HookSystem into a typed event bus (#13333)

Refactors the old HookSystem into a typed event bus with clear
separation,
discovery and types.
This commit is contained in:
Vaxry 2026-02-22 23:30:10 +00:00 committed by GitHub
parent b4ee4674f9
commit b88813c7ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
58 changed files with 493 additions and 516 deletions

View file

@ -10,6 +10,7 @@
#include "../../../../desktop/history/WindowHistoryTracker.hpp"
#include "../../../../helpers/Monitor.hpp"
#include "../../../../Compositor.hpp"
#include "../../../../event/EventBus.hpp"
#include <hyprutils/string/VarList2.hpp>
#include <hyprutils/string/ConstVarList.hpp>
@ -22,16 +23,14 @@ using namespace Layout::Tiled;
CMonocleAlgorithm::CMonocleAlgorithm() {
// hook into focus changes to bring focused window to front
m_focusCallback = g_pHookSystem->hookDynamic("activeWindow", [this](void* hk, SCallbackInfo& info, std::any param) {
const auto PWINDOW = std::any_cast<Desktop::View::SWindowActiveEvent>(param).window;
if (!PWINDOW)
m_focusCallback = Event::bus()->m_events.window.active.listen([this](PHLWINDOW pWindow, Desktop::eFocusReason reason) {
if (!pWindow)
return;
if (!PWINDOW->m_workspace->isVisible())
if (!pWindow->m_workspace->isVisible())
return;
const auto TARGET = PWINDOW->layoutTarget();
const auto TARGET = pWindow->layoutTarget();
if (!TARGET)
return;

View file

@ -1,7 +1,7 @@
#pragma once
#include "../../TiledAlgorithm.hpp"
#include "../../../../managers/HookSystemManager.hpp"
#include "../../../../helpers/signal/Signal.hpp"
#include <vector>
@ -38,7 +38,7 @@ namespace Layout::Tiled {
private:
std::vector<SP<SMonocleTargetData>> m_targetDatas;
SP<HOOK_CALLBACK_FN> m_focusCallback;
CHyprSignalListener m_focusCallback;
int m_currentVisibleIndex = 0;

View file

@ -11,6 +11,7 @@
#include "../../../../config/ConfigManager.hpp"
#include "../../../../render/Renderer.hpp"
#include "../../../../managers/input/InputManager.hpp"
#include "../../../../event/EventBus.hpp"
#include <hyprutils/string/VarList2.hpp>
#include <hyprutils/string/ConstVarList.hpp>
@ -477,7 +478,7 @@ CScrollingAlgorithm::CScrollingAlgorithm() {
return SCROLL_DIR_RIGHT; // default
};
m_configCallback = g_pHookSystem->hookDynamic("configReloaded", [this, parseDirection](void* hk, SCallbackInfo& info, std::any param) {
m_configCallback = Event::bus()->m_events.config.reloaded.listen([this, parseDirection] {
static const auto PCONFDIRECTION = CConfigValue<Hyprlang::STRING>("scrolling:direction");
m_config.configuredWidths.clear();
@ -495,32 +496,28 @@ CScrollingAlgorithm::CScrollingAlgorithm() {
m_scrollingData->controller->setDirection(parseDirection(*PCONFDIRECTION));
});
m_mouseButtonCallback = g_pHookSystem->hookDynamic("mouseButton", [this](void* self, SCallbackInfo& info, std::any e) {
auto E = std::any_cast<IPointer::SButtonEvent>(e);
if (E.state == WL_POINTER_BUTTON_STATE_RELEASED && Desktop::focusState()->window())
m_mouseButtonCallback = Event::bus()->m_events.input.mouse.button.listen([this](IPointer::SButtonEvent e, Event::SCallbackInfo&) {
if (e.state == WL_POINTER_BUTTON_STATE_RELEASED && Desktop::focusState()->window())
focusOnInput(Desktop::focusState()->window()->layoutTarget(), true);
});
m_focusCallback = g_pHookSystem->hookDynamic("activeWindow", [this](void* hk, SCallbackInfo& info, std::any param) {
const auto E = std::any_cast<Desktop::View::SWindowActiveEvent>(param);
const auto PWINDOW = E.window;
if (!PWINDOW)
m_focusCallback = Event::bus()->m_events.window.active.listen([this](PHLWINDOW pWindow, Desktop::eFocusReason reason) {
if (!pWindow)
return;
static const auto PFOLLOW_FOCUS = CConfigValue<Hyprlang::INT>("scrolling:follow_focus");
if (!*PFOLLOW_FOCUS && !Desktop::isHardInputFocusReason(E.reason))
if (!*PFOLLOW_FOCUS && !Desktop::isHardInputFocusReason(reason))
return;
if (PWINDOW->m_workspace != m_parent->space()->workspace())
if (pWindow->m_workspace != m_parent->space()->workspace())
return;
const auto TARGET = PWINDOW->layoutTarget();
const auto TARGET = pWindow->layoutTarget();
if (!TARGET || TARGET->floating())
return;
focusOnInput(TARGET, Desktop::isHardInputFocusReason(E.reason));
focusOnInput(TARGET, Desktop::isHardInputFocusReason(reason));
});
// Initialize default widths and direction

View file

@ -1,9 +1,9 @@
#pragma once
#include "../../TiledAlgorithm.hpp"
#include "../../../../managers/HookSystemManager.hpp"
#include "../../../../helpers/math/Direction.hpp"
#include "ScrollTapeController.hpp"
#include "../../../../helpers/signal/Signal.hpp"
#include <vector>
@ -112,11 +112,11 @@ namespace Layout::Tiled {
CBox usableArea();
private:
SP<SScrollingData> m_scrollingData;
SP<SScrollingData> m_scrollingData;
SP<HOOK_CALLBACK_FN> m_configCallback;
SP<HOOK_CALLBACK_FN> m_focusCallback;
SP<HOOK_CALLBACK_FN> m_mouseButtonCallback;
CHyprSignalListener m_configCallback;
CHyprSignalListener m_focusCallback;
CHyprSignalListener m_mouseButtonCallback;
struct {
std::vector<float> configuredWidths;