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

@ -62,7 +62,6 @@
#include "managers/animation/AnimationManager.hpp" #include "managers/animation/AnimationManager.hpp"
#include "managers/animation/DesktopAnimationManager.hpp" #include "managers/animation/DesktopAnimationManager.hpp"
#include "managers/EventManager.hpp" #include "managers/EventManager.hpp"
#include "managers/HookSystemManager.hpp"
#include "managers/ProtocolManager.hpp" #include "managers/ProtocolManager.hpp"
#include "managers/WelcomeManager.hpp" #include "managers/WelcomeManager.hpp"
#include "render/AsyncResourceGatherer.hpp" #include "render/AsyncResourceGatherer.hpp"
@ -74,6 +73,7 @@
#include "i18n/Engine.hpp" #include "i18n/Engine.hpp"
#include "layout/LayoutManager.hpp" #include "layout/LayoutManager.hpp"
#include "layout/target/WindowTarget.hpp" #include "layout/target/WindowTarget.hpp"
#include "event/EventBus.hpp"
#include <hyprutils/string/String.hpp> #include <hyprutils/string/String.hpp>
#include <aquamarine/input/Input.hpp> #include <aquamarine/input/Input.hpp>
@ -106,11 +106,6 @@ static void handleUnrecoverableSignal(int sig) {
signal(SIGABRT, SIG_DFL); signal(SIGABRT, SIG_DFL);
signal(SIGSEGV, SIG_DFL); signal(SIGSEGV, SIG_DFL);
if (g_pHookSystem && g_pHookSystem->m_currentEventPlugin) {
longjmp(g_pHookSystem->m_hookFaultJumpBuf, 1);
return;
}
// Kill the program if the crash-reporter is caught in a deadlock. // Kill the program if the crash-reporter is caught in a deadlock.
signal(SIGALRM, [](int _) { signal(SIGALRM, [](int _) {
char const* msg = "\nCrashReporter exceeded timeout, forcefully exiting\n"; char const* msg = "\nCrashReporter exceeded timeout, forcefully exiting\n";
@ -286,7 +281,6 @@ static bool filterGlobals(const wl_client* client, const wl_global* global, void
// //
void CCompositor::initServer(std::string socketName, int socketFd) { void CCompositor::initServer(std::string socketName, int socketFd) {
if (m_onlyConfigVerification) { if (m_onlyConfigVerification) {
g_pHookSystem = makeUnique<CHookSystemManager>();
g_pKeybindManager = makeUnique<CKeybindManager>(); g_pKeybindManager = makeUnique<CKeybindManager>();
g_pAnimationManager = makeUnique<CHyprAnimationManager>(); g_pAnimationManager = makeUnique<CHyprAnimationManager>();
g_pConfigManager = makeUnique<CConfigManager>(); g_pConfigManager = makeUnique<CConfigManager>();
@ -597,7 +591,6 @@ void CCompositor::cleanup() {
g_pHyprError.reset(); g_pHyprError.reset();
g_pConfigManager.reset(); g_pConfigManager.reset();
g_pKeybindManager.reset(); g_pKeybindManager.reset();
g_pHookSystem.reset();
g_pXWaylandManager.reset(); g_pXWaylandManager.reset();
g_pPointerManager.reset(); g_pPointerManager.reset();
g_pSeatManager.reset(); g_pSeatManager.reset();
@ -626,9 +619,6 @@ void CCompositor::initManagers(eManagersInitStage stage) {
Log::logger->log(Log::DEBUG, "Creating the EventLoopManager!"); Log::logger->log(Log::DEBUG, "Creating the EventLoopManager!");
g_pEventLoopManager = makeUnique<CEventLoopManager>(m_wlDisplay, m_wlEventLoop); g_pEventLoopManager = makeUnique<CEventLoopManager>(m_wlDisplay, m_wlEventLoop);
Log::logger->log(Log::DEBUG, "Creating the HookSystem!");
g_pHookSystem = makeUnique<CHookSystemManager>();
Log::logger->log(Log::DEBUG, "Creating the KeybindManager!"); Log::logger->log(Log::DEBUG, "Creating the KeybindManager!");
g_pKeybindManager = makeUnique<CKeybindManager>(); g_pKeybindManager = makeUnique<CKeybindManager>();
@ -799,7 +789,8 @@ void CCompositor::startCompositor() {
createLockFile(); createLockFile();
EMIT_HOOK_EVENT("ready", nullptr); Event::bus()->m_events.ready.emit();
if (m_watchdogWriteFd.isValid()) if (m_watchdogWriteFd.isValid())
write(m_watchdogWriteFd.get(), "vax", 3); write(m_watchdogWriteFd.get(), "vax", 3);
@ -879,7 +870,7 @@ PHLMONITOR CCompositor::getMonitorFromVector(const Vector2D& point) {
void CCompositor::removeWindowFromVectorSafe(PHLWINDOW pWindow) { void CCompositor::removeWindowFromVectorSafe(PHLWINDOW pWindow) {
if (!pWindow->m_fadingOut) { if (!pWindow->m_fadingOut) {
EMIT_HOOK_EVENT("destroyWindow", pWindow); Event::bus()->m_events.window.destroy.emit(pWindow);
std::erase_if(m_windows, [&](SP<Desktop::View::CWindow>& el) { return el == pWindow; }); std::erase_if(m_windows, [&](SP<Desktop::View::CWindow>& el) { return el == pWindow; });
std::erase_if(m_windowsFadingOut, [&](PHLWINDOWREF el) { return el.lock() == pWindow; }); std::erase_if(m_windowsFadingOut, [&](PHLWINDOWREF el) { return el.lock() == pWindow; });
@ -1834,17 +1825,17 @@ void CCompositor::swapActiveWorkspaces(PHLMONITOR pMonitorA, PHLMONITOR pMonitor
const auto PNEWWORKSPACE = pMonitorA->m_id == Desktop::focusState()->monitor()->m_id ? PWORKSPACEB : PWORKSPACEA; const auto PNEWWORKSPACE = pMonitorA->m_id == Desktop::focusState()->monitor()->m_id ? PWORKSPACEB : PWORKSPACEA;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "workspace", .data = PNEWWORKSPACE->m_name}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "workspace", .data = PNEWWORKSPACE->m_name});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "workspacev2", .data = std::format("{},{}", PNEWWORKSPACE->m_id, PNEWWORKSPACE->m_name)}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "workspacev2", .data = std::format("{},{}", PNEWWORKSPACE->m_id, PNEWWORKSPACE->m_name)});
EMIT_HOOK_EVENT("workspace", PNEWWORKSPACE); Event::bus()->m_events.workspace.active.emit(PNEWWORKSPACE);
} }
// event // events
g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspace", .data = PWORKSPACEA->m_name + "," + pMonitorB->m_name}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspace", .data = PWORKSPACEA->m_name + "," + pMonitorB->m_name});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspacev2", .data = std::format("{},{},{}", PWORKSPACEA->m_id, PWORKSPACEA->m_name, pMonitorB->m_name)}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspacev2", .data = std::format("{},{},{}", PWORKSPACEA->m_id, PWORKSPACEA->m_name, pMonitorB->m_name)});
EMIT_HOOK_EVENT("moveWorkspace", (std::vector<std::any>{PWORKSPACEA, pMonitorB}));
g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspace", .data = PWORKSPACEB->m_name + "," + pMonitorA->m_name}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspace", .data = PWORKSPACEB->m_name + "," + pMonitorA->m_name});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspacev2", .data = std::format("{},{},{}", PWORKSPACEB->m_id, PWORKSPACEB->m_name, pMonitorA->m_name)}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspacev2", .data = std::format("{},{},{}", PWORKSPACEB->m_id, PWORKSPACEB->m_name, pMonitorA->m_name)});
EMIT_HOOK_EVENT("moveWorkspace", (std::vector<std::any>{PWORKSPACEB, pMonitorA})); Event::bus()->m_events.workspace.moveToMonitor.emit(PWORKSPACEA, pMonitorB);
Event::bus()->m_events.workspace.moveToMonitor.emit(PWORKSPACEB, pMonitorA);
} }
PHLMONITOR CCompositor::getMonitorFromString(const std::string& name) { PHLMONITOR CCompositor::getMonitorFromString(const std::string& name) {
@ -2054,7 +2045,8 @@ void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, PHLMONITOR pMo
// event // event
g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspace", .data = pWorkspace->m_name + "," + pMonitor->m_name}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspace", .data = pWorkspace->m_name + "," + pMonitor->m_name});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspacev2", .data = std::format("{},{},{}", pWorkspace->m_id, pWorkspace->m_name, pMonitor->m_name)}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "moveworkspacev2", .data = std::format("{},{},{}", pWorkspace->m_id, pWorkspace->m_name, pMonitor->m_name)});
EMIT_HOOK_EVENT("moveWorkspace", (std::vector<std::any>{pWorkspace, pMonitor}));
Event::bus()->m_events.workspace.moveToMonitor.emit(pWorkspace, pMonitor);
} }
bool CCompositor::workspaceIDOutOfBounds(const WORKSPACEID& id) { bool CCompositor::workspaceIDOutOfBounds(const WORKSPACEID& id) {
@ -2149,7 +2141,7 @@ void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, Desktop::Vie
PWINDOW->m_fullscreenState.internal = state.internal; PWINDOW->m_fullscreenState.internal = state.internal;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "fullscreen", .data = std::to_string(sc<int>(EFFECTIVE_MODE) != FSMODE_NONE)}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "fullscreen", .data = std::to_string(sc<int>(EFFECTIVE_MODE) != FSMODE_NONE)});
EMIT_HOOK_EVENT("fullscreen", PWINDOW); Event::bus()->m_events.window.fullscreen.emit(PWINDOW);
PWINDOW->m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_FULLSCREEN | Desktop::Rule::RULE_PROP_FULLSCREENSTATE_CLIENT | PWINDOW->m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_FULLSCREEN | Desktop::Rule::RULE_PROP_FULLSCREENSTATE_CLIENT |
Desktop::Rule::RULE_PROP_FULLSCREENSTATE_INTERNAL | Desktop::Rule::RULE_PROP_ON_WORKSPACE); Desktop::Rule::RULE_PROP_FULLSCREENSTATE_INTERNAL | Desktop::Rule::RULE_PROP_ON_WORKSPACE);
@ -2897,7 +2889,7 @@ void CCompositor::onNewMonitor(SP<Aquamarine::IOutput> output) {
PNEWMONITOR->m_id = FALLBACK ? MONITOR_INVALID : g_pCompositor->getNextAvailableMonitorID(output->name); PNEWMONITOR->m_id = FALLBACK ? MONITOR_INVALID : g_pCompositor->getNextAvailableMonitorID(output->name);
PNEWMONITOR->m_isUnsafeFallback = FALLBACK; PNEWMONITOR->m_isUnsafeFallback = FALLBACK;
EMIT_HOOK_EVENT("newMonitor", PNEWMONITOR); Event::bus()->m_events.monitor.newMon.emit(PNEWMONITOR);
if (!FALLBACK) if (!FALLBACK)
PNEWMONITOR->onConnect(false); PNEWMONITOR->onConnect(false);

View file

@ -38,10 +38,6 @@ enum eInputType : uint8_t {
INPUT_TYPE_MOTION INPUT_TYPE_MOTION
}; };
struct SCallbackInfo {
bool cancelled = false; /* on cancellable events, will cancel the event. */
};
enum eHyprCtlOutputFormat : uint8_t { enum eHyprCtlOutputFormat : uint8_t {
FORMAT_NORMAL = 0, FORMAT_NORMAL = 0,
FORMAT_JSON FORMAT_JSON
@ -62,5 +58,3 @@ struct SDispatchResult {
using WINDOWID = int64_t; using WINDOWID = int64_t;
using MONITORID = int64_t; using MONITORID = int64_t;
using WORKSPACEID = int64_t; using WORKSPACEID = int64_t;
using HOOK_CALLBACK_FN = std::function<void(void*, SCallbackInfo&, std::any)>;

View file

@ -42,7 +42,8 @@
#include "../managers/input/trackpad/gestures/FullscreenGesture.hpp" #include "../managers/input/trackpad/gestures/FullscreenGesture.hpp"
#include "../managers/input/trackpad/gestures/CursorZoomGesture.hpp" #include "../managers/input/trackpad/gestures/CursorZoomGesture.hpp"
#include "../managers/HookSystemManager.hpp" #include "../event/EventBus.hpp"
#include "../protocols/types/ContentType.hpp" #include "../protocols/types/ContentType.hpp"
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
@ -1066,7 +1067,7 @@ static void clearHlVersionVars() {
} }
void CConfigManager::reload() { void CConfigManager::reload() {
EMIT_HOOK_EVENT("preConfigReload", nullptr); Event::bus()->m_events.config.preReload.emit();
setDefaultAnimationVars(); setDefaultAnimationVars();
resetHLConfig(); resetHLConfig();
m_configCurrentPath = getMainConfigPath(); m_configCurrentPath = getMainConfigPath();
@ -1458,7 +1459,7 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
// update layouts // update layouts
Layout::Supplementary::algoMatcher()->updateWorkspaceLayouts(); Layout::Supplementary::algoMatcher()->updateWorkspaceLayouts();
EMIT_HOOK_EVENT("configReloaded", nullptr); Event::bus()->m_events.config.reloaded.emit();
if (g_pEventManager) if (g_pEventManager)
g_pEventManager->postEvent(SHyprIPCEvent{"configreloaded", ""}); g_pEventManager->postEvent(SHyprIPCEvent{"configreloaded", ""});
} }
@ -1747,7 +1748,7 @@ void CConfigManager::performMonitorReload() {
m_wantsMonitorReload = false; m_wantsMonitorReload = false;
EMIT_HOOK_EVENT("monitorLayoutChanged", nullptr); Event::bus()->m_events.monitor.layoutChanged.emit();
} }
void* const* CConfigManager::getConfigValuePtr(const std::string& val) { void* const* CConfigManager::getConfigValuePtr(const std::string& val) {

View file

@ -4,9 +4,9 @@
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../config/ConfigValue.hpp" #include "../config/ConfigValue.hpp"
#include "../render/pass/TexPassElement.hpp" #include "../render/pass/TexPassElement.hpp"
#include "../event/EventBus.hpp"
#include "../managers/animation/AnimationManager.hpp" #include "../managers/animation/AnimationManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"
static inline auto iconBackendFromLayout(PangoLayout* layout) { static inline auto iconBackendFromLayout(PangoLayout* layout) {
@ -22,7 +22,7 @@ static inline auto iconBackendFromLayout(PangoLayout* layout) {
} }
CHyprNotificationOverlay::CHyprNotificationOverlay() { CHyprNotificationOverlay::CHyprNotificationOverlay() {
static auto P = g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.monitor.focused.listen([&](PHLMONITOR mon) {
if (m_notifications.empty()) if (m_notifications.empty())
return; return;

View file

@ -1,9 +1,8 @@
#include "Logger.hpp" #include "Logger.hpp"
#include "RollingLogFollow.hpp" #include "RollingLogFollow.hpp"
#include "../../defines.hpp" #include "../../event/EventBus.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../config/ConfigValue.hpp" #include "../../config/ConfigValue.hpp"
using namespace Log; using namespace Log;
@ -39,7 +38,7 @@ void CLogger::initIS(const std::string_view& IS) {
} }
void CLogger::initCallbacks() { void CLogger::initCallbacks() {
static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { recheckCfg(); }); static auto P = Event::bus()->m_events.config.reloaded.listen([this]() { recheckCfg(); });
recheckCfg(); recheckCfg();
} }

View file

@ -5,9 +5,9 @@
#include "config/ConfigManager.hpp" #include "config/ConfigManager.hpp"
#include "managers/animation/AnimationManager.hpp" #include "managers/animation/AnimationManager.hpp"
#include "../managers/EventManager.hpp" #include "../managers/EventManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../layout/space/Space.hpp" #include "../layout/space/Space.hpp"
#include "../layout/supplementary/WorkspaceAlgoMatcher.hpp" #include "../layout/supplementary/WorkspaceAlgoMatcher.hpp"
#include "../event/EventBus.hpp"
#include <hyprutils/animation/AnimatedVariable.hpp> #include <hyprutils/animation/AnimatedVariable.hpp>
#include <hyprutils/string/String.hpp> #include <hyprutils/string/String.hpp>
@ -37,10 +37,8 @@ void CWorkspace::init(PHLWORKSPACE self) {
if (RULEFORTHIS.defaultName.has_value()) if (RULEFORTHIS.defaultName.has_value())
m_name = RULEFORTHIS.defaultName.value(); m_name = RULEFORTHIS.defaultName.value();
m_focusedWindowHook = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any param) { m_focusedWindowHook = Event::bus()->m_events.window.close.listen([this](PHLWINDOW pWindow) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(param); if (pWindow == m_lastFocusedWindow.lock())
if (PWINDOW == m_lastFocusedWindow.lock())
m_lastFocusedWindow.reset(); m_lastFocusedWindow.reset();
}); });
@ -58,22 +56,19 @@ void CWorkspace::init(PHLWORKSPACE self) {
g_pEventManager->postEvent({.event = "createworkspace", .data = m_name}); g_pEventManager->postEvent({.event = "createworkspace", .data = m_name});
g_pEventManager->postEvent({.event = "createworkspacev2", .data = std::format("{},{}", m_id, 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() { CWorkspace::~CWorkspace() {
Log::logger->log(Log::DEBUG, "Destroying workspace ID {}", m_id); 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) { if (g_pEventManager) {
g_pEventManager->postEvent({.event = "destroyworkspace", .data = m_name}); g_pEventManager->postEvent({.event = "destroyworkspace", .data = m_name});
g_pEventManager->postEvent({.event = "destroyworkspacev2", .data = std::format("{},{}", m_id, 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(); m_events.destroy.emit();
} }

View file

@ -93,13 +93,13 @@ class CWorkspace {
} m_events; } m_events;
private: private:
void init(PHLWORKSPACE self); void init(PHLWORKSPACE self);
SP<HOOK_CALLBACK_FN> m_focusedWindowHook; CHyprSignalListener m_focusedWindowHook;
bool m_inert = true; bool m_inert = true;
SP<CWorkspace> m_selfPersistent; // for persistent workspaces. SP<CWorkspace> m_selfPersistent; // for persistent workspaces.
bool m_persistent = false; bool m_persistent = false;
}; };
inline bool valid(const PHLWORKSPACE& ref) { inline bool valid(const PHLWORKSPACE& ref) {

View file

@ -1,7 +1,7 @@
#include "WindowHistoryTracker.hpp" #include "WindowHistoryTracker.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../view/Window.hpp" #include "../view/Window.hpp"
#include "../../event/EventBus.hpp"
using namespace Desktop; using namespace Desktop;
using namespace Desktop::History; using namespace Desktop::History;
@ -12,18 +12,12 @@ SP<CWindowHistoryTracker> History::windowTracker() {
} }
CWindowHistoryTracker::CWindowHistoryTracker() { CWindowHistoryTracker::CWindowHistoryTracker() {
static auto P = g_pHookSystem->hookDynamic("openWindowEarly", [this](void* self, SCallbackInfo& info, std::any data) { static auto P = Event::bus()->m_events.window.openEarly.listen([this](PHLWINDOW pWindow) {
auto window = std::any_cast<PHLWINDOW>(data);
// add a last track // 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) { static auto P1 = Event::bus()->m_events.window.active.listen([this](PHLWINDOW window, uint8_t reason) { track(window); });
auto window = std::any_cast<Desktop::View::SWindowActiveEvent>(data).window;
track(window);
});
} }
void CWindowHistoryTracker::track(PHLWINDOW w) { void CWindowHistoryTracker::track(PHLWINDOW w) {

View file

@ -3,8 +3,8 @@
#include "../../helpers/Monitor.hpp" #include "../../helpers/Monitor.hpp"
#include "../Workspace.hpp" #include "../Workspace.hpp"
#include "../state/FocusState.hpp" #include "../state/FocusState.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../managers/eventLoop/EventLoopManager.hpp" #include "../../managers/eventLoop/EventLoopManager.hpp"
#include "../../event/EventBus.hpp"
#include "../../config/ConfigValue.hpp" #include "../../config/ConfigValue.hpp"
#include <hyprutils/utils/ScopeGuard.hpp> #include <hyprutils/utils/ScopeGuard.hpp>
@ -18,14 +18,9 @@ SP<CWorkspaceHistoryTracker> History::workspaceTracker() {
} }
CWorkspaceHistoryTracker::CWorkspaceHistoryTracker() { CWorkspaceHistoryTracker::CWorkspaceHistoryTracker() {
static auto P = g_pHookSystem->hookDynamic("workspace", [this](void* self, SCallbackInfo& info, std::any data) { static auto P = Event::bus()->m_events.workspace.active.listen([this](PHLWORKSPACE workspace) { track(workspace); });
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 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 // 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 // want to remember the workspace that was not visible there
// TODO: do something about this // TODO: do something about this

View file

@ -4,7 +4,7 @@
#include "../utils/SetUtils.hpp" #include "../utils/SetUtils.hpp"
#include "../../view/Window.hpp" #include "../../view/Window.hpp"
#include "../../types/OverridableVar.hpp" #include "../../types/OverridableVar.hpp"
#include "../../../managers/HookSystemManager.hpp" #include "../../../event/EventBus.hpp"
#include <hyprutils/string/String.hpp> #include <hyprutils/string/String.hpp>
@ -634,5 +634,5 @@ void CWindowRuleApplicator::propertiesChanged(std::underlying_type_t<eRuleProper
g_pDecorationPositioner->forceRecalcFor(m_window.lock()); g_pDecorationPositioner->forceRecalcFor(m_window.lock());
// for plugins // for plugins
EMIT_HOOK_EVENT("windowUpdateRules", m_window.lock()); Event::bus()->m_events.window.updateRules.emit(m_window.lock());
} }

View file

@ -4,13 +4,13 @@
#include "../../protocols/XDGShell.hpp" #include "../../protocols/XDGShell.hpp"
#include "../../render/Renderer.hpp" #include "../../render/Renderer.hpp"
#include "../../managers/EventManager.hpp" #include "../../managers/EventManager.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../managers/input/InputManager.hpp" #include "../../managers/input/InputManager.hpp"
#include "../../managers/SeatManager.hpp" #include "../../managers/SeatManager.hpp"
#include "../../xwayland/XSurface.hpp" #include "../../xwayland/XSurface.hpp"
#include "../../protocols/PointerConstraints.hpp" #include "../../protocols/PointerConstraints.hpp"
#include "managers/animation/DesktopAnimationManager.hpp" #include "managers/animation/DesktopAnimationManager.hpp"
#include "../../layout/LayoutManager.hpp" #include "../../layout/LayoutManager.hpp"
#include "../../event/EventBus.hpp"
using namespace Desktop; 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{"activewindow", ","});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ""}); 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(); 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 = "activewindow", .data = pWindow->m_class + "," + pWindow->m_title});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindowv2", .data = std::format("{:x}", rc<uintptr_t>(pWindow.get()))}); 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(); g_pInputManager->recheckIdleInhibitorStatus();
@ -233,7 +233,7 @@ void CFocusState::rawSurfaceFocus(SP<CWLSurfaceResource> pSurface, PHLWINDOW pWi
g_pSeatManager->setKeyboardFocus(nullptr); g_pSeatManager->setKeyboardFocus(nullptr);
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindow", .data = ","}); g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindow", .data = ","});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindowv2", .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(); m_focusSurface.reset();
return; return;
} }
@ -249,7 +249,7 @@ void CFocusState::rawSurfaceFocus(SP<CWLSurfaceResource> pSurface, PHLWINDOW pWi
g_pXWaylandManager->activateSurface(pSurface, true); g_pXWaylandManager->activateSurface(pSurface, true);
m_focusSurface = pSurface; 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 SURF = Desktop::View::CWLSurface::fromResource(pSurface);
const auto OLDSURF = Desktop::View::CWLSurface::fromResource(PLASTSURF); 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 = "focusedmon", .data = pMonitor->m_name + "," + WORKSPACE_NAME});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "focusedmonv2", .data = pMonitor->m_name + "," + WORKSPACE_ID}); 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; m_focusMonitor = pMonitor;
} }

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "../DesktopTypes.hpp" #include "../DesktopTypes.hpp"
#include "../../SharedDefs.hpp" #include "../../helpers/signal/Signal.hpp"
class CWLSurfaceResource; class CWLSurfaceResource;
@ -44,7 +44,7 @@ namespace Desktop {
PHLWINDOWREF m_focusWindow; PHLWINDOWREF m_focusWindow;
PHLMONITORREF m_focusMonitor; PHLMONITORREF m_focusMonitor;
SP<HOOK_CALLBACK_FN> m_windowOpen, m_windowClose; CHyprSignalListener m_windowOpen, m_windowClose;
}; };
SP<CFocusState> focusState(); SP<CFocusState> focusState();

View file

@ -10,8 +10,8 @@
#include "../../config/ConfigManager.hpp" #include "../../config/ConfigManager.hpp"
#include "../../helpers/Monitor.hpp" #include "../../helpers/Monitor.hpp"
#include "../../managers/input/InputManager.hpp" #include "../../managers/input/InputManager.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../managers/EventManager.hpp" #include "../../managers/EventManager.hpp"
#include "../../event/EventBus.hpp"
using namespace Desktop; using namespace Desktop;
using namespace Desktop::View; using namespace Desktop::View;
@ -222,7 +222,7 @@ void CLayerSurface::onMap() {
m_fadingOut = false; m_fadingOut = false;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "openlayer", .data = m_namespace}); 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->setPreferredScaleForSurface(m_wlSurface->resource(), PMONITOR->m_scale);
g_pCompositor->setPreferredTransformForSurface(m_wlSurface->resource(), PMONITOR->m_transform); 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())); 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}); 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; }); std::erase_if(g_pInputManager->m_exclusiveLSes, [this](const auto& other) { return !other || other == m_self; });

