mirror of https://github.com/hyprwm/Hyprland
hooksystem: add callbackinfo struct and cancellable events
This commit is contained in:
parent
c6233a790f
commit
a61eb7694d
|
@ -58,8 +58,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
||||||
|
|
||||||
HyprlandAPI::addNotification(PHANDLE, "Hello World from an example plugin!", CColor{0.f, 1.f, 1.f, 1.f}, 5000);
|
HyprlandAPI::addNotification(PHANDLE, "Hello World from an example plugin!", CColor{0.f, 1.f, 1.f, 1.f}, 5000);
|
||||||
|
|
||||||
HyprlandAPI::registerCallbackDynamic(PHANDLE, "activeWindow", [&](void* self, std::any data) { onActiveWindowChange(self, data); });
|
HyprlandAPI::registerCallbackDynamic(PHANDLE, "activeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onActiveWindowChange(self, data); });
|
||||||
HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, std::any data) { onNewWindow(self, data); });
|
HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); });
|
||||||
|
|
||||||
g_pCustomLayout = std::make_unique<CHyprCustomLayout>();
|
g_pCustomLayout = std::make_unique<CHyprCustomLayout>();
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,8 @@ enum eRenderStage
|
||||||
RENDER_POST_MIRROR, /* After rendering a mirror */
|
RENDER_POST_MIRROR, /* After rendering a mirror */
|
||||||
RENDER_PRE_WINDOW, /* Before rendering a window (any pass) Note some windows (e.g. tiled) may have 2 passes (main & popup) */
|
RENDER_PRE_WINDOW, /* Before rendering a window (any pass) Note some windows (e.g. tiled) may have 2 passes (main & popup) */
|
||||||
RENDER_POST_WINDOW, /* After rendering a window (any pass) */
|
RENDER_POST_WINDOW, /* After rendering a window (any pass) */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SCallbackInfo {
|
||||||
|
bool cancelled = false; /* on cancellable events, will cancel the event. */
|
||||||
};
|
};
|
|
@ -3,7 +3,7 @@
|
||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
|
|
||||||
CHyprNotificationOverlay::CHyprNotificationOverlay() {
|
CHyprNotificationOverlay::CHyprNotificationOverlay() {
|
||||||
g_pHookSystem->hookDynamic("focusedMon", [&](void* self, std::any param) {
|
g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) {
|
||||||
if (m_dNotifications.size() == 0)
|
if (m_dNotifications.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ CHyprError::CHyprError() {
|
||||||
m_fFadeOpacity.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), nullptr, AVARDAMAGE_NONE);
|
m_fFadeOpacity.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), nullptr, AVARDAMAGE_NONE);
|
||||||
m_fFadeOpacity.registerVar();
|
m_fFadeOpacity.registerVar();
|
||||||
|
|
||||||
g_pHookSystem->hookDynamic("focusedMon", [&](void* self, std::any param) {
|
g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) {
|
||||||
if (!m_bIsCreated)
|
if (!m_bIsCreated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ CHyprError::CHyprError() {
|
||||||
m_bMonitorChanged = true;
|
m_bMonitorChanged = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
g_pHookSystem->hookDynamic("preRender", [&](void* self, std::any param) {
|
g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any param) {
|
||||||
if (!m_bIsCreated)
|
if (!m_bIsCreated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ void CHookSystemManager::unhook(HOOK_CALLBACK_FN* fn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHookSystemManager::emit(const std::vector<SCallbackFNPtr>* callbacks, std::any data) {
|
void CHookSystemManager::emit(const std::vector<SCallbackFNPtr>* callbacks, SCallbackInfo& info, std::any data) {
|
||||||
if (callbacks->empty())
|
if (callbacks->empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ void CHookSystemManager::emit(const std::vector<SCallbackFNPtr>* callbacks, std:
|
||||||
|
|
||||||
if (!cb.handle) {
|
if (!cb.handle) {
|
||||||
// we don't guard hl hooks
|
// we don't guard hl hooks
|
||||||
(*cb.fn)(cb.fn, data);
|
(*cb.fn)(cb.fn, info, data);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ void CHookSystemManager::emit(const std::vector<SCallbackFNPtr>* callbacks, std:
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!setjmp(m_jbHookFaultJumpBuf))
|
if (!setjmp(m_jbHookFaultJumpBuf))
|
||||||
(*cb.fn)(cb.fn, data);
|
(*cb.fn)(cb.fn, info, data);
|
||||||
else {
|
else {
|
||||||
// this module crashed.
|
// this module crashed.
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
#include "../plugins/PluginAPI.hpp"
|
#include "../plugins/PluginAPI.hpp"
|
||||||
|
|
||||||
// global typedef for hooked functions. Passes itself as a ptr when called, and `data` additionally.
|
// global typedef for hooked functions. Passes itself as a ptr when called, and `data` additionally.
|
||||||
typedef std::function<void(void*, std::any)> HOOK_CALLBACK_FN;
|
|
||||||
|
typedef std::function<void(void*, SCallbackInfo& info, std::any data)> HOOK_CALLBACK_FN;
|
||||||
|
|
||||||
struct SCallbackFNPtr {
|
struct SCallbackFNPtr {
|
||||||
HOOK_CALLBACK_FN* fn = nullptr;
|
HOOK_CALLBACK_FN* fn = nullptr;
|
||||||
|
@ -22,7 +23,17 @@ struct SCallbackFNPtr {
|
||||||
#define EMIT_HOOK_EVENT(name, param) \
|
#define EMIT_HOOK_EVENT(name, param) \
|
||||||
{ \
|
{ \
|
||||||
static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent(name); \
|
static auto* const PEVENTVEC = g_pHookSystem->getVecForEvent(name); \
|
||||||
g_pHookSystem->emit(PEVENTVEC, param); \
|
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 {
|
class CHookSystemManager {
|
||||||
|
@ -34,7 +45,7 @@ class CHookSystemManager {
|
||||||
void hookStatic(const std::string& event, HOOK_CALLBACK_FN* fn, HANDLE handle = nullptr);
|
void hookStatic(const std::string& event, HOOK_CALLBACK_FN* fn, HANDLE handle = nullptr);
|
||||||
void unhook(HOOK_CALLBACK_FN* fn);
|
void unhook(HOOK_CALLBACK_FN* fn);
|
||||||
|
|
||||||
void emit(const std::vector<SCallbackFNPtr>* callbacks, std::any data = 0);
|
void emit(const std::vector<SCallbackFNPtr>* callbacks, SCallbackInfo& info, std::any data = 0);
|
||||||
std::vector<SCallbackFNPtr>* getVecForEvent(const std::string& event);
|
std::vector<SCallbackFNPtr>* getVecForEvent(const std::string& event);
|
||||||
|
|
||||||
bool m_bCurrentEventPlugin = false;
|
bool m_bCurrentEventPlugin = false;
|
||||||
|
|
|
@ -77,7 +77,7 @@ CKeybindManager::CKeybindManager() {
|
||||||
|
|
||||||
m_tScrollTimer.reset();
|
m_tScrollTimer.reset();
|
||||||
|
|
||||||
g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, std::any param) {
|
g_pHookSystem->hookDynamic("configReloaded", [this](void* hk, SCallbackInfo& info, std::any param) {
|
||||||
// clear cuz realloc'd
|
// clear cuz realloc'd
|
||||||
m_pActiveKeybind = nullptr;
|
m_pActiveKeybind = nullptr;
|
||||||
m_vPressedSpecialBinds.clear();
|
m_vPressedSpecialBinds.clear();
|
||||||
|
|
|
@ -97,11 +97,11 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
|
||||||
if (MOUSECOORDSFLOORED == m_vLastCursorPosFloored && !refocus)
|
if (MOUSECOORDSFLOORED == m_vLastCursorPosFloored && !refocus)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
EMIT_HOOK_EVENT_CANCELLABLE("mouseMove", MOUSECOORDSFLOORED);
|
||||||
|
|
||||||
if (time)
|
if (time)
|
||||||
g_pCompositor->notifyIdleActivity();
|
g_pCompositor->notifyIdleActivity();
|
||||||
|
|
||||||
EMIT_HOOK_EVENT("mouseMove", MOUSECOORDSFLOORED);
|
|
||||||
|
|
||||||
m_vLastCursorPosFloored = MOUSECOORDSFLOORED;
|
m_vLastCursorPosFloored = MOUSECOORDSFLOORED;
|
||||||
|
|
||||||
const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
|
const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
|
||||||
|
@ -422,9 +422,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputManager::onMouseButton(wlr_pointer_button_event* e) {
|
void CInputManager::onMouseButton(wlr_pointer_button_event* e) {
|
||||||
g_pCompositor->notifyIdleActivity();
|
EMIT_HOOK_EVENT_CANCELLABLE("mouseButton", e);
|
||||||
|
|
||||||
EMIT_HOOK_EVENT("mouseButton", e);
|
g_pCompositor->notifyIdleActivity();
|
||||||
|
|
||||||
m_tmrLastCursorMovement.reset();
|
m_tmrLastCursorMovement.reset();
|
||||||
|
|
||||||
|
@ -1580,7 +1580,7 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) {
|
||||||
wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
|
wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
|
||||||
eBorderIconDirection direction = BORDERICON_NONE;
|
eBorderIconDirection direction = BORDERICON_NONE;
|
||||||
wlr_box boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE),
|
wlr_box boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE),
|
||||||
box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)};
|
box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)};
|
||||||
|
|
||||||
if (!wlr_box_contains_point(&boxFullGrabInput, mouseCoords.x, mouseCoords.y) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) {
|
if (!wlr_box_contains_point(&boxFullGrabInput, mouseCoords.x, mouseCoords.y) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) {
|
||||||
direction = BORDERICON_NONE;
|
direction = BORDERICON_NONE;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "../../Compositor.hpp"
|
#include "../../Compositor.hpp"
|
||||||
|
|
||||||
CInputMethodRelay::CInputMethodRelay() {
|
CInputMethodRelay::CInputMethodRelay() {
|
||||||
g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, std::any param) { onKeyboardFocus(std::any_cast<wlr_surface*>(param)); });
|
g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<wlr_surface*>(param)); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
|
void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ Feel like the API is missing something you'd like to use in your plugin? Open an
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
typedef std::function<void(void*, std::any)> HOOK_CALLBACK_FN;
|
typedef std::function<void(void*, SCallbackInfo&, std::any)> HOOK_CALLBACK_FN;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string description;
|
std::string description;
|
||||||
|
|
|
@ -119,7 +119,7 @@ CScreencopyClient::~CScreencopyClient() {
|
||||||
CScreencopyClient::CScreencopyClient() {
|
CScreencopyClient::CScreencopyClient() {
|
||||||
lastMeasure.reset();
|
lastMeasure.reset();
|
||||||
lastFrame.reset();
|
lastFrame.reset();
|
||||||
tickCallback = g_pHookSystem->hookDynamic("tick", [&](void* self, std::any data) { onTick(); });
|
tickCallback = g_pHookSystem->hookDynamic("tick", [&](void* self, SCallbackInfo& info, std::any data) { onTick(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScreencopyClient::onTick() {
|
void CScreencopyClient::onTick() {
|
||||||
|
|
|
@ -58,9 +58,9 @@ 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) {
|
||||||
g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, std::any param) { this->updateAllOutputs(); });
|
g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
|
||||||
g_pHookSystem->hookDynamic("configReloaded", [this](void* self, std::any param) { this->updateAllOutputs(); });
|
g_pHookSystem->hookDynamic("configReloaded", [this](void* self, SCallbackInfo& info, std::any param) { this->updateAllOutputs(); });
|
||||||
g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, std::any param) {
|
g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
|
||||||
const auto PMONITOR = std::any_cast<CMonitor*>(param);
|
const auto PMONITOR = std::any_cast<CMonitor*>(param);
|
||||||
std::erase_if(m_vXDGOutputs, [&](const auto& other) {
|
std::erase_if(m_vXDGOutputs, [&](const auto& other) {
|
||||||
const auto REMOVE = other->monitor == PMONITOR;
|
const auto REMOVE = other->monitor == PMONITOR;
|
||||||
|
|
|
@ -37,7 +37,7 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() {
|
||||||
Debug::log(WARN, "!RENDERER: Using the legacy GLES2 renderer!");
|
Debug::log(WARN, "!RENDERER: Using the legacy GLES2 renderer!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_pHookSystem->hookDynamic("preRender", [&](void* self, std::any data) { preRender(std::any_cast<CMonitor*>(data)); });
|
g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any data) { preRender(std::any_cast<CMonitor*>(data)); });
|
||||||
|
|
||||||
RASSERT(eglMakeCurrent(wlr_egl_get_display(g_pCompositor->m_sWLREGL), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!");
|
RASSERT(eglMakeCurrent(wlr_egl_get_display(g_pCompositor->m_sWLREGL), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue