summaryrefslogtreecommitdiff
path: root/src/event
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/event
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/event')
-rw-r--r--src/event/EventBus.cpp8
-rw-r--r--src/event/EventBus.hpp142
2 files changed, 150 insertions, 0 deletions
diff --git a/src/event/EventBus.cpp b/src/event/EventBus.cpp
new file mode 100644
index 00000000..f06c3984
--- /dev/null
+++ b/src/event/EventBus.cpp
@@ -0,0 +1,8 @@
+#include "EventBus.hpp"
+
+using namespace Event;
+
+UP<CEventBus>& Event::bus() {
+ static UP<CEventBus> p = makeUnique<CEventBus>();
+ return p;
+}
diff --git a/src/event/EventBus.hpp b/src/event/EventBus.hpp
new file mode 100644
index 00000000..8f59acbd
--- /dev/null
+++ b/src/event/EventBus.hpp
@@ -0,0 +1,142 @@
+#pragma once
+
+#include "../helpers/memory/Memory.hpp"
+#include "../helpers/signal/Signal.hpp"
+#include "../helpers/math/Math.hpp"
+
+#include "../devices/IPointer.hpp"
+#include "../devices/IKeyboard.hpp"
+#include "../devices/Tablet.hpp"
+#include "../devices/ITouch.hpp"
+
+#include "../desktop/DesktopTypes.hpp"
+
+#include "../SharedDefs.hpp"
+
+namespace Desktop {
+ enum eFocusReason : uint8_t;
+}
+namespace Event {
+ struct SCallbackInfo {
+ bool cancelled = false; /* on cancellable events, will cancel the event. */
+ };
+
+ class CEventBus {
+ public:
+ CEventBus() = default;
+ ~CEventBus() = default;
+
+ template <typename... Args>
+ using Event = CSignalT<Args...>;
+
+ template <typename... Args>
+ using Cancellable = CSignalT<Args..., SCallbackInfo&>;
+
+ struct {
+ Event<> ready;
+ Event<> tick;
+
+ struct {
+ Event<PHLWINDOW> open;
+ Event<PHLWINDOW> openEarly;
+ Event<PHLWINDOW> destroy;
+ Event<PHLWINDOW> close;
+ Event<PHLWINDOW, Desktop::eFocusReason> active;
+ Event<PHLWINDOW> urgent;
+ Event<PHLWINDOW> title;
+ Event<PHLWINDOW> class_;
+ Event<PHLWINDOW> pin;
+ Event<PHLWINDOW> fullscreen;
+ Event<PHLWINDOW> updateRules;
+ Event<PHLWINDOW, PHLWORKSPACE> moveToWorkspace;
+ } window;
+
+ struct {
+ Event<PHLLS> opened;
+ Event<PHLLS> closed;
+ } layer;
+
+ struct {
+ struct {
+ Cancellable<Vector2D> move;
+ Cancellable<IPointer::SButtonEvent> button;
+ Cancellable<IPointer::SAxisEvent> axis;
+ } mouse;
+
+ struct {
+ Cancellable<IKeyboard::SKeyEvent> key;
+ Event<SP<IKeyboard>, const std::string&> layout;
+ Event<SP<CWLSurfaceResource>> focus;
+ } keyboard;
+
+ struct {
+ Cancellable<CTablet::SAxisEvent> axis;
+ Cancellable<CTablet::SButtonEvent> button;
+ Cancellable<CTablet::SProximityEvent> proximity;
+ Cancellable<CTablet::STipEvent> tip;
+ } tablet;
+
+ struct {
+ Cancellable<ITouch::SCancelEvent> cancel;
+ Cancellable<ITouch::SDownEvent> down;
+ Cancellable<ITouch::SUpEvent> up;
+ Cancellable<ITouch::SMotionEvent> motion;
+ } touch;
+ } input;
+
+ struct {
+ Event<PHLMONITOR> pre;
+ Event<eRenderStage> stage;
+ } render;
+
+ struct {
+ Event<bool /* state start/stop */, uint8_t /* eScreenshareType */, const std::string& /* name */> state;
+ } screenshare;
+
+ struct {
+ struct {
+ Cancellable<IPointer::SSwipeBeginEvent> begin;
+ Cancellable<IPointer::SSwipeEndEvent> end;
+ Cancellable<IPointer::SSwipeUpdateEvent> update;
+ } swipe;
+
+ struct {
+ Cancellable<IPointer::SPinchBeginEvent> begin;
+ Cancellable<IPointer::SPinchEndEvent> end;
+ Cancellable<IPointer::SPinchUpdateEvent> update;
+ } pinch;
+ } gesture;
+
+ struct {
+ Event<PHLMONITOR> newMon;
+ Event<PHLMONITOR> preAdded;
+ Event<PHLMONITOR> added;
+ Event<PHLMONITOR> preRemoved;
+ Event<PHLMONITOR> removed;
+ Event<PHLMONITOR> preCommit;
+ Event<PHLMONITOR> focused;
+
+ Event<> layoutChanged;
+ } monitor;
+
+ struct {
+ Event<PHLWORKSPACE, PHLMONITOR> moveToMonitor;
+ Event<PHLWORKSPACE> active;
+ Event<PHLWORKSPACEREF> created;
+ Event<PHLWORKSPACEREF> removed;
+ } workspace;
+
+ struct {
+ Event<> preReload;
+ Event<> reloaded;
+ } config;
+
+ struct {
+ Event<const std::string&> submap;
+ } keybinds;
+
+ } m_events;
+ };
+
+ UP<CEventBus>& bus();
+}; \ No newline at end of file