summaryrefslogtreecommitdiff
path: root/src/desktop
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/desktop
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/desktop')
-rw-r--r--src/desktop/Workspace.cpp17
-rw-r--r--src/desktop/Workspace.hpp10
-rw-r--r--src/desktop/history/WindowHistoryTracker.cpp14
-rw-r--r--src/desktop/history/WorkspaceHistoryTracker.cpp11
-rw-r--r--src/desktop/rule/windowRule/WindowRuleApplicator.cpp4
-rw-r--r--src/desktop/state/FocusState.cpp12
-rw-r--r--src/desktop/state/FocusState.hpp4
-rw-r--r--src/desktop/view/LayerSurface.cpp6
-rw-r--r--src/desktop/view/Window.cpp18
9 files changed, 41 insertions, 55 deletions
diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp
index f6e5288e..5df3f087 100644
--- a/src/desktop/Workspace.cpp
+++ b/src/desktop/Workspace.cpp
@@ -5,9 +5,9 @@
#include "config/ConfigManager.hpp"
#include "managers/animation/AnimationManager.hpp"
#include "../managers/EventManager.hpp"
-#include "../managers/HookSystemManager.hpp"
#include "../layout/space/Space.hpp"
#include "../layout/supplementary/WorkspaceAlgoMatcher.hpp"
+#include "../event/EventBus.hpp"
#include <hyprutils/animation/AnimatedVariable.hpp>
#include <hyprutils/string/String.hpp>
@@ -37,10 +37,8 @@ void CWorkspace::init(PHLWORKSPACE self) {
if (RULEFORTHIS.defaultName.has_value())
m_name = RULEFORTHIS.defaultName.value();
- m_focusedWindowHook = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any param) {
- const auto PWINDOW = std::any_cast<PHLWINDOW>(param);
-
- if (PWINDOW == m_lastFocusedWindow.lock())
+ m_focusedWindowHook = Event::bus()->m_events.window.close.listen([this](PHLWINDOW pWindow) {
+ if (pWindow == m_lastFocusedWindow.lock())
m_lastFocusedWindow.reset();
});
@@ -58,22 +56,19 @@ void CWorkspace::init(PHLWORKSPACE self) {
g_pEventManager->postEvent({.event = "createworkspace", .data = m_name});
g_pEventManager->postEvent({.event = "createworkspacev2", .data = std::format("{},{}", m_id, m_name)});
- EMIT_HOOK_EVENT("createWorkspace", this);
+ Event::bus()->m_events.workspace.created.emit(self);
}
CWorkspace::~CWorkspace() {
Log::logger->log(Log::DEBUG, "Destroying workspace ID {}", m_id);
- // check if g_pHookSystem and g_pEventManager exist, they might be destroyed as in when the compositor is closing.
- if (g_pHookSystem)
- g_pHookSystem->unhook(m_focusedWindowHook);
-
if (g_pEventManager) {
g_pEventManager->postEvent({.event = "destroyworkspace", .data = m_name});
g_pEventManager->postEvent({.event = "destroyworkspacev2", .data = std::format("{},{}", m_id, m_name)});
- EMIT_HOOK_EVENT("destroyWorkspace", this);
}
+ Event::bus()->m_events.workspace.removed.emit(m_self);
+
m_events.destroy.emit();
}
diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp
index c39e928f..87d1c2d8 100644
--- a/src/desktop/Workspace.hpp
+++ b/src/desktop/Workspace.hpp
@@ -93,13 +93,13 @@ class CWorkspace {
} m_events;
private:
- void init(PHLWORKSPACE self);
+ void init(PHLWORKSPACE self);
- SP<HOOK_CALLBACK_FN> m_focusedWindowHook;
- bool m_inert = true;
+ CHyprSignalListener m_focusedWindowHook;
+ bool m_inert = true;
- SP<CWorkspace> m_selfPersistent; // for persistent workspaces.
- bool m_persistent = false;
+ SP<CWorkspace> m_selfPersistent; // for persistent workspaces.
+ bool m_persistent = false;
};
inline bool valid(const PHLWORKSPACE& ref) {
diff --git a/src/desktop/history/WindowHistoryTracker.cpp b/src/desktop/history/WindowHistoryTracker.cpp
index edaa2b5e..1dd32164 100644
--- a/src/desktop/history/WindowHistoryTracker.cpp
+++ b/src/desktop/history/WindowHistoryTracker.cpp
@@ -1,7 +1,7 @@
#include "WindowHistoryTracker.hpp"
-#include "../../managers/HookSystemManager.hpp"
#include "../view/Window.hpp"
+#include "../../event/EventBus.hpp"
using namespace Desktop;
using namespace Desktop::History;
@@ -12,18 +12,12 @@ SP<CWindowHistoryTracker> History::windowTracker() {
}
CWindowHistoryTracker::CWindowHistoryTracker() {
- static auto P = g_pHookSystem->hookDynamic("openWindowEarly", [this](void* self, SCallbackInfo& info, std::any data) {
- auto window = std::any_cast<PHLWINDOW>(data);
-
+ static auto P = Event::bus()->m_events.window.openEarly.listen([this](PHLWINDOW pWindow) {
// add a last track
- m_history.insert(m_history.begin(), window);
+ m_history.insert(m_history.begin(), pWindow);
});
- static auto P1 = g_pHookSystem->hookDynamic("activeWindow", [this](void* self, SCallbackInfo& info, std::any data) {
- auto window = std::any_cast<Desktop::View::SWindowActiveEvent>(data).window;
-
- track(window);
- });
+ static auto P1 = Event::bus()->m_events.window.active.listen([this](PHLWINDOW window, uint8_t reason) { track(window); });
}
void CWindowHistoryTracker::track(PHLWINDOW w) {
diff --git a/src/desktop/history/WorkspaceHistoryTracker.cpp b/src/desktop/history/WorkspaceHistoryTracker.cpp
index 0b4ef2fd..daa115f8 100644
--- a/src/desktop/history/WorkspaceHistoryTracker.cpp
+++ b/src/desktop/history/WorkspaceHistoryTracker.cpp
@@ -3,8 +3,8 @@
#include "../../helpers/Monitor.hpp"
#include "../Workspace.hpp"
#include "../state/FocusState.hpp"
-#include "../../managers/HookSystemManager.hpp"
#include "../../managers/eventLoop/EventLoopManager.hpp"
+#include "../../event/EventBus.hpp"
#include "../../config/ConfigValue.hpp"
#include <hyprutils/utils/ScopeGuard.hpp>
@@ -18,14 +18,9 @@ SP<CWorkspaceHistoryTracker> History::workspaceTracker() {
}
CWorkspaceHistoryTracker::CWorkspaceHistoryTracker() {
- static auto P = g_pHookSystem->hookDynamic("workspace", [this](void* self, SCallbackInfo& info, std::any data) {
- auto workspace = std::any_cast<PHLWORKSPACE>(data);
- track(workspace);
- });
-
- static auto P1 = g_pHookSystem->hookDynamic("focusedMon", [this](void* self, SCallbackInfo& info, std::any data) {
- auto mon = std::any_cast<PHLMONITOR>(data);
+ static auto P = Event::bus()->m_events.workspace.active.listen([this](PHLWORKSPACE workspace) { track(workspace); });
+ static auto P1 = Event::bus()->m_events.monitor.focused.listen([this](PHLMONITOR mon) {
// This sucks ASS, but we have to do this because switching to a workspace on another mon will trigger a workspace event right afterwards and we don't
// want to remember the workspace that was not visible there
// TODO: do something about this
diff --git a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp
index a30b65a8..aa7f5b7d 100644
--- a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp
+++ b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp
@@ -4,7 +4,7 @@
#include "../utils/SetUtils.hpp"
#include "../../view/Window.hpp"
#include "../../types/OverridableVar.hpp"
-#include "../../../managers/HookSystemManager.hpp"
+#include "../../../event/EventBus.hpp"
#include <hyprutils/string/String.hpp>
@@ -634,5 +634,5 @@ void CWindowRuleApplicator::propertiesChanged(std::underlying_type_t<eRuleProper
g_pDecorationPositioner->forceRecalcFor(m_window.lock());
// for plugins
- EMIT_HOOK_EVENT("windowUpdateRules", m_window.lock());
+ Event::bus()->m_events.window.updateRules.emit(m_window.lock());
}
diff --git a/src/desktop/state/FocusState.cpp b/src/desktop/state/FocusState.cpp
index 90524b74..c1298766 100644
--- a/src/desktop/state/FocusState.cpp
+++ b/src/desktop/state/FocusState.cpp
@@ -4,13 +4,13 @@
#include "../../protocols/XDGShell.hpp"
#include "../../render/Renderer.hpp"
#include "../../managers/EventManager.hpp"
-#include "../../managers/HookSystemManager.hpp"
#include "../../managers/input/InputManager.hpp"
#include "../../managers/SeatManager.hpp"
#include "../../xwayland/XSurface.hpp"
#include "../../protocols/PointerConstraints.hpp"
#include "managers/animation/DesktopAnimationManager.hpp"
#include "../../layout/LayoutManager.hpp"
+#include "../../event/EventBus.hpp"
using namespace Desktop;
@@ -133,7 +133,7 @@ void CFocusState::rawWindowFocus(PHLWINDOW pWindow, eFocusReason reason, SP<CWLS
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ""});
- EMIT_HOOK_EVENT("activeWindow", Desktop::View::SWindowActiveEvent{nullptr COMMA reason});
+ Event::bus()->m_events.window.active.emit(nullptr, reason);
m_focusSurface.reset();
@@ -200,7 +200,7 @@ void CFocusState::rawWindowFocus(PHLWINDOW pWindow, eFocusReason reason, SP<CWLS
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindow", .data = pWindow->m_class + "," + pWindow->m_title});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindowv2", .data = std::format("{:x}", rc<uintptr_t>(pWindow.get()))});
- EMIT_HOOK_EVENT("activeWindow", Desktop::View::SWindowActiveEvent{pWindow COMMA reason});
+ Event::bus()->m_events.window.active.emit(pWindow, reason);
g_pInputManager->recheckIdleInhibitorStatus();
@@ -233,7 +233,7 @@ void CFocusState::rawSurfaceFocus(SP<CWLSurfaceResource> pSurface, PHLWINDOW pWi
g_pSeatManager->setKeyboardFocus(nullptr);
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindow", .data = ","});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindowv2", .data = ""});
- EMIT_HOOK_EVENT("keyboardFocus", SP<CWLSurfaceResource>{nullptr});
+ Event::bus()->m_events.input.keyboard.focus.emit(nullptr);
m_focusSurface.reset();
return;
}
@@ -249,7 +249,7 @@ void CFocusState::rawSurfaceFocus(SP<CWLSurfaceResource> pSurface, PHLWINDOW pWi
g_pXWaylandManager->activateSurface(pSurface, true);
m_focusSurface = pSurface;
- EMIT_HOOK_EVENT("keyboardFocus", pSurface);
+ Event::bus()->m_events.input.keyboard.focus.emit(pSurface);
const auto SURF = Desktop::View::CWLSurface::fromResource(pSurface);
const auto OLDSURF = Desktop::View::CWLSurface::fromResource(PLASTSURF);
@@ -278,7 +278,7 @@ void CFocusState::rawMonitorFocus(PHLMONITOR pMonitor) {
g_pEventManager->postEvent(SHyprIPCEvent{.event = "focusedmon", .data = pMonitor->m_name + "," + WORKSPACE_NAME});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "focusedmonv2", .data = pMonitor->m_name + "," + WORKSPACE_ID});
- EMIT_HOOK_EVENT("focusedMon", pMonitor);
+ Event::bus()->m_events.monitor.focused.emit(pMonitor);
m_focusMonitor = pMonitor;
}
diff --git a/src/desktop/state/FocusState.hpp b/src/desktop/state/FocusState.hpp
index 76a3538f..71330a3e 100644
--- a/src/desktop/state/FocusState.hpp
+++ b/src/desktop/state/FocusState.hpp
@@ -1,7 +1,7 @@
#pragma once
#include "../DesktopTypes.hpp"
-#include "../../SharedDefs.hpp"
+#include "../../helpers/signal/Signal.hpp"
class CWLSurfaceResource;
@@ -44,7 +44,7 @@ namespace Desktop {
PHLWINDOWREF m_focusWindow;
PHLMONITORREF m_focusMonitor;
- SP<HOOK_CALLBACK_FN> m_windowOpen, m_windowClose;
+ CHyprSignalListener m_windowOpen, m_windowClose;
};
SP<CFocusState> focusState();
diff --git a/src/desktop/view/LayerSurface.cpp b/src/desktop/view/LayerSurface.cpp
index 85e511e2..a10c9d4d 100644
--- a/src/desktop/view/LayerSurface.cpp
+++ b/src/desktop/view/LayerSurface.cpp
@@ -10,8 +10,8 @@
#include "../../config/ConfigManager.hpp"
#include "../../helpers/Monitor.hpp"
#include "../../managers/input/InputManager.hpp"
-#include "../../managers/HookSystemManager.hpp"
#include "../../managers/EventManager.hpp"
+#include "../../event/EventBus.hpp"
using namespace Desktop;
using namespace Desktop::View;
@@ -222,7 +222,7 @@ void CLayerSurface::onMap() {
m_fadingOut = false;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "openlayer", .data = m_namespace});
- EMIT_HOOK_EVENT("openLayer", m_self.lock());
+ Event::bus()->m_events.layer.opened.emit(m_self.lock());
g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), PMONITOR->m_scale);
g_pCompositor->setPreferredTransformForSurface(m_wlSurface->resource(), PMONITOR->m_transform);
@@ -232,7 +232,7 @@ void CLayerSurface::onUnmap() {
Log::logger->log(Log::DEBUG, "LayerSurface {:x} unmapped", rc<uintptr_t>(m_layerSurface.get()));
g_pEventManager->postEvent(SHyprIPCEvent{.event = "closelayer", .data = m_layerSurface->m_layerNamespace});
- EMIT_HOOK_EVENT("closeLayer", m_self.lock());
+ Event::bus()->m_events.layer.closed.emit(m_self.lock());
std::erase_if(g_pInputManager->m_exclusiveLSes, [this](const auto& other) { return !other || other == m_self; });
diff --git a/src/desktop/view/Window.cpp b/src/desktop/view/Window.cpp
index b43e181c..5660cda6 100644
--- a/src/desktop/view/Window.cpp
+++ b/src/desktop/view/Window.cpp
@@ -39,7 +39,6 @@
#include "../../helpers/math/Expression.hpp"
#include "../../managers/XWaylandManager.hpp"
#include "../../render/Renderer.hpp"
-#include "../../managers/HookSystemManager.hpp"
#include "../../managers/EventManager.hpp"
#include "../../managers/input/InputManager.hpp"
#include "../../managers/PointerManager.hpp"
@@ -48,6 +47,7 @@
#include "../../layout/LayoutManager.hpp"
#include "../../layout/target/WindowTarget.hpp"
#include "../../layout/target/WindowGroupTarget.hpp"
+#include "../../event/EventBus.hpp"
#include <hyprutils/string/String.hpp>
@@ -521,7 +521,7 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) {
if (valid(pWorkspace)) {
g_pEventManager->postEvent(SHyprIPCEvent{.event = "movewindow", .data = std::format("{:x},{}", rc<uintptr_t>(this), pWorkspace->m_name)});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "movewindowv2", .data = std::format("{:x},{},{}", rc<uintptr_t>(this), pWorkspace->m_id, pWorkspace->m_name)});
- EMIT_HOOK_EVENT("moveWindow", (std::vector<std::any>{m_self.lock(), pWorkspace}));
+ Event::bus()->m_events.window.moveToWorkspace.emit(m_self.lock(), pWorkspace);
}
if (const auto SWALLOWED = m_swallowed.lock()) {
@@ -1037,7 +1037,7 @@ void CWindow::activate(bool force) {
m_isUrgent = true;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "urgent", .data = std::format("{:x}", rc<uintptr_t>(this))});
- EMIT_HOOK_EVENT("urgent", m_self.lock());
+ Event::bus()->m_events.window.urgent.emit(m_self.lock());
if (!force &&
(!m_ruleApplicator->focusOnActivate().valueOr(*PFOCUSONACTIVATE) || (m_suppressedEvents & SUPPRESS_ACTIVATE_FOCUSONLY) || (m_suppressedEvents & SUPPRESS_ACTIVATE)))
@@ -1098,7 +1098,7 @@ void CWindow::onUpdateMeta() {
m_title = NEWTITLE;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "windowtitle", .data = std::format("{:x}", rc<uintptr_t>(this))});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "windowtitlev2", .data = std::format("{:x},{}", rc<uintptr_t>(this), m_title)});
- EMIT_HOOK_EVENT("windowTitle", m_self.lock());
+ Event::bus()->m_events.window.title.emit(m_self.lock());
if (m_self == Desktop::focusState()->window()) { // if it's the active, let's post an event to update others
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindow", .data = m_class + "," + m_title});
@@ -1115,6 +1115,8 @@ void CWindow::onUpdateMeta() {
if (m_class != NEWCLASS) {
m_class = NEWCLASS;
+ Event::bus()->m_events.window.class_.emit(m_self.lock());
+
if (m_self == Desktop::focusState()->window()) { // if it's the active, let's post an event to update others
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindow", .data = m_class + "," + m_title});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindowv2", .data = std::format("{:x}", rc<uintptr_t>(this))});
@@ -1945,7 +1947,7 @@ void CWindow::mapWindow() {
// emit the IPC event before the layout might focus the window to avoid a focus event first
g_pEventManager->postEvent(SHyprIPCEvent{"openwindow", std::format("{:x},{},{},{}", m_self.lock(), PWORKSPACE->m_name, m_class, m_title)});
- EMIT_HOOK_EVENT("openWindowEarly", m_self.lock());
+ Event::bus()->m_events.window.openEarly.emit(m_self.lock());
if (*PAUTOGROUP // auto_group enabled
&& Desktop::focusState()->window() // focused window exists
@@ -2078,7 +2080,7 @@ void CWindow::mapWindow() {
Log::logger->log(Log::DEBUG, "Map request dispatched, monitor {}, window pos: {:5j}, window size: {:5j}", PMONITOR->m_name, m_realPosition->goal(), m_realSize->goal());
// emit the hook event here after basic stuff has been initialized
- EMIT_HOOK_EVENT("openWindow", m_self.lock());
+ Event::bus()->m_events.window.open.emit(m_self.lock());
// apply data from default decos. Borders, shadows.
g_pDecorationPositioner->forceRecalcFor(m_self.lock());
@@ -2136,7 +2138,7 @@ void CWindow::unmapWindow() {
m_events.unmap.emit();
g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", std::format("{:x}", m_self.lock())});
- EMIT_HOOK_EVENT("closeWindow", m_self.lock());
+ Event::bus()->m_events.window.close.emit(m_self.lock());
if (m_isFloating && !m_isX11 && m_ruleApplicator->persistentSize().valueOrDefault()) {
Log::logger->log(Log::DEBUG, "storing floating size {}x{} for window {}::{} on close", m_realSize->value().x, m_realSize->value().y, m_class, m_title);
@@ -2250,7 +2252,7 @@ void CWindow::unmapWindow() {
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ""});
- EMIT_HOOK_EVENT("activeWindow", Desktop::View::SWindowActiveEvent{nullptr COMMA FOCUS_REASON_OTHER});
+ Event::bus()->m_events.window.active.emit(m_self.lock(), FOCUS_REASON_OTHER);
}
} else {
Log::logger->log(Log::DEBUG, "Unmapped was not focused, ignoring a refocus.");