View file

@ -39,7 +39,6 @@
#include "../../helpers/math/Expression.hpp" #include "../../helpers/math/Expression.hpp"
#include "../../managers/XWaylandManager.hpp" #include "../../managers/XWaylandManager.hpp"
#include "../../render/Renderer.hpp" #include "../../render/Renderer.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../managers/EventManager.hpp" #include "../../managers/EventManager.hpp"
#include "../../managers/input/InputManager.hpp" #include "../../managers/input/InputManager.hpp"
#include "../../managers/PointerManager.hpp" #include "../../managers/PointerManager.hpp"
@ -48,6 +47,7 @@
#include "../../layout/LayoutManager.hpp" #include "../../layout/LayoutManager.hpp"
#include "../../layout/target/WindowTarget.hpp" #include "../../layout/target/WindowTarget.hpp"
#include "../../layout/target/WindowGroupTarget.hpp" #include "../../layout/target/WindowGroupTarget.hpp"
#include "../../event/EventBus.hpp"
#include <hyprutils/string/String.hpp> #include <hyprutils/string/String.hpp>
@ -521,7 +521,7 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) {
if (valid(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 = "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)}); 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()) { if (const auto SWALLOWED = m_swallowed.lock()) {
@ -1037,7 +1037,7 @@ void CWindow::activate(bool force) {
m_isUrgent = true; m_isUrgent = true;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "urgent", .data = std::format("{:x}", rc<uintptr_t>(this))}); 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 && if (!force &&
(!m_ruleApplicator->focusOnActivate().valueOr(*PFOCUSONACTIVATE) || (m_suppressedEvents & SUPPRESS_ACTIVATE_FOCUSONLY) || (m_suppressedEvents & SUPPRESS_ACTIVATE))) (!m_ruleApplicator->focusOnActivate().valueOr(*PFOCUSONACTIVATE) || (m_suppressedEvents & SUPPRESS_ACTIVATE_FOCUSONLY) || (m_suppressedEvents & SUPPRESS_ACTIVATE)))
@ -1098,7 +1098,7 @@ void CWindow::onUpdateMeta() {
m_title = NEWTITLE; m_title = NEWTITLE;
g_pEventManager->postEvent(SHyprIPCEvent{.event = "windowtitle", .data = std::format("{:x}", rc<uintptr_t>(this))}); 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)}); 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 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 = "activewindow", .data = m_class + "," + m_title});
@ -1115,6 +1115,8 @@ void CWindow::onUpdateMeta() {
if (m_class != NEWCLASS) { if (m_class != NEWCLASS) {
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 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 = "activewindow", .data = m_class + "," + m_title});
g_pEventManager->postEvent(SHyprIPCEvent{.event = "activewindowv2", .data = std::format("{:x}", rc<uintptr_t>(this))}); 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 // 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)}); 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 if (*PAUTOGROUP // auto_group enabled
&& Desktop::focusState()->window() // focused window exists && 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()); 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 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. // apply data from default decos. Borders, shadows.
g_pDecorationPositioner->forceRecalcFor(m_self.lock()); g_pDecorationPositioner->forceRecalcFor(m_self.lock());
@ -2136,7 +2138,7 @@ void CWindow::unmapWindow() {
m_events.unmap.emit(); m_events.unmap.emit();
g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", std::format("{:x}", m_self.lock())}); 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()) { 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); 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{"activewindow", ","});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ""}); 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 { } else {
Log::logger->log(Log::DEBUG, "Unmapped was not focused, ignoring a refocus."); Log::logger->log(Log::DEBUG, "Unmapped was not focused, ignoring a refocus.");

8
src/event/EventBus.cpp Normal file
View file

@ -0,0 +1,8 @@
#include "EventBus.hpp"
using namespace Event;
UP<CEventBus>& Event::bus() {
static UP<CEventBus> p = makeUnique<CEventBus>();
return p;
}

142
src/event/EventBus.hpp Normal file
View file

@ -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();
};

View file

@ -26,7 +26,6 @@
#include "../managers/animation/AnimationManager.hpp" #include "../managers/animation/AnimationManager.hpp"
#include "../managers/animation/DesktopAnimationManager.hpp" #include "../managers/animation/DesktopAnimationManager.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../hyprerror/HyprError.hpp" #include "../hyprerror/HyprError.hpp"
#include "../layout/LayoutManager.hpp" #include "../layout/LayoutManager.hpp"
#include "../i18n/Engine.hpp" #include "../i18n/Engine.hpp"
@ -34,6 +33,7 @@
#include "time/Time.hpp" #include "time/Time.hpp"
#include "../desktop/view/LayerSurface.hpp" #include "../desktop/view/LayerSurface.hpp"
#include "../desktop/state/FocusState.hpp" #include "../desktop/state/FocusState.hpp"
#include "../event/EventBus.hpp"
#include "Drm.hpp" #include "Drm.hpp"
#include <aquamarine/output/Output.hpp> #include <aquamarine/output/Output.hpp>
#include "debug/log/Logger.hpp" #include "debug/log/Logger.hpp"
@ -74,7 +74,7 @@ CMonitor::~CMonitor() {
} }
void CMonitor::onConnect(bool noRule) { void CMonitor::onConnect(bool noRule) {
EMIT_HOOK_EVENT("preMonitorAdded", m_self.lock()); Event::bus()->m_events.monitor.preAdded.emit(m_self.lock());
CScopeGuard x = {[]() { g_pCompositor->arrangeMonitors(); }}; CScopeGuard x = {[]() { g_pCompositor->arrangeMonitors(); }};
m_zoomAnimProgress->setValueAndWarp(0.F); m_zoomAnimProgress->setValueAndWarp(0.F);
@ -347,17 +347,17 @@ void CMonitor::onConnect(bool noRule) {
g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", m_name}); g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", m_name});
g_pEventManager->postEvent(SHyprIPCEvent{"monitoraddedv2", std::format("{},{},{}", m_id, m_name, m_shortDescription)}); g_pEventManager->postEvent(SHyprIPCEvent{"monitoraddedv2", std::format("{},{},{}", m_id, m_name, m_shortDescription)});
EMIT_HOOK_EVENT("monitorAdded", m_self.lock()); Event::bus()->m_events.monitor.added.emit(m_self.lock());
} }
void CMonitor::onDisconnect(bool destroy) { void CMonitor::onDisconnect(bool destroy) {
EMIT_HOOK_EVENT("preMonitorRemoved", m_self.lock()); Event::bus()->m_events.monitor.preRemoved.emit(m_self.lock());
CScopeGuard x = {[this]() { CScopeGuard x = {[this]() {
if (g_pCompositor->m_isShuttingDown) if (g_pCompositor->m_isShuttingDown)
return; return;
g_pEventManager->postEvent(SHyprIPCEvent{"monitorremoved", m_name}); g_pEventManager->postEvent(SHyprIPCEvent{"monitorremoved", m_name});
g_pEventManager->postEvent(SHyprIPCEvent{"monitorremovedv2", std::format("{},{},{}", m_id, m_name, m_shortDescription)}); g_pEventManager->postEvent(SHyprIPCEvent{"monitorremovedv2", std::format("{},{},{}", m_id, m_name, m_shortDescription)});
EMIT_HOOK_EVENT("monitorRemoved", m_self.lock()); Event::bus()->m_events.monitor.removed.emit(m_self.lock());
g_pCompositor->scheduleMonitorStateRecheck(); g_pCompositor->scheduleMonitorStateRecheck();
}}; }};
@ -1016,7 +1016,7 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
Log::logger->log(Log::DEBUG, "Monitor {} data dump: res {:X}@{:.2f}Hz, scale {:.2f}, transform {}, pos {:X}, 10b {}", m_name, m_pixelSize, m_refreshRate, m_scale, Log::logger->log(Log::DEBUG, "Monitor {} data dump: res {:X}@{:.2f}Hz, scale {:.2f}, transform {}, pos {:X}, 10b {}", m_name, m_pixelSize, m_refreshRate, m_scale,
sc<int>(m_transform), m_position, sc<int>(m_enabled10bit)); sc<int>(m_transform), m_position, sc<int>(m_enabled10bit));
EMIT_HOOK_EVENT("monitorLayoutChanged", nullptr); Event::bus()->m_events.monitor.layoutChanged.emit();
m_events.modeChanged.emit(); m_events.modeChanged.emit();
@ -1336,7 +1336,7 @@ void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bo
g_pEventManager->postEvent(SHyprIPCEvent{"workspace", pWorkspace->m_name}); g_pEventManager->postEvent(SHyprIPCEvent{"workspace", pWorkspace->m_name});
g_pEventManager->postEvent(SHyprIPCEvent{"workspacev2", std::format("{},{}", pWorkspace->m_id, pWorkspace->m_name)}); g_pEventManager->postEvent(SHyprIPCEvent{"workspacev2", std::format("{},{}", pWorkspace->m_id, pWorkspace->m_name)});
EMIT_HOOK_EVENT("workspace", pWorkspace); Event::bus()->m_events.workspace.active.emit(pWorkspace);
} }
// set all LSes as not above fullscreen on workspace changes // set all LSes as not above fullscreen on workspace changes
@ -2196,7 +2196,7 @@ bool CMonitorState::commit() {
if (!updateSwapchain()) if (!updateSwapchain())
return false; return false;
EMIT_HOOK_EVENT("preMonitorCommit", m_owner->m_self.lock()); Event::bus()->m_events.monitor.preCommit.emit(m_owner->m_self.lock());
ensureBufferPresent(); ensureBufferPresent();

View file

@ -6,8 +6,8 @@
#include "../render/pass/TexPassElement.hpp" #include "../render/pass/TexPassElement.hpp"
#include "../managers/animation/AnimationManager.hpp" #include "../managers/animation/AnimationManager.hpp"
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../desktop/state/FocusState.hpp" #include "../desktop/state/FocusState.hpp"
#include "../event/EventBus.hpp"
#include <hyprutils/utils/ScopeGuard.hpp> #include <hyprutils/utils/ScopeGuard.hpp>
using namespace Hyprutils::Animation; using namespace Hyprutils::Animation;
@ -15,7 +15,7 @@ using namespace Hyprutils::Animation;
CHyprError::CHyprError() { CHyprError::CHyprError() {
g_pAnimationManager->createAnimation(0.f, m_fadeOpacity, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), AVARDAMAGE_NONE); g_pAnimationManager->createAnimation(0.f, m_fadeOpacity, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), AVARDAMAGE_NONE);
static auto P = g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.monitor.focused.listen([&](PHLMONITOR mon) {
if (!m_isCreated) if (!m_isCreated)
return; return;
@ -23,7 +23,7 @@ CHyprError::CHyprError() {
m_monitorChanged = true; m_monitorChanged = true;
}); });
static auto P2 = g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any param) { static auto P2 = Event::bus()->m_events.render.pre.listen([&](PHLMONITOR mon) {
if (!m_isCreated) if (!m_isCreated)
return; return;

View file

@ -5,14 +5,14 @@
#include "../config/ConfigManager.hpp" #include "../config/ConfigManager.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../desktop/state/FocusState.hpp" #include "../desktop/state/FocusState.hpp"
#include "../desktop/view/Group.hpp" #include "../desktop/view/Group.hpp"
#include "../event/EventBus.hpp"
using namespace Layout; using namespace Layout;
CLayoutManager::CLayoutManager() { CLayoutManager::CLayoutManager() {
static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [](void* hk, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.monitor.layoutChanged.listen([] {
for (const auto& ws : g_pCompositor->getWorkspaces()) { for (const auto& ws : g_pCompositor->getWorkspaces()) {
ws->m_space->recheckWorkArea(); ws->m_space->recheckWorkArea();
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -3,13 +3,13 @@
#include "../helpers/fs/FsUtils.hpp" #include "../helpers/fs/FsUtils.hpp"
#include "../debug/log/Logger.hpp" #include "../debug/log/Logger.hpp"
#include "../macros.hpp" #include "../macros.hpp"
#include "HookSystemManager.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../protocols/XDGShell.hpp" #include "../protocols/XDGShell.hpp"
#include "./eventLoop/EventLoopManager.hpp" #include "./eventLoop/EventLoopManager.hpp"
#include "../config/ConfigValue.hpp" #include "../config/ConfigValue.hpp"
#include "../xwayland/XSurface.hpp" #include "../xwayland/XSurface.hpp"
#include "../i18n/Engine.hpp" #include "../i18n/Engine.hpp"
#include "../event/EventBus.hpp"
using namespace Hyprutils::OS; using namespace Hyprutils::OS;
@ -26,9 +26,7 @@ CANRManager::CANRManager() {
m_active = true; m_active = true;
static auto P = g_pHookSystem->hookDynamic("openWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P = Event::bus()->m_events.window.open.listen([this](PHLWINDOW window) {
auto window = std::any_cast<PHLWINDOW>(data);
for (const auto& d : m_data) { for (const auto& d : m_data) {
// Window is ANR dialog // Window is ANR dialog
if (d->isRunning() && d->dialogBox->getPID() == window->getPID()) if (d->isRunning() && d->dialogBox->getPID() == window->getPID())
@ -41,9 +39,7 @@ CANRManager::CANRManager() {
m_data.emplace_back(makeShared<SANRData>(window)); m_data.emplace_back(makeShared<SANRData>(window));
}); });
static auto P1 = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P1 = Event::bus()->m_events.window.close.listen([this](PHLWINDOW window) {
auto window = std::any_cast<PHLWINDOW>(data);
for (const auto& d : m_data) { for (const auto& d : m_data) {
if (!d->fitsWindow(window)) if (!d->fitsWindow(window))
continue; continue;

View file

@ -3,8 +3,8 @@
#include "../config/ConfigValue.hpp" #include "../config/ConfigValue.hpp"
#include "PointerManager.hpp" #include "PointerManager.hpp"
#include "../xwayland/XWayland.hpp" #include "../xwayland/XWayland.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../event/EventBus.hpp"
static int cursorAnimTimer(SP<CEventLoopTimer> self, void* data) { static int cursorAnimTimer(SP<CEventLoopTimer> self, void* data) {
const auto cursorMgr = sc<CCursorManager*>(data); const auto cursorMgr = sc<CCursorManager*>(data);
@ -111,7 +111,7 @@ CCursorManager::CCursorManager() {
updateTheme(); 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() { CCursorManager::~CCursorManager() {

View file

@ -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];
}

View file

@ -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;

View file

@ -16,7 +16,6 @@
#include "TokenManager.hpp" #include "TokenManager.hpp"
#include "eventLoop/EventLoopManager.hpp" #include "eventLoop/EventLoopManager.hpp"
#include "debug/log/Logger.hpp" #include "debug/log/Logger.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../managers/animation/DesktopAnimationManager.hpp" #include "../managers/animation/DesktopAnimationManager.hpp"
#include "../managers/EventManager.hpp" #include "../managers/EventManager.hpp"
@ -32,6 +31,7 @@
#include "../layout/algorithm/Algorithm.hpp" #include "../layout/algorithm/Algorithm.hpp"
#include "../layout/algorithm/tiled/master/MasterAlgorithm.hpp" #include "../layout/algorithm/tiled/master/MasterAlgorithm.hpp"
#include "../layout/algorithm/tiled/monocle/MonocleAlgorithm.hpp" #include "../layout/algorithm/tiled/monocle/MonocleAlgorithm.hpp"
#include "../event/EventBus.hpp"
#include <optional> #include <optional>
#include <iterator> #include <iterator>
@ -203,8 +203,7 @@ CKeybindManager::CKeybindManager() {
g_pEventLoopManager->addTimer(m_repeatKeyTimer); g_pEventLoopManager->addTimer(m_repeatKeyTimer);
} }
static auto P = g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.config.reloaded.listen([this] {
// clear cuz realloc'd
m_activeKeybinds.clear(); m_activeKeybinds.clear();
m_lastLongPressKeybind.reset(); m_lastLongPressKeybind.reset();
m_pressedSpecialBinds.clear(); m_pressedSpecialBinds.clear();
@ -2215,7 +2214,7 @@ SDispatchResult CKeybindManager::setSubmap(std::string submap) {
m_currentSelectedSubmap.name = ""; m_currentSelectedSubmap.name = "";
Log::logger->log(Log::DEBUG, "Reset active submap to the default one."); Log::logger->log(Log::DEBUG, "Reset active submap to the default one.");
g_pEventManager->postEvent(SHyprIPCEvent{"submap", ""}); g_pEventManager->postEvent(SHyprIPCEvent{"submap", ""});
EMIT_HOOK_EVENT("submap", m_currentSelectedSubmap.name); Event::bus()->m_events.keybinds.submap.emit(m_currentSelectedSubmap.name);
return {}; return {};
} }
@ -2224,7 +2223,7 @@ SDispatchResult CKeybindManager::setSubmap(std::string submap) {
m_currentSelectedSubmap.name = submap; m_currentSelectedSubmap.name = submap;
Log::logger->log(Log::DEBUG, "Changed keybind submap to {}", submap); Log::logger->log(Log::DEBUG, "Changed keybind submap to {}", submap);
g_pEventManager->postEvent(SHyprIPCEvent{"submap", 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 {}; 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_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))}); 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); g_pHyprRenderer->damageWindow(PWINDOW, true);

View file

@ -11,13 +11,13 @@
#include "eventLoop/EventLoopManager.hpp" #include "eventLoop/EventLoopManager.hpp"
#include "../render/pass/TexPassElement.hpp" #include "../render/pass/TexPassElement.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"
#include "../render/OpenGL.hpp" #include "../render/OpenGL.hpp"
#include "../desktop/state/FocusState.hpp" #include "../desktop/state/FocusState.hpp"
#include "SeatManager.hpp" #include "SeatManager.hpp"
#include "../helpers/time/Time.hpp" #include "../helpers/time/Time.hpp"
#include "../helpers/Drm.hpp" #include "../helpers/Drm.hpp"
#include "../event/EventBus.hpp"
#include <cstring> #include <cstring>
#include <gbm.h> #include <gbm.h>
#include <cairo/cairo.h> #include <cairo/cairo.h>
@ -26,21 +26,19 @@
using namespace Hyprutils::Utils; using namespace Hyprutils::Utils;
CPointerManager::CPointerManager() { CPointerManager::CPointerManager() {
m_hooks.monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any data) { m_hooks.monitorAdded = Event::bus()->m_events.monitor.added.listen([this](PHLMONITOR monitor) {
auto PMONITOR = std::any_cast<PHLMONITOR>(data);
onMonitorLayoutChange(); onMonitorLayoutChange();
PMONITOR->m_events.modeChanged.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }); monitor->m_events.modeChanged.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); });
PMONITOR->m_events.disconnect.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }); monitor->m_events.disconnect.listenStatic([this] { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); });
PMONITOR->m_events.destroy.listenStatic([this] { monitor->m_events.destroy.listenStatic([this] {
if (g_pCompositor && !g_pCompositor->m_isShuttingDown) if (g_pCompositor && !g_pCompositor->m_isShuttingDown)
std::erase_if(m_monitorStates, [](const auto& other) { return other->monitor.expired(); }); 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) { m_hooks.monitorPreRender = Event::bus()->m_events.monitor.preCommit.listen([this](PHLMONITOR monitor) {
auto state = stateFor(std::any_cast<PHLMONITOR>(data)); auto state = stateFor(monitor);
if (!state) if (!state)
return; return;

View file

@ -7,6 +7,7 @@
#include "../desktop/view/WLSurface.hpp" #include "../desktop/view/WLSurface.hpp"
#include "../helpers/sync/SyncTimeline.hpp" #include "../helpers/sync/SyncTimeline.hpp"
#include "../helpers/time/Time.hpp" #include "../helpers/time/Time.hpp"
#include "../helpers/signal/Signal.hpp"
#include <tuple> #include <tuple>
class CMonitor; class CMonitor;
@ -184,8 +185,8 @@ class CPointerManager {
bool setHWCursorBuffer(SP<SMonitorPointerState> state, SP<Aquamarine::IBuffer> buf); bool setHWCursorBuffer(SP<SMonitorPointerState> state, SP<Aquamarine::IBuffer> buf);
struct { struct {
SP<HOOK_CALLBACK_FN> monitorAdded; CHyprSignalListener monitorAdded;
SP<HOOK_CALLBACK_FN> monitorPreRender; CHyprSignalListener monitorPreRender;
} m_hooks; } m_hooks;
}; };

View file

@ -67,9 +67,9 @@
#include "../protocols/PointerWarp.hpp" #include "../protocols/PointerWarp.hpp"
#include "../protocols/Fifo.hpp" #include "../protocols/Fifo.hpp"
#include "../protocols/CommitTiming.hpp" #include "../protocols/CommitTiming.hpp"
#include "HookSystemManager.hpp"
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../event/EventBus.hpp"
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "content-type-v1.hpp" #include "content-type-v1.hpp"
@ -113,9 +113,7 @@ CProtocolManager::CProtocolManager() {
static const auto PENABLECT = CConfigValue<Hyprlang::INT>("render:commit_timing_enabled"); static const auto PENABLECT = CConfigValue<Hyprlang::INT>("render:commit_timing_enabled");
// Outputs are a bit dumb, we have to agree. // Outputs are a bit dumb, we have to agree.
static auto P = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.monitor.added.listen([this](PHLMONITOR M) {
auto M = std::any_cast<PHLMONITOR>(param);
// ignore mirrored outputs. I don't think this will ever be hit as mirrors are applied after // ignore mirrored outputs. I don't think this will ever be hit as mirrors are applied after
// this event is emitted iirc. // this event is emitted iirc.
// also ignore the fallback // also ignore the fallback
@ -132,8 +130,7 @@ CProtocolManager::CProtocolManager() {
m_modeChangeListeners[M->m_name] = M->m_events.modeChanged.listen([this, M] { onMonitorModeChange(M); }); 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) { static auto P2 = Event::bus()->m_events.monitor.removed.listen([this](PHLMONITOR M) {
auto M = std::any_cast<PHLMONITOR>(param);
if (!PROTO::outputs.contains(M->m_name)) if (!PROTO::outputs.contains(M->m_name))
return; return;
PROTO::outputs.at(M->m_name)->remove(); PROTO::outputs.at(M->m_name)->remove();

View file

@ -11,7 +11,6 @@
#include "../devices/IKeyboard.hpp" #include "../devices/IKeyboard.hpp"
#include "../desktop/view/LayerSurface.hpp" #include "../desktop/view/LayerSurface.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "wlr-layer-shell-unstable-v1.hpp" #include "wlr-layer-shell-unstable-v1.hpp"
#include <algorithm> #include <algorithm>
#include <hyprutils/utils/ScopeGuard.hpp> #include <hyprutils/utils/ScopeGuard.hpp>

View file

@ -1,6 +1,5 @@
#include "AnimationManager.hpp" #include "AnimationManager.hpp"
#include "../../Compositor.hpp" #include "../../Compositor.hpp"
#include "../HookSystemManager.hpp"
#include "../../config/ConfigManager.hpp" #include "../../config/ConfigManager.hpp"
#include "../../desktop/DesktopTypes.hpp" #include "../../desktop/DesktopTypes.hpp"
#include "../../helpers/AnimatedVariable.hpp" #include "../../helpers/AnimatedVariable.hpp"
@ -11,6 +10,7 @@
#include "../eventLoop/EventLoopManager.hpp" #include "../eventLoop/EventLoopManager.hpp"
#include "../../helpers/varlist/VarList.hpp" #include "../../helpers/varlist/VarList.hpp"
#include "../../render/Renderer.hpp" #include "../../render/Renderer.hpp"
#include "../../event/EventBus.hpp"
#include <hyprgraphics/color/Color.hpp> #include <hyprgraphics/color/Color.hpp>
#include <hyprutils/animation/AnimatedVariable.hpp> #include <hyprutils/animation/AnimatedVariable.hpp>
@ -252,7 +252,7 @@ void CHyprAnimationManager::frameTick() {
if (!shouldTickForNext()) if (!shouldTickForNext())
return; 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; })) !std::ranges::any_of(g_pCompositor->m_monitors, [](const auto& mon) { return mon->m_enabled && mon->m_output; }))
return; return;
@ -261,7 +261,7 @@ void CHyprAnimationManager::frameTick() {
m_lastTickValid = true; m_lastTickValid = true;
tick(); tick();
EMIT_HOOK_EVENT("tick", nullptr); Event::bus()->m_events.tick.emit();
} }
if (shouldTickForNext()) if (shouldTickForNext())

View file

@ -35,7 +35,6 @@
#include "../../managers/SeatManager.hpp" #include "../../managers/SeatManager.hpp"
#include "../../managers/KeybindManager.hpp" #include "../../managers/KeybindManager.hpp"
#include "../../render/Renderer.hpp" #include "../../render/Renderer.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../managers/EventManager.hpp" #include "../../managers/EventManager.hpp"
#include "../../managers/permissions/DynamicPermissionManager.hpp" #include "../../managers/permissions/DynamicPermissionManager.hpp"
@ -44,6 +43,8 @@
#include "../../layout/LayoutManager.hpp" #include "../../layout/LayoutManager.hpp"
#include "../../event/EventBus.hpp"
#include "trackpad/TrackpadGestures.hpp" #include "trackpad/TrackpadGestures.hpp"
#include "../cursor/CursorShapeOverrideController.hpp" #include "../cursor/CursorShapeOverrideController.hpp"
@ -233,7 +234,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st
PHLLS pFoundLayerSurface; PHLLS pFoundLayerSurface;
const auto FOCUS_REASON = refocus ? Desktop::FOCUS_REASON_CLICK : Desktop::FOCUS_REASON_FFM; 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; m_lastCursorPosFloored = MOUSECOORDSFLOORED;
@ -644,7 +648,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st
} }
void CInputManager::onMouseButton(IPointer::SButtonEvent e) { 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) if (e.mouse)
recheckMouseWarpOnMouseInput(); recheckMouseWarpOnMouseInput();
@ -866,8 +873,10 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e, SP<IPointer> pointer) {
if (pointer && pointer->m_scrollFactor.has_value()) if (pointer && pointer->m_scrollFactor.has_value())
factor = *pointer->m_scrollFactor; factor = *pointer->m_scrollFactor;
const auto EMAP = std::unordered_map<std::string, std::any>{{"event", e}}; Event::SCallbackInfo info;
EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP); Event::bus()->m_events.input.mouse.axis.emit(e, info);
if (info.cancelled)
return;
if (e.mouse) if (e.mouse)
recheckMouseWarpOnMouseInput(); recheckMouseWarpOnMouseInput();
@ -1056,7 +1065,7 @@ void CInputManager::setupKeyboard(SP<IKeyboard> keeb) {
} }
g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", PKEEB->m_hlName + "," + LAYOUT}); 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); disableAllKeyboards(false);
@ -1153,7 +1162,7 @@ void CInputManager::applyConfigToKeyboard(SP<IKeyboard> pKeyboard) {
const auto LAYOUTSTR = pKeyboard->getActiveLayout(); const auto LAYOUTSTR = pKeyboard->getActiveLayout();
g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", pKeyboard->m_hlName + "," + LAYOUTSTR}); 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, 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); pKeyboard->m_hlName);
@ -1475,14 +1484,16 @@ void CInputManager::onKeyboardKey(const IKeyboard::SKeyEvent& event, SP<IKeyboar
if (!pKeyboard->m_enabled || !pKeyboard->m_allowed) if (!pKeyboard->m_enabled || !pKeyboard->m_allowed)
return; return;
const bool DISALLOWACTION = pKeyboard->isVirtual() && shouldIgnoreVirtualKeyboard(pKeyboard); const bool DISALLOWACTION = pKeyboard->isVirtual() && shouldIgnoreVirtualKeyboard(pKeyboard);
const auto IME = m_relay.m_inputMethod.lock(); const auto IME = m_relay.m_inputMethod.lock();
const bool HASIME = IME && IME->hasGrab(); const bool HASIME = IME && IME->hasGrab();
const bool USEIME = HASIME && !DISALLOWACTION; const bool USEIME = HASIME && !DISALLOWACTION;
const auto EMAP = std::unordered_map<std::string, std::any>{{"keyboard", pKeyboard}, {"event", event}}; Event::SCallbackInfo info;
EMIT_HOOK_EVENT_CANCELLABLE("keyPress", EMAP); Event::bus()->m_events.input.keyboard.key.emit(event, info);
if (info.cancelled)
return;
bool passEvent = DISALLOWACTION; 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); Log::logger->log(Log::DEBUG, "LAYOUT CHANGED TO {} GROUP {}", LAYOUT, MODS.group);
g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", pKeyboard->m_hlName + "," + LAYOUT}); 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) { 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); g_pTrackpadGestures->gestureBegin(e);
@ -2047,7 +2061,10 @@ void CInputManager::onSwipeBegin(IPointer::SSwipeBeginEvent e) {
} }
void CInputManager::onSwipeUpdate(IPointer::SSwipeUpdateEvent 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); g_pTrackpadGestures->gestureUpdate(e);
@ -2055,7 +2072,10 @@ void CInputManager::onSwipeUpdate(IPointer::SSwipeUpdateEvent e) {
} }
void CInputManager::onSwipeEnd(IPointer::SSwipeEndEvent 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); g_pTrackpadGestures->gestureEnd(e);
@ -2063,7 +2083,10 @@ void CInputManager::onSwipeEnd(IPointer::SSwipeEndEvent e) {
} }
void CInputManager::onPinchBegin(IPointer::SPinchBeginEvent 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); g_pTrackpadGestures->gestureBegin(e);
@ -2071,7 +2094,10 @@ void CInputManager::onPinchBegin(IPointer::SPinchBeginEvent e) {
} }
void CInputManager::onPinchUpdate(IPointer::SPinchUpdateEvent 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); g_pTrackpadGestures->gestureUpdate(e);
@ -2079,7 +2105,10 @@ void CInputManager::onPinchUpdate(IPointer::SPinchUpdateEvent e) {
} }
void CInputManager::onPinchEnd(IPointer::SPinchEndEvent 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); g_pTrackpadGestures->gestureEnd(e);

View file

@ -1,14 +1,13 @@
#include "InputMethodRelay.hpp" #include "InputMethodRelay.hpp"
#include "../../desktop/state/FocusState.hpp" #include "../../desktop/state/FocusState.hpp"
#include "../../event/EventBus.hpp"
#include "../../protocols/TextInputV3.hpp" #include "../../protocols/TextInputV3.hpp"
#include "../../protocols/TextInputV1.hpp" #include "../../protocols/TextInputV1.hpp"
#include "../../protocols/InputMethodV2.hpp" #include "../../protocols/InputMethodV2.hpp"
#include "../../protocols/core/Compositor.hpp" #include "../../protocols/core/Compositor.hpp"
#include "../../managers/HookSystemManager.hpp"
CInputMethodRelay::CInputMethodRelay() { CInputMethodRelay::CInputMethodRelay() {
static auto P = static auto P = Event::bus()->m_events.input.keyboard.focus.listen([&](SP<CWLSurfaceResource> surf) { onKeyboardFocus(surf); });
g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<SP<CWLSurfaceResource>>(param)); });
m_listeners.newTIV3 = PROTO::textInputV3->m_events.newTextInput.listen([this](const auto& input) { onNewTextInput(input); }); 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); }); m_listeners.newTIV1 = PROTO::textInputV1->m_events.newTextInput.listen([this](const auto& input) { onNewTextInput(input); });

View file

@ -2,11 +2,11 @@
#include "../../desktop/view/Window.hpp" #include "../../desktop/view/Window.hpp"
#include "../../protocols/Tablet.hpp" #include "../../protocols/Tablet.hpp"
#include "../../devices/Tablet.hpp" #include "../../devices/Tablet.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../managers/PointerManager.hpp" #include "../../managers/PointerManager.hpp"
#include "../../managers/SeatManager.hpp" #include "../../managers/SeatManager.hpp"
#include "../../protocols/PointerConstraints.hpp" #include "../../protocols/PointerConstraints.hpp"
#include "../../protocols/core/DataDevice.hpp" #include "../../protocols/core/DataDevice.hpp"
#include "../../event/EventBus.hpp"
static void unfocusTool(SP<CTabletTool> tool) { static void unfocusTool(SP<CTabletTool> tool) {
if (!tool->getSurface()) if (!tool->getSurface())
@ -107,6 +107,11 @@ static Vector2D transformToActiveRegion(const Vector2D pos, const CBox activeAre
} }
void CInputManager::onTabletAxis(CTablet::SAxisEvent e) { 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 PTAB = e.tablet;
const auto PTOOL = ensureTabletToolPresent(e.tool); const auto PTOOL = ensureTabletToolPresent(e.tool);
@ -171,7 +176,10 @@ void CInputManager::onTabletAxis(CTablet::SAxisEvent e) {
} }
void CInputManager::onTabletTip(CTablet::STipEvent 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 PTAB = e.tablet;
const auto PTOOL = ensureTabletToolPresent(e.tool); const auto PTOOL = ensureTabletToolPresent(e.tool);
@ -196,6 +204,11 @@ void CInputManager::onTabletTip(CTablet::STipEvent e) {
} }
void CInputManager::onTabletButton(CTablet::SButtonEvent 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); const auto PTOOL = ensureTabletToolPresent(e.tool);
if (e.down) if (e.down)
@ -210,6 +223,11 @@ void CInputManager::onTabletButton(CTablet::SButtonEvent e) {
} }
void CInputManager::onTabletProximity(CTablet::SProximityEvent 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 PTAB = e.tablet;
const auto PTOOL = ensureTabletToolPresent(e.tool); const auto PTOOL = ensureTabletToolPresent(e.tool);

View file

@ -7,8 +7,8 @@
#include "../../config/ConfigValue.hpp" #include "../../config/ConfigValue.hpp"
#include "../../helpers/Monitor.hpp" #include "../../helpers/Monitor.hpp"
#include "../../devices/ITouch.hpp" #include "../../devices/ITouch.hpp"
#include "../../event/EventBus.hpp"
#include "../SeatManager.hpp" #include "../SeatManager.hpp"
#include "../HookSystemManager.hpp"
#include "debug/log/Logger.hpp" #include "debug/log/Logger.hpp"
#include "UnifiedWorkspaceSwipeGesture.hpp" #include "UnifiedWorkspaceSwipeGesture.hpp"
@ -19,10 +19,14 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) {
static auto PGAPSOUTDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_out"); static auto PGAPSOUTDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_out");
auto* const PGAPSOUT = sc<CCssGapData*>((PGAPSOUTDATA.ptr())->getData()); auto* const PGAPSOUT = sc<CCssGapData*>((PGAPSOUTDATA.ptr())->getData());
// TODO: WORKSPACERULE.gapsOut.value_or() // TODO: WORKSPACERULE.gapsOut.value_or()
auto gapsOut = *PGAPSOUT; auto gapsOut = *PGAPSOUT;
static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size"); static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch_invert"); static auto PSWIPEINVR = CConfigValue<Hyprlang::INT>("gestures:workspace_swipe_touch_invert");
EMIT_HOOK_EVENT_CANCELLABLE("touchDown", e);
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 : ""); 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) { void CInputManager::onTouchUp(ITouch::SUpEvent e) {
m_lastInputTouch = true; 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 (g_pUnifiedWorkspaceSwipe->isGestureInProgress()) {
// If there was a swipe from this finger, end it. // If there was a swipe from this finger, end it.
if (e.touchID == g_pUnifiedWorkspaceSwipe->m_touchID) if (e.touchID == g_pUnifiedWorkspaceSwipe->m_touchID)
@ -126,7 +134,11 @@ void CInputManager::onTouchMove(ITouch::SMotionEvent e) {
m_lastCursorMovement.reset(); 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()) { if (g_pUnifiedWorkspaceSwipe->isGestureInProgress()) {
// Do nothing if this is using a different finger. // Do nothing if this is using a different finger.
if (e.touchID != g_pUnifiedWorkspaceSwipe->m_touchID) if (e.touchID != g_pUnifiedWorkspaceSwipe->m_touchID)

View file

@ -2,9 +2,9 @@
#include "../../render/OpenGL.hpp" #include "../../render/OpenGL.hpp"
#include "../../Compositor.hpp" #include "../../Compositor.hpp"
#include "../../render/Renderer.hpp" #include "../../render/Renderer.hpp"
#include "../HookSystemManager.hpp"
#include "../EventManager.hpp" #include "../EventManager.hpp"
#include "../eventLoop/EventLoopManager.hpp" #include "../eventLoop/EventLoopManager.hpp"
#include "../../event/EventBus.hpp"
using namespace Screenshare; using namespace Screenshare;
@ -119,18 +119,18 @@ void CScreenshareSession::calculateConstraints() {
void CScreenshareSession::screenshareEvents(bool startSharing) { void CScreenshareSession::screenshareEvents(bool startSharing) {
if (startSharing && !m_sharing) { if (startSharing && !m_sharing) {
m_sharing = true; 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)}); 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)}); 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); 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) { } else if (!startSharing && m_sharing) {
m_sharing = false; 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)}); 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)}); 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); LOGM(Log::INFO, "Stopped screenshare session for ({}): {}", m_type, m_name);
Event::bus()->m_events.screenshare.state.emit(false, m_type, m_name);
} }
} }

