From b88813c7efa4b7b0c5fe01471c5fa5b67a61dc7e Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 22 Feb 2026 23:30:10 +0000 Subject: event: refactor HookSystem into a typed event bus (#13333) Refactors the old HookSystem into a typed event bus with clear separation, discovery and types. --- src/managers/input/InputManager.cpp | 69 ++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 20 deletions(-) (limited to 'src/managers/input/InputManager.cpp') diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index e0b1a452..4a87a878 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -35,7 +35,6 @@ #include "../../managers/SeatManager.hpp" #include "../../managers/KeybindManager.hpp" #include "../../render/Renderer.hpp" -#include "../../managers/HookSystemManager.hpp" #include "../../managers/EventManager.hpp" #include "../../managers/permissions/DynamicPermissionManager.hpp" @@ -44,6 +43,8 @@ #include "../../layout/LayoutManager.hpp" +#include "../../event/EventBus.hpp" + #include "trackpad/TrackpadGestures.hpp" #include "../cursor/CursorShapeOverrideController.hpp" @@ -233,7 +234,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st PHLLS pFoundLayerSurface; const auto FOCUS_REASON = refocus ? Desktop::FOCUS_REASON_CLICK : Desktop::FOCUS_REASON_FFM; - EMIT_HOOK_EVENT_CANCELLABLE("mouseMove", MOUSECOORDSFLOORED); + Event::SCallbackInfo info; + Event::bus()->m_events.input.mouse.move.emit(MOUSECOORDSFLOORED, info); + if (info.cancelled) + return; m_lastCursorPosFloored = MOUSECOORDSFLOORED; @@ -644,7 +648,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st } void CInputManager::onMouseButton(IPointer::SButtonEvent e) { - EMIT_HOOK_EVENT_CANCELLABLE("mouseButton", e); + Event::SCallbackInfo info; + Event::bus()->m_events.input.mouse.button.emit(e, info); + if (info.cancelled) + return; if (e.mouse) recheckMouseWarpOnMouseInput(); @@ -866,8 +873,10 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e, SP pointer) { if (pointer && pointer->m_scrollFactor.has_value()) factor = *pointer->m_scrollFactor; - const auto EMAP = std::unordered_map{{"event", e}}; - EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP); + Event::SCallbackInfo info; + Event::bus()->m_events.input.mouse.axis.emit(e, info); + if (info.cancelled) + return; if (e.mouse) recheckMouseWarpOnMouseInput(); @@ -1056,7 +1065,7 @@ void CInputManager::setupKeyboard(SP keeb) { } g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", PKEEB->m_hlName + "," + LAYOUT}); - EMIT_HOOK_EVENT("activeLayout", (std::vector{PKEEB, LAYOUT})); + Event::bus()->m_events.input.keyboard.layout.emit(PKEEB, LAYOUT); }); disableAllKeyboards(false); @@ -1153,7 +1162,7 @@ void CInputManager::applyConfigToKeyboard(SP pKeyboard) { const auto LAYOUTSTR = pKeyboard->getActiveLayout(); g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", pKeyboard->m_hlName + "," + LAYOUTSTR}); - EMIT_HOOK_EVENT("activeLayout", (std::vector{pKeyboard, LAYOUTSTR})); + Event::bus()->m_events.input.keyboard.layout.emit(pKeyboard, LAYOUTSTR); Log::logger->log(Log::DEBUG, "Set the keyboard layout to {} and variant to {} for keyboard \"{}\"", pKeyboard->m_currentRules.layout, pKeyboard->m_currentRules.variant, pKeyboard->m_hlName); @@ -1475,14 +1484,16 @@ void CInputManager::onKeyboardKey(const IKeyboard::SKeyEvent& event, SPm_enabled || !pKeyboard->m_allowed) return; - const bool DISALLOWACTION = pKeyboard->isVirtual() && shouldIgnoreVirtualKeyboard(pKeyboard); + const bool DISALLOWACTION = pKeyboard->isVirtual() && shouldIgnoreVirtualKeyboard(pKeyboard); - const auto IME = m_relay.m_inputMethod.lock(); - const bool HASIME = IME && IME->hasGrab(); - const bool USEIME = HASIME && !DISALLOWACTION; + const auto IME = m_relay.m_inputMethod.lock(); + const bool HASIME = IME && IME->hasGrab(); + const bool USEIME = HASIME && !DISALLOWACTION; - const auto EMAP = std::unordered_map{{"keyboard", pKeyboard}, {"event", event}}; - EMIT_HOOK_EVENT_CANCELLABLE("keyPress", EMAP); + Event::SCallbackInfo info; + Event::bus()->m_events.input.keyboard.key.emit(event, info); + if (info.cancelled) + return; bool passEvent = DISALLOWACTION; @@ -1571,7 +1582,7 @@ void CInputManager::onKeyboardMod(SP pKeyboard) { Log::logger->log(Log::DEBUG, "LAYOUT CHANGED TO {} GROUP {}", LAYOUT, MODS.group); g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", pKeyboard->m_hlName + "," + LAYOUT}); - EMIT_HOOK_EVENT("activeLayout", (std::vector{pKeyboard, LAYOUT})); + Event::bus()->m_events.input.keyboard.layout.emit(pKeyboard, LAYOUT); } } @@ -2039,7 +2050,10 @@ void CInputManager::recheckMouseWarpOnMouseInput() { } void CInputManager::onSwipeBegin(IPointer::SSwipeBeginEvent e) { - EMIT_HOOK_EVENT_CANCELLABLE("swipeBegin", e); + Event::SCallbackInfo info; + Event::bus()->m_events.gesture.swipe.begin.emit(e, info); + if (info.cancelled) + return; g_pTrackpadGestures->gestureBegin(e); @@ -2047,7 +2061,10 @@ void CInputManager::onSwipeBegin(IPointer::SSwipeBeginEvent e) { } void CInputManager::onSwipeUpdate(IPointer::SSwipeUpdateEvent e) { - EMIT_HOOK_EVENT_CANCELLABLE("swipeUpdate", e); + Event::SCallbackInfo info; + Event::bus()->m_events.gesture.swipe.update.emit(e, info); + if (info.cancelled) + return; g_pTrackpadGestures->gestureUpdate(e); @@ -2055,7 +2072,10 @@ void CInputManager::onSwipeUpdate(IPointer::SSwipeUpdateEvent e) { } void CInputManager::onSwipeEnd(IPointer::SSwipeEndEvent e) { - EMIT_HOOK_EVENT_CANCELLABLE("swipeEnd", e); + Event::SCallbackInfo info; + Event::bus()->m_events.gesture.swipe.end.emit(e, info); + if (info.cancelled) + return; g_pTrackpadGestures->gestureEnd(e); @@ -2063,7 +2083,10 @@ void CInputManager::onSwipeEnd(IPointer::SSwipeEndEvent e) { } void CInputManager::onPinchBegin(IPointer::SPinchBeginEvent e) { - EMIT_HOOK_EVENT_CANCELLABLE("pinchBegin", e); + Event::SCallbackInfo info; + Event::bus()->m_events.gesture.pinch.begin.emit(e, info); + if (info.cancelled) + return; g_pTrackpadGestures->gestureBegin(e); @@ -2071,7 +2094,10 @@ void CInputManager::onPinchBegin(IPointer::SPinchBeginEvent e) { } void CInputManager::onPinchUpdate(IPointer::SPinchUpdateEvent e) { - EMIT_HOOK_EVENT_CANCELLABLE("pinchUpdate", e); + Event::SCallbackInfo info; + Event::bus()->m_events.gesture.pinch.update.emit(e, info); + if (info.cancelled) + return; g_pTrackpadGestures->gestureUpdate(e); @@ -2079,7 +2105,10 @@ void CInputManager::onPinchUpdate(IPointer::SPinchUpdateEvent e) { } void CInputManager::onPinchEnd(IPointer::SPinchEndEvent e) { - EMIT_HOOK_EVENT_CANCELLABLE("pinchEnd", e); + Event::SCallbackInfo info; + Event::bus()->m_events.gesture.pinch.end.emit(e, info); + if (info.cancelled) + return; g_pTrackpadGestures->gestureEnd(e); -- cgit v1.2.3