summaryrefslogtreecommitdiff
path: root/src/managers
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2026-02-22 23:30:10 +0000
committerGitHub <noreply@github.com>2026-02-22 23:30:10 +0000
commitb88813c7efa4b7b0c5fe01471c5fa5b67a61dc7e (patch)
tree4454e82bc033d7e28a23ee372d0e3f48341d0aaa /src/managers
parentb4ee4674f9a74e3d602c7fb17bc09f79d221583c (diff)
event: refactor HookSystem into a typed event bus (#13333)
Refactors the old HookSystem into a typed event bus with clear separation, discovery and types.
Diffstat (limited to 'src/managers')
-rw-r--r--src/managers/ANRManager.cpp10
-rw-r--r--src/managers/CursorManager.cpp4
-rw-r--r--src/managers/HookSystemManager.cpp83
-rw-r--r--src/managers/HookSystemManager.hpp60
-rw-r--r--src/managers/KeybindManager.cpp11
-rw-r--r--src/managers/PointerManager.cpp16
-rw-r--r--src/managers/PointerManager.hpp5
-rw-r--r--src/managers/ProtocolManager.cpp9
-rw-r--r--src/managers/SeatManager.cpp1
-rw-r--r--src/managers/animation/AnimationManager.cpp6
-rw-r--r--src/managers/input/InputManager.cpp69
-rw-r--r--src/managers/input/InputMethodRelay.cpp5
-rw-r--r--src/managers/input/Tablets.cpp22
-rw-r--r--src/managers/input/Touch.cpp26
-rw-r--r--src/managers/screenshare/ScreenshareSession.cpp10
15 files changed, 121 insertions, 216 deletions
diff --git a/src/managers/ANRManager.cpp b/src/managers/ANRManager.cpp
index 43d2d080..9f613df8 100644
--- a/src/managers/ANRManager.cpp
+++ b/src/managers/ANRManager.cpp
@@ -3,13 +3,13 @@
#include "../helpers/fs/FsUtils.hpp"
#include "../debug/log/Logger.hpp"
#include "../macros.hpp"
-#include "HookSystemManager.hpp"
#include "../Compositor.hpp"
#include "../protocols/XDGShell.hpp"
#include "./eventLoop/EventLoopManager.hpp"
#include "../config/ConfigValue.hpp"
#include "../xwayland/XSurface.hpp"
#include "../i18n/Engine.hpp"
+#include "../event/EventBus.hpp"
using namespace Hyprutils::OS;
@@ -26,9 +26,7 @@ CANRManager::CANRManager() {
m_active = true;
- static auto P = g_pHookSystem->hookDynamic("openWindow", [this](void* self, SCallbackInfo& info, std::any data) {
- auto window = std::any_cast<PHLWINDOW>(data);
-
+ static auto P = Event::bus()->m_events.window.open.listen([this](PHLWINDOW window) {
for (const auto& d : m_data) {
// Window is ANR dialog
if (d->isRunning() && d->dialogBox->getPID() == window->getPID())
@@ -41,9 +39,7 @@ CANRManager::CANRManager() {
m_data.emplace_back(makeShared<SANRData>(window));
});
- static auto P1 = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any data) {
- auto window = std::any_cast<PHLWINDOW>(data);
-
+ static auto P1 = Event::bus()->m_events.window.close.listen([this](PHLWINDOW window) {
for (const auto& d : m_data) {
if (!d->fitsWindow(window))
continue;
diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp
index 8392db0a..7564ca75 100644
--- a/src/managers/CursorManager.cpp
+++ b/src/managers/CursorManager.cpp
@@ -3,8 +3,8 @@
#include "../config/ConfigValue.hpp"
#include "PointerManager.hpp"
#include "../xwayland/XWayland.hpp"
-#include "../managers/HookSystemManager.hpp"
#include "../helpers/Monitor.hpp"
+#include "../event/EventBus.hpp"
static int cursorAnimTimer(SP<CEventLoopTimer> self, void* data) {
const auto cursorMgr = sc<CCursorManager*>(data);
@@ -111,7 +111,7 @@ CCursorManager::CCursorManager() {
updateTheme();
- static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateTheme(); });
+ static auto P = Event::bus()->m_events.monitor.layoutChanged.listen([this] { this->updateTheme(); });
}
CCursorManager::~CCursorManager() {
diff --git a/src/managers/HookSystemManager.cpp b/src/managers/HookSystemManager.cpp
deleted file mode 100644
index 0aa2d93e..00000000
--- a/src/managers/HookSystemManager.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "HookSystemManager.hpp"
-
-#include "../plugins/PluginSystem.hpp"
-
-CHookSystemManager::CHookSystemManager() {
- ; //
-}
-
-// returns the pointer to the function
-SP<HOOK_CALLBACK_FN> CHookSystemManager::hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn, HANDLE handle) {
- SP<HOOK_CALLBACK_FN> hookFN = makeShared<HOOK_CALLBACK_FN>(fn);
- m_registeredHooks[event].emplace_back(SCallbackFNPtr{.fn = hookFN, .handle = handle});
- return hookFN;
-}
-
-void CHookSystemManager::unhook(SP<HOOK_CALLBACK_FN> fn) {
- for (auto& [k, v] : m_registeredHooks) {
- std::erase_if(v, [&](const auto& other) {
- SP<HOOK_CALLBACK_FN> fn_ = other.fn.lock();
-
- return fn_.get() == fn.get();
- });
- }
-}
-
-void CHookSystemManager::emit(std::vector<SCallbackFNPtr>* const callbacks, SCallbackInfo& info, std::any data) {
- if (callbacks->empty())
- return;
-
- std::vector<HANDLE> faultyHandles;
- volatile bool needsDeadCleanup = false;
-
- for (auto const& cb : *callbacks) {
-
- m_currentEventPlugin = false;
-
- if (!cb.handle) {
- // we don't guard hl hooks
-
- if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock())
- (*fn)(fn.get(), info, data);
- else
- needsDeadCleanup = true;
- continue;
- }
-
- m_currentEventPlugin = true;
-
- if (std::ranges::find(faultyHandles, cb.handle) != faultyHandles.end())
- continue;
-
- try {
- if (!setjmp(m_hookFaultJumpBuf)) {
- if (SP<HOOK_CALLBACK_FN> fn = cb.fn.lock())
- (*fn)(fn.get(), info, data);
- else
- needsDeadCleanup = true;
- } else {
- // this module crashed.
- throw std::exception();
- }
- } catch (std::exception& e) {
- // TODO: this works only once...?
- faultyHandles.push_back(cb.handle);
- Log::logger->log(Log::ERR, "[hookSystem] Hook from plugin {:x} caused a SIGSEGV, queueing for unloading.", rc<uintptr_t>(cb.handle));
- }
- }
-
- if (needsDeadCleanup)
- std::erase_if(*callbacks, [](const auto& fn) { return !fn.fn.lock(); });
-
- if (!faultyHandles.empty()) {
- for (auto const& h : faultyHandles)
- g_pPluginSystem->unloadPlugin(g_pPluginSystem->getPluginByHandle(h), true);
- }
-}
-
-std::vector<SCallbackFNPtr>* CHookSystemManager::getVecForEvent(const std::string& event) {
- if (!m_registeredHooks.contains(event))
- Log::logger->log(Log::DEBUG, "[hookSystem] New hook event registered: {}", event);
-
- return &m_registeredHooks[event];
-}
diff --git a/src/managers/HookSystemManager.hpp b/src/managers/HookSystemManager.hpp
deleted file mode 100644
index 647e9670..00000000
--- a/src/managers/HookSystemManager.hpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#pragma once
-
-#include "../defines.hpp"
-
-#include <unordered_map>
-#include <any>
-#include <array>
-#include <list>
-
-#include <csetjmp>
-
-#define HANDLE void*
-
-// global type alias for hooked functions. Passes itself as a ptr when called, and `data` additionally.
-
-using HOOK_CALLBACK_FN = std::function<void(void*, SCallbackInfo& info, std::any data)>;
-
-struct SCallbackFNPtr {
- WP<HOOK_CALLBACK_FN> fn;
- HANDLE handle = nullptr;
-};
-
-#define EMIT_HOOK_EVENT(name, param) \
- { \
- static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent(name); \
- SCallbackInfo info; \
- g_pHookSystem->emit(PEVENTVEC, info, param); \
- }
-
-#define EMIT_HOOK_EVENT_CANCELLABLE(name, param) \
- { \
- static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent(name); \
- SCallbackInfo info; \
- g_pHookSystem->emit(PEVENTVEC, info, param); \
- if (info.cancelled) \
- return; \
- }
-
-class CHookSystemManager {
- public:
- CHookSystemManager();
-
- // returns the pointer to the function.
- // losing this pointer (letting it get destroyed)
- // will equal to unregistering the callback.
- [[nodiscard("Losing this pointer instantly unregisters the callback")]] SP<HOOK_CALLBACK_FN> hookDynamic(const std::string& event, HOOK_CALLBACK_FN fn,
- HANDLE handle = nullptr);
- void unhook(SP<HOOK_CALLBACK_FN> fn);
-
- void emit(std::vector<SCallbackFNPtr>* const callbacks, SCallbackInfo& info, std::any data = 0);
- std::vector<SCallbackFNPtr>* getVecForEvent(const std::string& event);
-
- bool m_currentEventPlugin = false;
- jmp_buf m_hookFaultJumpBuf;
-
- private:
- std::unordered_map<std::string, std::vector<SCallbackFNPtr>> m_registeredHooks;
-};
-
-inline UP<CHookSystemManager> g_pHookSystem;
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 777f6bbe..e815579f 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -16,7 +16,6 @@
#include "TokenManager.hpp"
#include "eventLoop/EventLoopManager.hpp"
#include "debug/log/Logger.hpp"
-#include "../managers/HookSystemManager.hpp"
#include "../managers/input/InputManager.hpp"
#include "../managers/animation/DesktopAnimationManager.hpp"
#include "../managers/EventManager.hpp"
@@ -32,6 +31,7 @@
#include "../layout/algorithm/Algorithm.hpp"
#include "../layout/algorithm/tiled/master/MasterAlgorithm.hpp"
#include "../layout/algorithm/tiled/monocle/MonocleAlgorithm.hpp"
+#include "../event/EventBus.hpp"
#include <optional>
#include <iterator>
@@ -203,8 +203,7 @@ CKeybindManager::CKeybindManager() {
g_pEventLoopManager->addTimer(m_repeatKeyTimer);
}
- static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) {
- // clear cuz realloc'd
+ static auto P = Event::bus()->m_events.config.reloaded.listen([this] {
m_activeKeybinds.clear();
m_lastLongPressKeybind.reset();
m_pressedSpecialBinds.clear();
@@ -2215,7 +2214,7 @@ SDispatchResult CKeybindManager::setSubmap(std::string submap) {
m_currentSelectedSubmap.name = "";
Log::logger->log(Log::DEBUG, "Reset active submap to the default one.");
g_pEventManager->postEvent(SHyprIPCEvent{"submap", ""});
- EMIT_HOOK_EVENT("submap", m_currentSelectedSubmap.name);
+ Event::bus()->m_events.keybinds.submap.emit(m_currentSelectedSubmap.name);
return {};
}
@@ -2224,7 +2223,7 @@ SDispatchResult CKeybindManager::setSubmap(std::string submap) {
m_currentSelectedSubmap.name = submap;
Log::logger->log(Log::DEBUG, "Changed keybind submap to {}", submap);
g_pEventManager->postEvent(SHyprIPCEvent{"submap", submap});
- EMIT_HOOK_EVENT("submap", m_currentSelectedSubmap.name);
+ Event::bus()->m_events.keybinds.submap.emit(m_currentSelectedSubmap.name);
return {};
}
}
@@ -2584,7 +2583,7 @@ SDispatchResult CKeybindManager::pinActive(std::string args) {
g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS);
g_pEventManager->postEvent(SHyprIPCEvent{"pin", std::format("{:x},{}", rc<uintptr_t>(PWINDOW.get()), sc<int>(PWINDOW->m_pinned))});
- EMIT_HOOK_EVENT("pin", PWINDOW);
+ Event::bus()->m_events.window.pin.emit(PWINDOW);
g_pHyprRenderer->damageWindow(PWINDOW, true);
diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp
index 60964d4d..bdc22f43 100644
--- a/src/managers/PointerManager.cpp
+++ b/src/managers/PointerManager.cpp
@@ -11,13 +11,13 @@
#include "eventLoop/EventLoopManager.hpp"
#include "../render/pass/TexPassElement.hpp"
#include "../managers/input/InputManager.hpp"
-#include "../managers/HookSystemManager.hpp"
#include "../render/Renderer.hpp"
#include "../render/OpenGL.hpp"
#include "../desktop/state/FocusState.hpp"
#include "SeatManager.hpp"
#include "../helpers/time/Time.hpp"
#include "../helpers/Drm.hpp"
+#include "../event/EventBus.hpp"
#include <cstring>
#include <gbm.h>
#include <cairo/cairo.h>
@@ -26,21 +26,19 @@
using namespace Hyprutils::Utils;
CPointerManager::CPointerManager() {
- m_hooks.monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any data) {
- auto PMONITOR = std::any_cast<PHLMONITOR>(data);
-
+ m_hooks.monitorAdded = Event::bus()->m_events.monitor.added.listen([this](PHLMONITOR monitor) {
onMonitorLayoutChange();
- PMONITOR->m_events.modeChanged.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); });
- PMONITOR->m_events.disconnect.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); });
- PMONITOR->m_events.destroy.listenStatic([this] {
+ monitor->m_events.modeChanged.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); });
+ monitor->m_events.disconnect.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); });
+ monitor->m_events.destroy.listenStatic([this] {
if (g_pCompositor && !g_pCompositor->m_isShuttingDown)
std::erase_if(m_monitorStates, [](const auto& other) { return other->monitor.expired(); });
});
});
- m_hooks.monitorPreRender = g_pHookSystem->hookDynamic("preMonitorCommit", [this](void* self, SCallbackInfo& info, std::any data) {
- auto state = stateFor(std::any_cast<PHLMONITOR>(data));
+ m_hooks.monitorPreRender = Event::bus()->m_events.monitor.preCommit.listen([this](PHLMONITOR monitor) {
+ auto state = stateFor(monitor);
if (!state)
return;
diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp
index 0109268b..218541a4 100644
--- a/src/managers/PointerManager.hpp
+++ b/src/managers/PointerManager.hpp
@@ -7,6 +7,7 @@
#include "../desktop/view/WLSurface.hpp"
#include "../helpers/sync/SyncTimeline.hpp"
#include "../helpers/time/Time.hpp"
+#include "../helpers/signal/Signal.hpp"
#include <tuple>
class CMonitor;
@@ -184,8 +185,8 @@ class CPointerManager {
bool setHWCursorBuffer(SP<SMonitorPointerState> state, SP<Aquamarine::IBuffer> buf);
struct {
- SP<HOOK_CALLBACK_FN> monitorAdded;
- SP<HOOK_CALLBACK_FN> monitorPreRender;
+ CHyprSignalListener monitorAdded;
+ CHyprSignalListener monitorPreRender;
} m_hooks;
};
diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp
index 216c07f1..c13e6e48 100644
--- a/src/managers/ProtocolManager.cpp
+++ b/src/managers/ProtocolManager.cpp
@@ -67,9 +67,9 @@
#include "../protocols/PointerWarp.hpp"
#include "../protocols/Fifo.hpp"
#include "../protocols/CommitTiming.hpp"
-#include "HookSystemManager.hpp"
#include "../helpers/Monitor.hpp"
+#include "../event/EventBus.hpp"
#include "../render/Renderer.hpp"
#include "../Compositor.hpp"
#include "content-type-v1.hpp"
@@ -113,9 +113,7 @@ CProtocolManager::CProtocolManager() {
static const auto PENABLECT = CConfigValue<Hyprlang::INT>("render:commit_timing_enabled");
// Outputs are a bit dumb, we have to agree.
- static auto P = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) {
- auto M = std::any_cast<PHLMONITOR>(param);
-
+ static auto P = Event::bus()->m_events.monitor.added.listen([this](PHLMONITOR M) {
// ignore mirrored outputs. I don't think this will ever be hit as mirrors are applied after
// this event is emitted iirc.
// also ignore the fallback
@@ -132,8 +130,7 @@ CProtocolManager::CProtocolManager() {
m_modeChangeListeners[M->m_name] = M->m_events.modeChanged.listen([this, M] { onMonitorModeChange(M); });
});
- static auto P2 = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
- auto M = std::any_cast<PHLMONITOR>(param);
+ static auto P2 = Event::bus()->m_events.monitor.removed.listen([this](PHLMONITOR M) {
if (!PROTO::outputs.contains(M->m_name))
return;
PROTO::outputs.at(M->m_name)->remove();
diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp
index 1803a884..a107dced 100644
--- a/src/managers/SeatManager.cpp
+++ b/src/managers/SeatManager.cpp
@@ -11,7 +11,6 @@
#include "../devices/IKeyboard.hpp"
#include "../desktop/view/LayerSurface.hpp"
#include "../managers/input/InputManager.hpp"
-#include "../managers/HookSystemManager.hpp"
#include "wlr-layer-shell-unstable-v1.hpp"
#include <algorithm>
#include <hyprutils/utils/ScopeGuard.hpp>
diff --git a/src/managers/animation/AnimationManager.cpp b/src/managers/animation/AnimationManager.cpp
index 5a11fd11..c4b921cb 100644
--- a/src/managers/animation/AnimationManager.cpp
+++ b/src/managers/animation/AnimationManager.cpp
@@ -1,6 +1,5 @@
#include "AnimationManager.hpp"
#include "../../Compositor.hpp"
-#include "../HookSystemManager.hpp"
#include "../../config/ConfigManager.hpp"
#include "../../desktop/DesktopTypes.hpp"
#include "../../helpers/AnimatedVariable.hpp"
@@ -11,6 +10,7 @@
#include "../eventLoop/EventLoopManager.hpp"
#include "../../helpers/varlist/VarList.hpp"
#include "../../render/Renderer.hpp"
+#include "../../event/EventBus.hpp"
#include <hyprgraphics/color/Color.hpp>
#include <hyprutils/animation/AnimatedVariable.hpp>
@@ -252,7 +252,7 @@ void CHyprAnimationManager::frameTick() {
if (!shouldTickForNext())
return;
- if UNLIKELY (!g_pCompositor->m_sessionActive || !g_pHookSystem || g_pCompositor->m_unsafeState ||
+ if UNLIKELY (!g_pCompositor->m_sessionActive || g_pCompositor->m_unsafeState ||
!std::ranges::any_of(g_pCompositor->m_monitors, [](const auto& mon) { return mon->m_enabled && mon->m_output; }))
return;
@@ -261,7 +261,7 @@ void CHyprAnimationManager::frameTick() {
m_lastTickValid = true;
tick();
- EMIT_HOOK_EVENT("tick", nullptr);
+ Event::bus()->m_events.tick.emit();
}
if (shouldTickForNext())
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<IPointer> pointer) {
if (pointer && pointer->m_scrollFactor.has_value())
factor = *pointer->m_scrollFactor;
- const auto EMAP = std::unordered_map<std::string, std::any>{{"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<IKeyboard> keeb) {
}
g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", PKEEB->m_hlName + "," + LAYOUT});
- EMIT_HOOK_EVENT("activeLayout", (std::vector<std::any>{PKEEB, LAYOUT}));
+ Event::bus()->m_events.input.keyboard.layout.emit(PKEEB, LAYOUT);
});
disableAllKeyboards(false);
@@ -1153,7 +1162,7 @@ void CInputManager::applyConfigToKeyboard(SP<IKeyboard> pKeyboard) {
const auto LAYOUTSTR = pKeyboard->getActiveLayout();
g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", pKeyboard->m_hlName + "," + LAYOUTSTR});
- EMIT_HOOK_EVENT("activeLayout", (std::vector<std::any>{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, SP<IKeyboar
if (!pKeyboard->m_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<std::string, std::any>{{"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<IKeyboard> 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<std::any>{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);
diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp
index 6ee3c836..27fd80b6 100644
--- a/src/managers/input/InputMethodRelay.cpp
+++ b/src/managers/input/InputMethodRelay.cpp
@@ -1,14 +1,13 @@
#include "InputMethodRelay.hpp"
#include "../../desktop/state/FocusState.hpp"
+#include "../../event/EventBus.hpp"
#include "../../protocols/TextInputV3.hpp"
#include "../../protocols/TextInputV1.hpp"
#include "../../protocols/InputMethodV2.hpp"
#include "../../protocols/core/Compositor.hpp"
-#include "../../managers/HookSystemManager.hpp"
CInputMethodRelay::CInputMethodRelay() {
- static auto P =
- g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<SP<CWLSurfaceResource>>(param)); });
+ static auto P = Event::bus()->m_events.input.keyboard.focus.listen([&](SP<CWLSurfaceResource> surf) { onKeyboardFocus(surf); });
m_listeners.newTIV3 = PROTO::textInputV3->m_events.newTextInput.listen([this](const auto& input) { onNewTextInput(input); });
m_listeners.newTIV1 = PROTO::textInputV1->m_events.newTextInput.listen([this](const auto& input) { onNewTextInput(input); });
diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp
index 52be6eee..a2fec15c 100644
--- a/src/managers/input/Tablets.cpp
+++ b/src/managers/input/Tablets.cpp
@@ -2,11 +2,11 @@
#include "../../desktop/view/Window.hpp"
#include "../../protocols/Tablet.hpp"
#include "../../devices/Tablet.hpp"
-#include "../../managers/HookSystemManager.hpp"
#include "../../managers/PointerManager.hpp"
#include "../../managers/SeatManager.hpp"
#include "../../protocols/PointerConstraints.hpp"
#include "../../protocols/core/DataDevice.hpp"
+#include "../../event/EventBus.hpp"
static void unfocusTool(SP<CTabletTool> tool) {
if (!tool->getSurface())
@@ -107,6 +107,11 @@ static Vector2D transformToActiveRegion(const Vector2D pos, const CBox activeAre
}
void CInputManager::onTabletAxis(CTablet::SAxisEvent e) {
+ Event::SCallbackInfo info;
+ Event::bus()->m_events.input.tablet.axis.emit(e, info);
+ if (info.cancelled)
+ return;
+
const auto PTAB = e.tablet;
const auto PTOOL = ensureTabletToolPresent(e.tool);
@@ -171,7 +176,10 @@ void CInputManager::onTabletAxis(CTablet::SAxisEvent e) {
}
void CInputManager::onTabletTip(CTablet::STipEvent e) {
- EMIT_HOOK_EVENT_CANCELLABLE("tabletTip", e);
+ Event::SCallbackInfo info;
+ Event::bus()->m_events.input.tablet.tip.emit(e, info);
+ if (info.cancelled)
+ return;
const auto PTAB = e.tablet;
const auto PTOOL = ensureTabletToolPresent(e.tool);
@@ -196,6 +204,11 @@ void CInputManager::onTabletTip(CTablet::STipEvent e) {
}
void CInputManager::onTabletButton(CTablet::SButtonEvent e) {
+ Event::SCallbackInfo info;
+ Event::bus()->m_events.input.tablet.button.emit(e, info);
+ if (info.cancelled)
+ return;
+
const auto PTOOL = ensureTabletToolPresent(e.tool);
if (e.down)
@@ -210,6 +223,11 @@ void CInputManager::onTabletButton(CTablet::SButtonEvent e) {
}
void CInputManager::onTabletProximity(CTablet::SProximityEvent e) {
+ Event::SCallbackInfo info;
+ Event::bus()->m_events.input.tablet.proximity.emit(e, info);
+ if (info.cancelled)
+ return;
+
const auto PTAB = e.tablet;
const auto PTOOL = ensureTabletToolPresent(e.tool);
diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp
index 6136cb3f..e45bfd28 100644
--- a/src/managers/input/Touch.cpp
+++ b/src/managers/input/Touch.cpp
@@ -7,8 +7,8 @@
#include "../../config/ConfigValue.hpp"
#include "../../helpers/Monitor.hpp"
#include "../../devices/ITouch.hpp"
+#include "../../event/EventBus.hpp"
#include "../SeatManager.hpp"
-#include "../HookSystemManager.hpp"
#include "debug/log/Logger.hpp"
#include "UnifiedWorkspaceSwipeGesture.hpp"
@@ -19,10 +19,14 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) {
static auto PGAPSOUTDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_out");
auto* const PGAPSOUT = sc<CCssGapData*>((PGAPSOUTDATA.ptr())->getData());
// TODO: WORKSPACERULE.gapsOut.value_or()
- auto gapsOut = *PGAPSOUT;
- static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
- static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch_invert");
- EMIT_HOOK_EVENT_CANCELLABLE("touchDown", e);
+ auto gapsOut = *PGAPSOUT;
+ static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
+ static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch_invert");
+
+ Event::SCallbackInfo info;
+ Event::bus()->m_events.input.touch.down.emit(e, info);
+ if (info.cancelled)
+ return;
auto PMONITOR = g_pCompositor->getMonitorFromName(!e.device->m_boundOutput.empty() ? e.device->m_boundOutput : "");
@@ -109,7 +113,11 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) {
void CInputManager::onTouchUp(ITouch::SUpEvent e) {
m_lastInputTouch = true;
- EMIT_HOOK_EVENT_CANCELLABLE("touchUp", e);
+ Event::SCallbackInfo info;
+ Event::bus()->m_events.input.touch.up.emit(e, info);
+ if (info.cancelled)
+ return;
+
if (g_pUnifiedWorkspaceSwipe->isGestureInProgress()) {
// If there was a swipe from this finger, end it.
if (e.touchID == g_pUnifiedWorkspaceSwipe->m_touchID)
@@ -126,7 +134,11 @@ void CInputManager::onTouchMove(ITouch::SMotionEvent e) {
m_lastCursorMovement.reset();
- EMIT_HOOK_EVENT_CANCELLABLE("touchMove", e);
+ Event::SCallbackInfo info;
+ Event::bus()->m_events.input.touch.motion.emit(e, info);
+ if (info.cancelled)
+ return;
+
if (g_pUnifiedWorkspaceSwipe->isGestureInProgress()) {
// Do nothing if this is using a different finger.
if (e.touchID != g_pUnifiedWorkspaceSwipe->m_touchID)
diff --git a/src/managers/screenshare/ScreenshareSession.cpp b/src/managers/screenshare/ScreenshareSession.cpp
index 83402abf..8e81454e 100644
--- a/src/managers/screenshare/ScreenshareSession.cpp
+++ b/src/managers/screenshare/ScreenshareSession.cpp
@@ -2,9 +2,9 @@
#include "../../render/OpenGL.hpp"
#include "../../Compositor.hpp"
#include "../../render/Renderer.hpp"
-#include "../HookSystemManager.hpp"
#include "../EventManager.hpp"
#include "../eventLoop/EventLoopManager.hpp"
+#include "../../event/EventBus.hpp"
using namespace Screenshare;
@@ -119,18 +119,18 @@ void CScreenshareSession::calculateConstraints() {
void CScreenshareSession::screenshareEvents(bool startSharing) {
if (startSharing && !m_sharing) {
m_sharing = true;
- EMIT_HOOK_EVENT("screencast", (std::vector<std::any>{1, m_type}));
g_pEventManager->postEvent(SHyprIPCEvent{.event = "screencast", .data = std::format("1,{}", m_type)});
- EMIT_HOOK_EVENT("screencastv2", (std::vector<std::any>{1, m_type, m_name}));
g_pEventManager->postEvent(SHyprIPCEvent{.event = "screencastv2", .data = std::format("1,{},{}", m_type, m_name)});
LOGM(Log::INFO, "New screenshare session for ({}): {}", m_type, m_name);
+
+ Event::bus()->m_events.screenshare.state.emit(true, m_type, m_name);
} else if (!startSharing && m_sharing) {
m_sharing = false;
- EMIT_HOOK_EVENT("screencast", (std::vector<std::any>{0, m_type}));
g_pEventManager->postEvent(SHyprIPCEvent{.event = "screencast", .data = std::format("0,{}", m_type)});
- EMIT_HOOK_EVENT("screencastv2", (std::vector<std::any>{0, m_type, m_name}));
g_pEventManager->postEvent(SHyprIPCEvent{.event = "screencastv2", .data = std::format("0,{},{}", m_type, m_name)});
LOGM(Log::INFO, "Stopped screenshare session for ({}): {}", m_type, m_name);
+
+ Event::bus()->m_events.screenshare.state.emit(false, m_type, m_name);
}
}