View file

@ -2,7 +2,6 @@
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../debug/HyprCtl.hpp" #include "../debug/HyprCtl.hpp"
#include "../plugins/PluginSystem.hpp" #include "../plugins/PluginSystem.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp" #include "../managers/eventLoop/EventLoopManager.hpp"
#include "../config/ConfigManager.hpp" #include "../config/ConfigManager.hpp"
#include "../debug/HyprNotificationOverlay.hpp" #include "../debug/HyprNotificationOverlay.hpp"
@ -38,9 +37,9 @@ APICALL SP<HOOK_CALLBACK_FN> HyprlandAPI::registerCallbackDynamic(HANDLE handle,
if (!PLUGIN) if (!PLUGIN)
return nullptr; return nullptr;
auto PFN = g_pHookSystem->hookDynamic(event, fn, handle); //auto PFN = g_pHookSystem->hookDynamic(event, fn, handle);
PLUGIN->m_registeredCallbacks.emplace_back(std::make_pair<>(event, WP<HOOK_CALLBACK_FN>(PFN))); //PLUGIN->m_registeredCallbacks.emplace_back(std::make_pair<>(event, WP<HOOK_CALLBACK_FN>(PFN)));
return PFN; return nullptr;
} }
APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, SP<HOOK_CALLBACK_FN> fn) { APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, SP<HOOK_CALLBACK_FN> fn) {
@ -49,8 +48,8 @@ APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, SP<HOOK_CALLBACK_FN>
if (!PLUGIN) if (!PLUGIN)
return false; return false;
g_pHookSystem->unhook(fn); //g_pHookSystem->unhook(fn);
std::erase_if(PLUGIN->m_registeredCallbacks, [&](const auto& other) { return other.second.lock() == fn; }); // std::erase_if(PLUGIN->m_registeredCallbacks, [&](const auto& other) { return other.second.lock() == fn; });
return true; return true;
} }

View file

@ -70,12 +70,15 @@ struct SVersionInfo {
class IHyprLayout; class IHyprLayout;
class IHyprWindowDecoration; class IHyprWindowDecoration;
struct SConfigValue; struct SConfigValue;
class Hypr_dummyClass {};
namespace Layout { namespace Layout {
class ITiledAlgorithm; class ITiledAlgorithm;
class IFloatingAlgorithm; class IFloatingAlgorithm;
}; };
using HOOK_CALLBACK_FN = Hypr_dummyClass;
/* /*
These methods are for the plugin to implement These methods are for the plugin to implement
Methods marked with REQUIRED are required. Methods marked with REQUIRED are required.
@ -148,6 +151,8 @@ namespace HyprlandAPI {
APICALL Hyprlang::CConfigValue* getConfigValue(HANDLE handle, const std::string& name); APICALL Hyprlang::CConfigValue* getConfigValue(HANDLE handle, const std::string& name);
/* /*
Deprecated: doesn't do anything anymore, use Event::bus()
Register a dynamic (function) callback to a selected event. Register a dynamic (function) callback to a selected event.
Pointer will be free'd by Hyprland on unregisterCallback(). Pointer will be free'd by Hyprland on unregisterCallback().
@ -155,7 +160,7 @@ namespace HyprlandAPI {
WARNING: Losing this pointer will unregister the callback! WARNING: Losing this pointer will unregister the callback!
*/ */
APICALL [[nodiscard]] SP<HOOK_CALLBACK_FN> registerCallbackDynamic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN fn); APICALL [[deprecated]] [[nodiscard]] SP<HOOK_CALLBACK_FN> registerCallbackDynamic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN fn);
/* /*
Unregisters a callback. If the callback was dynamic, frees the memory. Unregisters a callback. If the callback was dynamic, frees the memory.

View file

@ -4,7 +4,6 @@
#include <ranges> #include <ranges>
#include "../config/ConfigManager.hpp" #include "../config/ConfigManager.hpp"
#include "../debug/HyprCtl.hpp" #include "../debug/HyprCtl.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp" #include "../managers/eventLoop/EventLoopManager.hpp"
#include "../managers/permissions/DynamicPermissionManager.hpp" #include "../managers/permissions/DynamicPermissionManager.hpp"
#include "../debug/HyprNotificationOverlay.hpp" #include "../debug/HyprNotificationOverlay.hpp"
@ -151,10 +150,10 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) {
exitFunc(); exitFunc();
} }
for (auto const& [k, v] : plugin->m_registeredCallbacks) { // for (auto const& [k, v] : plugin->m_registeredCallbacks) {
if (const auto SHP = v.lock()) // if (const auto SHP = v.lock())
g_pHookSystem->unhook(SHP); // g_pHookSystem->unhook(SHP);
} // }
for (const auto& l : plugin->m_registeredAlgos) { for (const auto& l : plugin->m_registeredAlgos) {
Layout::Supplementary::algoMatcher()->unregisterAlgo(l); Layout::Supplementary::algoMatcher()->unregisterAlgo(l);

View file

@ -12,22 +12,22 @@ class IHyprWindowDecoration;
class CPlugin { class CPlugin {
public: public:
std::string m_name = ""; std::string m_name = "";
std::string m_description = ""; std::string m_description = "";
std::string m_author = ""; std::string m_author = "";
std::string m_version = ""; std::string m_version = "";
std::string m_path = ""; std::string m_path = "";
bool m_loadedWithConfig = false; bool m_loadedWithConfig = false;
HANDLE m_handle = nullptr; HANDLE m_handle = nullptr;
std::vector<IHyprWindowDecoration*> m_registeredDecorations; std::vector<IHyprWindowDecoration*> m_registeredDecorations;
std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks; //std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks;
std::vector<std::string> m_registeredDispatchers; std::vector<std::string> m_registeredDispatchers;
std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands; std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands;
std::vector<std::string> m_registeredAlgos; std::vector<std::string> m_registeredAlgos;
}; };
class CPluginSystem { class CPluginSystem {

View file

@ -1,9 +1,8 @@
#include "ExtWorkspace.hpp" #include "ExtWorkspace.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp" #include "../managers/eventLoop/EventLoopManager.hpp"
#include "../event/EventBus.hpp"
#include <algorithm> #include <algorithm>
#include <any>
#include <utility> #include <utility>
#include "core/Output.hpp" #include "core/Output.hpp"
@ -297,17 +296,13 @@ void CExtWorkspaceManagerResource::onWorkspaceCreated(const PHLWORKSPACE& worksp
} }
CExtWorkspaceProtocol::CExtWorkspaceProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CExtWorkspaceProtocol::CExtWorkspaceProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P1 = g_pHookSystem->hookDynamic("createWorkspace", [this](void* self, SCallbackInfo& info, std::any data) { static auto P1 = Event::bus()->m_events.workspace.created.listen([this](PHLWORKSPACEREF workspace) {
auto workspace = std::any_cast<CWorkspace*>(data)->m_self.lock();
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onWorkspaceCreated(workspace); m->onWorkspaceCreated(workspace.lock());
} }
}); });
static auto P2 = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any data) { static auto P2 = Event::bus()->m_events.monitor.added.listen([this](PHLMONITOR monitor) {
auto monitor = std::any_cast<PHLMONITOR>(data);
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onMonitorCreated(monitor); m->onMonitorCreated(monitor);
} }

View file

@ -1,8 +1,8 @@
#include "Fifo.hpp" #include "Fifo.hpp"
#include "Compositor.hpp" #include "Compositor.hpp"
#include "core/Compositor.hpp" #include "core/Compositor.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../event/EventBus.hpp"
CFifoResource::CFifoResource(UP<CWpFifoV1>&& resource_, SP<CWLSurfaceResource> surface) : m_resource(std::move(resource_)), m_surface(surface) { CFifoResource::CFifoResource(UP<CWpFifoV1>&& resource_, SP<CWLSurfaceResource> surface) : m_resource(std::move(resource_)), m_surface(surface) {
if UNLIKELY (!m_resource->resource()) if UNLIKELY (!m_resource->resource())
@ -153,9 +153,7 @@ bool CFifoManagerResource::good() {
} }
CFifoProtocol::CFifoProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CFifoProtocol::CFifoProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.monitor.added.listen([this](PHLMONITOR M) {
auto M = std::any_cast<PHLMONITOR>(param);
M->m_events.presented.listenStatic([this, m = PHLMONITORREF{M}]() { M->m_events.presented.listenStatic([this, m = PHLMONITORREF{M}]() {
if (!m || !PROTO::fifo) if (!m || !PROTO::fifo)
return; return;

View file

@ -1,6 +1,6 @@
#include "ForeignToplevel.hpp" #include "ForeignToplevel.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../managers/HookSystemManager.hpp" #include "../event/EventBus.hpp"
CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : m_resource(resource_), m_window(pWindow_) { CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : m_resource(resource_), m_window(pWindow_) {
if UNLIKELY (!resource_->resource()) if UNLIKELY (!resource_->resource())
@ -123,9 +123,7 @@ bool CForeignToplevelList::good() {
} }
CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("openWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P = Event::bus()->m_events.window.open.listen([this](PHLWINDOW window) {
auto window = std::any_cast<PHLWINDOW>(data);
if (!windowValidForForeign(window)) if (!windowValidForForeign(window))
return; return;
@ -134,9 +132,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
} }
}); });
static auto P1 = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P1 = Event::bus()->m_events.window.close.listen([this](PHLWINDOW window) {
auto window = std::any_cast<PHLWINDOW>(data);
if (!windowValidForForeign(window)) if (!windowValidForForeign(window))
return; return;
@ -145,9 +141,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
} }
}); });
static auto P2 = g_pHookSystem->hookDynamic("windowTitle", [this](void* self, SCallbackInfo& info, std::any data) { static auto P2 = Event::bus()->m_events.window.title.listen([this](PHLWINDOW window) {
auto window = std::any_cast<PHLWINDOW>(data);
if (!windowValidForForeign(window)) if (!windowValidForForeign(window))
return; return;

View file

@ -5,8 +5,8 @@
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../desktop/state/FocusState.hpp" #include "../desktop/state/FocusState.hpp"
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/EventManager.hpp" #include "../managers/EventManager.hpp"
#include "../event/EventBus.hpp"
CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : m_resource(resource_), m_window(pWindow_) { CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : m_resource(resource_), m_window(pWindow_) {
if UNLIKELY (!resource_->resource()) if UNLIKELY (!resource_->resource())
@ -343,70 +343,57 @@ bool CForeignToplevelWlrManager::good() {
} }
CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("openWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P = Event::bus()->m_events.window.open.listen([this](PHLWINDOW window) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(data); if (!windowValidForForeign(window))
if (!windowValidForForeign(PWINDOW))
return; return;
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onMap(PWINDOW); m->onMap(window);
} }
}); });
static auto P1 = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P1 = Event::bus()->m_events.window.close.listen([this](PHLWINDOW window) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(data); if (!windowValidForForeign(window))
if (!windowValidForForeign(PWINDOW))
return; return;
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onUnmap(PWINDOW); m->onUnmap(window);
} }
}); });
static auto P2 = g_pHookSystem->hookDynamic("windowTitle", [this](void* self, SCallbackInfo& info, std::any data) { static auto P2 = Event::bus()->m_events.window.title.listen([this](PHLWINDOW window) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(data); if (!windowValidForForeign(window))
if (!windowValidForForeign(PWINDOW))
return; return;
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onTitle(PWINDOW); m->onTitle(window);
} }
}); });
static auto P3 = g_pHookSystem->hookDynamic("activeWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P3 = Event::bus()->m_events.window.active.listen([this](PHLWINDOW window, Desktop::eFocusReason reason) {
const auto PWINDOW = std::any_cast<Desktop::View::SWindowActiveEvent>(data).window; if (window && !windowValidForForeign(window))
if (PWINDOW && !windowValidForForeign(PWINDOW))
return; return;
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onNewFocus(PWINDOW); m->onNewFocus(window);
} }
}); });
static auto P4 = g_pHookSystem->hookDynamic("moveWindow", [this](void* self, SCallbackInfo& info, std::any data) { static auto P4 = Event::bus()->m_events.window.moveToWorkspace.listen([this](PHLWINDOW window, PHLWORKSPACE ws) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(std::any_cast<std::vector<std::any>>(data).at(0)); if (!ws)
const auto PWORKSPACE = std::any_cast<PHLWORKSPACE>(std::any_cast<std::vector<std::any>>(data).at(1));
if (!PWORKSPACE)
return; return;
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onMoveMonitor(PWINDOW, PWORKSPACE->m_monitor.lock()); m->onMoveMonitor(window, ws->m_monitor.lock());
} }
}); });
static auto P5 = g_pHookSystem->hookDynamic("fullscreen", [this](void* self, SCallbackInfo& info, std::any data) { static auto P5 = Event::bus()->m_events.window.fullscreen.listen([this](PHLWINDOW window) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(data); if (!windowValidForForeign(window))
if (!windowValidForForeign(PWINDOW))
return; return;
for (auto const& m : m_managers) { for (auto const& m : m_managers) {
m->onFullscreen(PWINDOW); m->onFullscreen(window);
} }
}); });
} }

View file

@ -10,9 +10,9 @@
#include "core/Compositor.hpp" #include "core/Compositor.hpp"
#include "types/DMABuffer.hpp" #include "types/DMABuffer.hpp"
#include "types/WLBuffer.hpp" #include "types/WLBuffer.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../render/OpenGL.hpp" #include "../render/OpenGL.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../event/EventBus.hpp"
using namespace Hyprutils::OS; using namespace Hyprutils::OS;
@ -434,7 +434,7 @@ void CLinuxDMABUFResource::sendMods() {
} }
CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("ready", [this](void* self, SCallbackInfo& info, std::any d) { static auto P = Event::bus()->m_events.ready.listen([this] {
int rendererFD = g_pCompositor->m_drmRenderNode.fd >= 0 ? g_pCompositor->m_drmRenderNode.fd : g_pCompositor->m_drm.fd; int rendererFD = g_pCompositor->m_drmRenderNode.fd >= 0 ? g_pCompositor->m_drmRenderNode.fd : g_pCompositor->m_drm.fd;
auto dev = devIDFromFD(rendererFD); auto dev = devIDFromFD(rendererFD);
@ -467,24 +467,22 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
tches.emplace_back(std::make_pair<>(mon, tranche)); tches.emplace_back(std::make_pair<>(mon, tranche));
} }
static auto monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) { static auto monitorAdded = Event::bus()->m_events.monitor.added.listen([this](PHLMONITOR mon) {
auto pMonitor = std::any_cast<PHLMONITOR>(param); auto tranche = SDMABUFTranche{
auto tranche = SDMABUFTranche{ .device = m_mainDevice,
.device = m_mainDevice, .flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT,
.flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT, .formats = mon->m_output->getRenderFormats(),
.formats = pMonitor->m_output->getRenderFormats(),
}; };
m_formatTable->m_monitorTranches.emplace_back(std::make_pair<>(pMonitor, tranche)); m_formatTable->m_monitorTranches.emplace_back(std::make_pair<>(mon, tranche));
resetFormatTable(); resetFormatTable();
}); });
static auto monitorRemoved = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { static auto monitorRemoved = Event::bus()->m_events.monitor.removed.listen([this](PHLMONITOR mon) {
auto pMonitor = std::any_cast<PHLMONITOR>(param); std::erase_if(m_formatTable->m_monitorTranches, [mon](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == mon; });
std::erase_if(m_formatTable->m_monitorTranches, [pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
resetFormatTable(); resetFormatTable();
}); });
static auto configReloaded = g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { static auto configReloaded = Event::bus()->m_events.config.reloaded.listen([this] {
static const auto PSKIP_NON_KMS = CConfigValue<Hyprlang::INT>("quirks:skip_non_kms_dmabuf_formats"); static const auto PSKIP_NON_KMS = CConfigValue<Hyprlang::INT>("quirks:skip_non_kms_dmabuf_formats");
static auto prev = *PSKIP_NON_KMS; static auto prev = *PSKIP_NON_KMS;
if (prev != *PSKIP_NON_KMS) { if (prev != *PSKIP_NON_KMS) {

View file

@ -2,8 +2,8 @@
#include <algorithm> #include <algorithm>
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../config/ConfigManager.hpp" #include "../config/ConfigManager.hpp"
#include "../event/EventBus.hpp"
using namespace Aquamarine; using namespace Aquamarine;
@ -578,7 +578,7 @@ bool COutputConfigurationHead::good() {
} }
COutputManagementProtocol::COutputManagementProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { COutputManagementProtocol::COutputManagementProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.monitor.layoutChanged.listen([this] {
updateAllOutputs(); updateAllOutputs();
sendPendingSuccessEvents(); sendPendingSuccessEvents();
}); });

View file

@ -1,7 +1,7 @@
#include "PresentationTime.hpp" #include "PresentationTime.hpp"
#include <algorithm> #include <algorithm>
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../managers/HookSystemManager.hpp" #include "../event/EventBus.hpp"
#include "core/Compositor.hpp" #include "core/Compositor.hpp"
#include "core/Output.hpp" #include "core/Output.hpp"
#include <aquamarine/output/Output.hpp> #include <aquamarine/output/Output.hpp>
@ -77,10 +77,8 @@ void CPresentationFeedback::sendQueued(WP<CQueuedPresentationData> data, const t
} }
CPresentationProtocol::CPresentationProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CPresentationProtocol::CPresentationProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.monitor.removed.listen(
const auto PMONITOR = PHLMONITORREF{std::any_cast<PHLMONITOR>(param)}; [this](PHLMONITOR mon) { std::erase_if(m_queue, [mon](const auto& other) { return !other->m_surface || other->m_monitor == mon; }); });
std::erase_if(m_queue, [PMONITOR](const auto& other) { return !other->m_surface || other->m_monitor == PMONITOR; });
});
} }
void CPresentationProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { void CPresentationProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {

View file

@ -1,13 +1,12 @@
#include "TearingControl.hpp" #include "TearingControl.hpp"
#include "../managers/ProtocolManager.hpp" #include "../managers/ProtocolManager.hpp"
#include "../desktop/view/Window.hpp" #include "../desktop/view/Window.hpp"
#include "../event/EventBus.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "core/Compositor.hpp" #include "core/Compositor.hpp"
#include "../managers/HookSystemManager.hpp"
CTearingControlProtocol::CTearingControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CTearingControlProtocol::CTearingControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = static auto P = Event::bus()->m_events.window.destroy.listen([this](PHLWINDOW window) { onWindowDestroy(window); });
g_pHookSystem->hookDynamic("destroyWindow", [this](void* self, SCallbackInfo& info, std::any param) { this->onWindowDestroy(std::any_cast<PHLWINDOW>(param)); });
} }
void CTearingControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { void CTearingControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {

View file

@ -2,7 +2,6 @@
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "ForeignToplevelWlr.hpp" #include "ForeignToplevelWlr.hpp"
#include "../managers/screenshare/ScreenshareManager.hpp" #include "../managers/screenshare/ScreenshareManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../helpers/Format.hpp" #include "../helpers/Format.hpp"
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"

View file

@ -2,7 +2,7 @@
#include "../config/ConfigValue.hpp" #include "../config/ConfigValue.hpp"
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../xwayland/XWayland.hpp" #include "../xwayland/XWayland.hpp"
#include "../managers/HookSystemManager.hpp" #include "../event/EventBus.hpp"
#include "core/Output.hpp" #include "core/Output.hpp"
#define OUTPUT_MANAGER_VERSION 3 #define OUTPUT_MANAGER_VERSION 3
@ -36,8 +36,8 @@ void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver
} }
CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
static auto P = g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); static auto P = Event::bus()->m_events.monitor.layoutChanged.listen([this] { updateAllOutputs(); });
static auto P2 = g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); }); static auto P2 = Event::bus()->m_events.config.reloaded.listen([this] { updateAllOutputs(); });
} }
void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32_t id, wl_resource* outputResource) { void CXDGOutputProtocol::onManagerGetXDGOutput(CZxdgOutputManagerV1* mgr, uint32_t id, wl_resource* outputResource) {

View file

@ -10,11 +10,11 @@
#include "../../xwayland/XWayland.hpp" #include "../../xwayland/XWayland.hpp"
#include "../../xwayland/Server.hpp" #include "../../xwayland/Server.hpp"
#include "../../managers/input/InputManager.hpp" #include "../../managers/input/InputManager.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../managers/cursor/CursorShapeOverrideController.hpp" #include "../../managers/cursor/CursorShapeOverrideController.hpp"
#include "../../helpers/Monitor.hpp" #include "../../helpers/Monitor.hpp"
#include "../../render/Renderer.hpp" #include "../../render/Renderer.hpp"
#include "../../xwayland/Dnd.hpp" #include "../../xwayland/Dnd.hpp"
#include "../../event/EventBus.hpp"
using namespace Hyprutils::OS; using namespace Hyprutils::OS;
CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : m_source(source_), m_resource(resource_) { CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : m_source(source_), m_resource(resource_) {
@ -586,29 +586,26 @@ void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource
}); });
} }
m_dnd.mouseButton = g_pHookSystem->hookDynamic("mouseButton", [this](void* self, SCallbackInfo& info, std::any e) { m_dnd.mouseButton = Event::bus()->m_events.input.mouse.button.listen([this](IPointer::SButtonEvent e, Event::SCallbackInfo&) {
auto E = std::any_cast<IPointer::SButtonEvent>(e); if (e.state == WL_POINTER_BUTTON_STATE_RELEASED) {
if (E.state == WL_POINTER_BUTTON_STATE_RELEASED) {
LOGM(Log::DEBUG, "Dropping drag on mouseUp"); LOGM(Log::DEBUG, "Dropping drag on mouseUp");
dropDrag(); dropDrag();
} }
}); });
m_dnd.touchUp = g_pHookSystem->hookDynamic("touchUp", [this](void* self, SCallbackInfo& info, std::any e) { m_dnd.touchUp = Event::bus()->m_events.input.touch.up.listen([this](ITouch::SUpEvent e, Event::SCallbackInfo&) {
LOGM(Log::DEBUG, "Dropping drag on touchUp"); LOGM(Log::DEBUG, "Dropping drag on touchUp");
dropDrag(); dropDrag();
}); });
m_dnd.tabletTip = g_pHookSystem->hookDynamic("tabletTip", [this](void* self, SCallbackInfo& info, std::any e) { m_dnd.tabletTip = Event::bus()->m_events.input.tablet.tip.listen([this](CTablet::STipEvent e, Event::SCallbackInfo&) {
auto E = std::any_cast<CTablet::STipEvent>(e); if (!e.in) {
if (!E.in) {
LOGM(Log::DEBUG, "Dropping drag on tablet tipUp"); LOGM(Log::DEBUG, "Dropping drag on tablet tipUp");
dropDrag(); dropDrag();
} }
}); });
m_dnd.mouseMove = g_pHookSystem->hookDynamic("mouseMove", [this](void* self, SCallbackInfo& info, std::any e) { m_dnd.mouseMove = Event::bus()->m_events.input.mouse.move.listen([this](Vector2D pos, Event::SCallbackInfo&) {
auto V = std::any_cast<const Vector2D>(e);
if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) { if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) {
auto surf = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock()); auto surf = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock());
@ -620,13 +617,12 @@ void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource
if (!box.has_value()) if (!box.has_value())
return; return;
m_dnd.focusedDevice->sendMotion(Time::millis(Time::steadyNow()), V - box->pos()); m_dnd.focusedDevice->sendMotion(Time::millis(Time::steadyNow()), pos - box->pos());
LOGM(Log::DEBUG, "Drag motion {}", V - box->pos()); LOGM(Log::DEBUG, "Drag motion {}", pos - box->pos());
} }
}); });
m_dnd.touchMove = g_pHookSystem->hookDynamic("touchMove", [this](void* self, SCallbackInfo& info, std::any e) { m_dnd.touchMove = Event::bus()->m_events.input.touch.motion.listen([this](ITouch::SMotionEvent e, Event::SCallbackInfo&) {
auto E = std::any_cast<ITouch::SMotionEvent>(e);
if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) { if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) {
auto surf = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock()); auto surf = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock());
@ -638,8 +634,8 @@ void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource
if (!box.has_value()) if (!box.has_value())
return; return;
m_dnd.focusedDevice->sendMotion(E.timeMs, E.pos); m_dnd.focusedDevice->sendMotion(e.timeMs, e.pos);
LOGM(Log::DEBUG, "Drag motion {}", E.pos); LOGM(Log::DEBUG, "Drag motion {}", e.pos);
} }
}); });

View file

@ -178,11 +178,11 @@ class CWLDataDeviceProtocol : public IWaylandProtocol {
CHyprSignalListener dndSurfaceCommit; CHyprSignalListener dndSurfaceCommit;
// for ending a dnd // for ending a dnd
SP<HOOK_CALLBACK_FN> mouseMove; CHyprSignalListener mouseMove;
SP<HOOK_CALLBACK_FN> mouseButton; CHyprSignalListener mouseButton;
SP<HOOK_CALLBACK_FN> touchUp; CHyprSignalListener touchUp;
SP<HOOK_CALLBACK_FN> touchMove; CHyprSignalListener touchMove;
SP<HOOK_CALLBACK_FN> tabletTip; CHyprSignalListener tabletTip;
} m_dnd; } m_dnd;
void abortDrag(); void abortDrag();

View file

@ -19,7 +19,6 @@
#include "../protocols/core/Compositor.hpp" #include "../protocols/core/Compositor.hpp"
#include "../protocols/ColorManagement.hpp" #include "../protocols/ColorManagement.hpp"
#include "../protocols/types/ColorManagement.hpp" #include "../protocols/types/ColorManagement.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp" #include "../managers/eventLoop/EventLoopManager.hpp"
#include "../managers/CursorManager.hpp" #include "../managers/CursorManager.hpp"
@ -27,6 +26,7 @@
#include "../helpers/env/Env.hpp" #include "../helpers/env/Env.hpp"
#include "../helpers/MainLoopExecutor.hpp" #include "../helpers/MainLoopExecutor.hpp"
#include "../i18n/Engine.hpp" #include "../i18n/Engine.hpp"
#include "../event/EventBus.hpp"
#include "debug/HyprNotificationOverlay.hpp" #include "debug/HyprNotificationOverlay.hpp"
#include "hyprerror/HyprError.hpp" #include "hyprerror/HyprError.hpp"
#include "pass/TexPassElement.hpp" #include "pass/TexPassElement.hpp"
@ -391,7 +391,7 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() : m_drmFD(g_pCompositor->m_drmRenderNode.fd >
initAssets(); initAssets();
static auto P = g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any data) { preRender(std::any_cast<PHLMONITOR>(data)); }); static auto P = Event::bus()->m_events.render.pre.listen([&](PHLMONITOR mon) { preRender(mon); });
RASSERT(eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!"); RASSERT(eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!");
@ -422,23 +422,19 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() : m_drmFD(g_pCompositor->m_drmRenderNode.fd >
#endif #endif
}; };
static auto P2 = g_pHookSystem->hookDynamic("mouseButton", [](void* self, SCallbackInfo& info, std::any e) { static auto P2 = Event::bus()->m_events.input.mouse.button.listen([](IPointer::SButtonEvent e, Event::SCallbackInfo&) {
auto E = std::any_cast<IPointer::SButtonEvent>(e); if (e.state != WL_POINTER_BUTTON_STATE_PRESSED)
if (E.state != WL_POINTER_BUTTON_STATE_PRESSED)
return; return;
addLastPressToHistory(g_pInputManager->getMouseCoordsInternal(), g_pInputManager->getClickMode() == CLICKMODE_KILL, false); addLastPressToHistory(g_pInputManager->getMouseCoordsInternal(), g_pInputManager->getClickMode() == CLICKMODE_KILL, false);
}); });
static auto P3 = g_pHookSystem->hookDynamic("touchDown", [](void* self, SCallbackInfo& info, std::any e) { static auto P3 = Event::bus()->m_events.input.touch.down.listen([](ITouch::SDownEvent e, Event::SCallbackInfo&) {
auto E = std::any_cast<ITouch::SDownEvent>(e); auto PMONITOR = g_pCompositor->getMonitorFromName(!e.device->m_boundOutput.empty() ? e.device->m_boundOutput : "");
auto PMONITOR = g_pCompositor->getMonitorFromName(!E.device->m_boundOutput.empty() ? E.device->m_boundOutput : "");
PMONITOR = PMONITOR ? PMONITOR : Desktop::focusState()->monitor(); PMONITOR = PMONITOR ? PMONITOR : Desktop::focusState()->monitor();
const auto TOUCH_COORDS = PMONITOR->m_position + (E.pos * PMONITOR->m_size); const auto TOUCH_COORDS = PMONITOR->m_position + (e.pos * PMONITOR->m_size);
addLastPressToHistory(TOUCH_COORDS, g_pInputManager->getClickMode() == CLICKMODE_KILL, true); addLastPressToHistory(TOUCH_COORDS, g_pInputManager->getClickMode() == CLICKMODE_KILL, true);
}); });

View file

@ -9,7 +9,6 @@
#include "../managers/CursorManager.hpp" #include "../managers/CursorManager.hpp"
#include "../managers/PointerManager.hpp" #include "../managers/PointerManager.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
#include "../managers/HookSystemManager.hpp"
#include "../managers/animation/AnimationManager.hpp" #include "../managers/animation/AnimationManager.hpp"
#include "../desktop/view/Window.hpp" #include "../desktop/view/Window.hpp"
#include "../desktop/view/LayerSurface.hpp" #include "../desktop/view/LayerSurface.hpp"
@ -30,6 +29,7 @@
#include "../layout/LayoutManager.hpp" #include "../layout/LayoutManager.hpp"
#include "../layout/space/Space.hpp" #include "../layout/space/Space.hpp"
#include "../i18n/Engine.hpp" #include "../i18n/Engine.hpp"
#include "../event/EventBus.hpp"
#include "helpers/CursorShapes.hpp" #include "helpers/CursorShapes.hpp"
#include "helpers/Monitor.hpp" #include "helpers/Monitor.hpp"
#include "pass/TexPassElement.hpp" #include "pass/TexPassElement.hpp"
@ -41,6 +41,7 @@
#include "../protocols/ColorManagement.hpp" #include "../protocols/ColorManagement.hpp"
#include "../protocols/types/ContentType.hpp" #include "../protocols/types/ContentType.hpp"
#include "../helpers/MiscFunctions.hpp" #include "../helpers/MiscFunctions.hpp"
#include "../event/EventBus.hpp"
#include "render/OpenGL.hpp" #include "render/OpenGL.hpp"
#include <hyprutils/utils/ScopeGuard.hpp> #include <hyprutils/utils/ScopeGuard.hpp>
@ -113,7 +114,7 @@ CHyprRenderer::CHyprRenderer() {
// cursor hiding stuff // cursor hiding stuff
static auto P = g_pHookSystem->hookDynamic("keyPress", [&](void* self, SCallbackInfo& info, std::any param) { static auto P = Event::bus()->m_events.input.keyboard.key.listen([&](IKeyboard::SKeyEvent e, Event::SCallbackInfo&) {
if (m_cursorHiddenConditions.hiddenOnKeyboard) if (m_cursorHiddenConditions.hiddenOnKeyboard)
return; return;
@ -121,7 +122,7 @@ CHyprRenderer::CHyprRenderer() {
ensureCursorRenderingMode(); ensureCursorRenderingMode();
}); });
static auto P2 = g_pHookSystem->hookDynamic("mouseMove", [&](void* self, SCallbackInfo& info, std::any param) { static auto P2 = Event::bus()->m_events.input.mouse.move.listen([&](Vector2D pos, Event::SCallbackInfo&) {
if (!m_cursorHiddenConditions.hiddenOnKeyboard && m_cursorHiddenConditions.hiddenOnTouch == g_pInputManager->m_lastInputTouch && if (!m_cursorHiddenConditions.hiddenOnKeyboard && m_cursorHiddenConditions.hiddenOnTouch == g_pInputManager->m_lastInputTouch &&
m_cursorHiddenConditions.hiddenOnTablet == g_pInputManager->m_lastInputTablet && !m_cursorHiddenConditions.hiddenOnTimeout) m_cursorHiddenConditions.hiddenOnTablet == g_pInputManager->m_lastInputTablet && !m_cursorHiddenConditions.hiddenOnTimeout)
return; return;
@ -133,7 +134,7 @@ CHyprRenderer::CHyprRenderer() {
ensureCursorRenderingMode(); ensureCursorRenderingMode();
}); });
static auto P3 = g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) { static auto P3 = Event::bus()->m_events.monitor.focused.listen([&](PHLMONITOR mon) {
g_pEventLoopManager->doLater([this]() { g_pEventLoopManager->doLater([this]() {
if (!g_pHyprError->active()) if (!g_pHyprError->active())
return; return;
@ -143,11 +144,9 @@ CHyprRenderer::CHyprRenderer() {
}); });
}); });
static auto P4 = g_pHookSystem->hookDynamic("windowUpdateRules", [&](void* self, SCallbackInfo& info, std::any param) { static auto P4 = Event::bus()->m_events.window.updateRules.listen([&](PHLWINDOW window) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(param); if (window->m_ruleApplicator->renderUnfocused().valueOrDefault())
addWindowToRenderUnfocused(window);
if (PWINDOW->m_ruleApplicator->renderUnfocused().valueOrDefault())
addWindowToRenderUnfocused(PWINDOW);
}); });
m_cursorTicker = wl_event_loop_add_timer(g_pCompositor->m_wlEventLoop, cursorTicker, nullptr); m_cursorTicker = wl_event_loop_add_timer(g_pCompositor->m_wlEventLoop, cursorTicker, nullptr);
@ -290,7 +289,7 @@ bool CHyprRenderer::shouldRenderWindow(PHLWINDOW pWindow) {
void CHyprRenderer::renderWorkspaceWindowsFullscreen(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, const Time::steady_tp& time) { void CHyprRenderer::renderWorkspaceWindowsFullscreen(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, const Time::steady_tp& time) {
PHLWINDOW pWorkspaceWindow = nullptr; PHLWINDOW pWorkspaceWindow = nullptr;
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); Event::bus()->m_events.render.stage.emit(RENDER_PRE_WINDOWS);
// loop over the tiled windows that are fading out // loop over the tiled windows that are fading out
for (auto const& w : g_pCompositor->m_windows) { for (auto const& w : g_pCompositor->m_windows) {
@ -381,7 +380,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(PHLMONITOR pMonitor, PHLWOR
void CHyprRenderer::renderWorkspaceWindows(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, const Time::steady_tp& time) { void CHyprRenderer::renderWorkspaceWindows(PHLMONITOR pMonitor, PHLWORKSPACE pWorkspace, const Time::steady_tp& time) {
PHLWINDOW lastWindow; PHLWINDOW lastWindow;
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); Event::bus()->m_events.render.stage.emit(RENDER_PRE_WINDOWS);
std::vector<PHLWINDOWREF> windows, tiledFadingOut; std::vector<PHLWINDOWREF> windows, tiledFadingOut;
windows.reserve(g_pCompositor->m_windows.size()); windows.reserve(g_pCompositor->m_windows.size());
@ -545,7 +544,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T
// for plugins // for plugins
g_pHyprOpenGL->m_renderData.currentWindow = pWindow; g_pHyprOpenGL->m_renderData.currentWindow = pWindow;
EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOW); Event::bus()->m_events.render.stage.emit(RENDER_PRE_WINDOW);
const auto fullAlpha = renderdata.alpha * renderdata.fadeAlpha; const auto fullAlpha = renderdata.alpha * renderdata.fadeAlpha;
@ -729,7 +728,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T
} }
} }
EMIT_HOOK_EVENT("render", RENDER_POST_WINDOW); Event::bus()->m_events.render.stage.emit(RENDER_POST_WINDOW);
g_pHyprOpenGL->m_renderData.currentWindow.reset(); g_pHyprOpenGL->m_renderData.currentWindow.reset();
} }
@ -941,7 +940,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPA
renderLayer(ls.lock(), pMonitor, time); renderLayer(ls.lock(), pMonitor, time);
} }
EMIT_HOOK_EVENT("render", RENDER_POST_WALLPAPER); Event::bus()->m_events.render.stage.emit(RENDER_POST_WALLPAPER);
for (auto const& ls : pMonitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) { for (auto const& ls : pMonitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) {
renderLayer(ls.lock(), pMonitor, time); renderLayer(ls.lock(), pMonitor, time);
@ -965,7 +964,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPA
renderLayer(ls.lock(), pMonitor, time); renderLayer(ls.lock(), pMonitor, time);
} }
EMIT_HOOK_EVENT("render", RENDER_POST_WALLPAPER); Event::bus()->m_events.render.stage.emit(RENDER_POST_WALLPAPER);
for (auto const& ls : pMonitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) { for (auto const& ls : pMonitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) {
renderLayer(ls.lock(), pMonitor, time); renderLayer(ls.lock(), pMonitor, time);
@ -1030,7 +1029,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(PHLMONITOR pMonitor, PHLWORKSPA
renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL); renderWindow(w, pMonitor, time, true, RENDER_PASS_ALL);
} }
EMIT_HOOK_EVENT("render", RENDER_POST_WINDOWS); Event::bus()->m_events.render.stage.emit(RENDER_POST_WINDOWS);
// Render surfaces above windows for monitor // Render surfaces above windows for monitor
for (auto const& ls : pMonitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { for (auto const& ls : pMonitor->m_layerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
@ -1330,7 +1329,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor, bool commit) {
pMonitor->m_drmFormat = pMonitor->m_prevDrmFormat; pMonitor->m_drmFormat = pMonitor->m_prevDrmFormat;
} }
EMIT_HOOK_EVENT("preRender", pMonitor); Event::bus()->m_events.render.pre.emit(pMonitor);
const auto NOW = Time::steadyNow(); const auto NOW = Time::steadyNow();
@ -1345,7 +1344,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor, bool commit) {
return; return;
} }
EMIT_HOOK_EVENT("render", RENDER_PRE); Event::bus()->m_events.render.stage.emit(RENDER_PRE);
pMonitor->m_renderingActive = true; pMonitor->m_renderingActive = true;
@ -1398,7 +1397,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor, bool commit) {
pMonitor->m_forceFullFrames = 0; pMonitor->m_forceFullFrames = 0;
} }
EMIT_HOOK_EVENT("render", RENDER_BEGIN); Event::bus()->m_events.render.stage.emit(RENDER_BEGIN);
bool renderCursor = true; bool renderCursor = true;
@ -1409,7 +1408,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor, bool commit) {
g_pHyprOpenGL->blend(false); g_pHyprOpenGL->blend(false);
g_pHyprOpenGL->renderMirrored(); g_pHyprOpenGL->renderMirrored();
g_pHyprOpenGL->blend(true); g_pHyprOpenGL->blend(true);
EMIT_HOOK_EVENT("render", RENDER_POST_MIRROR); Event::bus()->m_events.render.stage.emit(RENDER_POST_MIRROR);
renderCursor = false; renderCursor = false;
} else { } else {
CBox renderBox = {0, 0, sc<int>(pMonitor->m_pixelSize.x), sc<int>(pMonitor->m_pixelSize.y)}; CBox renderBox = {0, 0, sc<int>(pMonitor->m_pixelSize.x), sc<int>(pMonitor->m_pixelSize.y)};
@ -1462,7 +1461,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor, bool commit) {
m_renderPass.add(makeUnique<CRectPassElement>(data)); m_renderPass.add(makeUnique<CRectPassElement>(data));
} }
EMIT_HOOK_EVENT("render", RENDER_LAST_MOMENT); Event::bus()->m_events.render.stage.emit(RENDER_LAST_MOMENT);
endRender(); endRender();
@ -1484,7 +1483,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor, bool commit) {
pMonitor->m_renderingActive = false; pMonitor->m_renderingActive = false;
EMIT_HOOK_EVENT("render", RENDER_POST); Event::bus()->m_events.render.stage.emit(RENDER_POST);
pMonitor->m_output->state->addDamage(frameDamage); pMonitor->m_output->state->addDamage(frameDamage);
pMonitor->m_output->state->setPresentationMode(shouldTear ? Aquamarine::eOutputPresentationMode::AQ_OUTPUT_PRESENTATION_IMMEDIATE : pMonitor->m_output->state->setPresentationMode(shouldTear ? Aquamarine::eOutputPresentationMode::AQ_OUTPUT_PRESENTATION_IMMEDIATE :

View file

@ -4,7 +4,6 @@
#include "../../managers/eventLoop/EventLoopManager.hpp" #include "../../managers/eventLoop/EventLoopManager.hpp"
#include "../pass/BorderPassElement.hpp" #include "../pass/BorderPassElement.hpp"
#include "../Renderer.hpp" #include "../Renderer.hpp"
#include "../../managers/HookSystemManager.hpp"
CHyprBorderDecoration::CHyprBorderDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow), m_window(pWindow) { CHyprBorderDecoration::CHyprBorderDecoration(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow), m_window(pWindow) {
; ;

View file

@ -1,18 +1,11 @@
#include "DecorationPositioner.hpp" #include "DecorationPositioner.hpp"
#include "../../desktop/view/Window.hpp" #include "../../desktop/view/Window.hpp"
#include "../../managers/HookSystemManager.hpp"
#include "../../layout/target/Target.hpp" #include "../../layout/target/Target.hpp"
#include "../../event/EventBus.hpp"
CDecorationPositioner::CDecorationPositioner() { CDecorationPositioner::CDecorationPositioner() {
static auto P = g_pHookSystem->hookDynamic("closeWindow", [this](void* call, SCallbackInfo& info, std::any data) { static auto P = Event::bus()->m_events.window.close.listen([this](PHLWINDOW window) { onWindowUnmap(window); });
auto PWINDOW = std::any_cast<PHLWINDOW>(data); static auto P2 = Event::bus()->m_events.window.open.listen([this](PHLWINDOW window) { onWindowMap(window); });
this->onWindowUnmap(PWINDOW);
});
static auto P2 = g_pHookSystem->hookDynamic("openWindow", [this](void* call, SCallbackInfo& info, std::any data) {
auto PWINDOW = std::any_cast<PHLWINDOW>(data);
this->onWindowMap(PWINDOW);
});
} }
Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, PHLWINDOWREF pWindow) { Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, PHLWINDOWREF pWindow) {