diff --git a/include/components/controller.hpp b/include/components/controller.hpp index 4370d3c3..323e59b5 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -117,7 +116,7 @@ class controller : public signal_receiver m_notifier{nullptr}; + std::unique_ptr m_notifier{nullptr}; /** * Notification data for the controller. diff --git a/include/components/eventloop.hpp b/include/components/eventloop.hpp index 3aeae15a..dabea632 100644 --- a/include/components/eventloop.hpp +++ b/include/components/eventloop.hpp @@ -138,6 +138,16 @@ struct TimerHandle : public UVHandle { } }; +struct AsyncHandle : public UVHandle { + AsyncHandle(uv_loop_t* loop, std::function fun) : UVHandle(fun) { + UV(uv_async_init, loop, handle.get(), &cb.callback); + } + + void send() { + UV(uv_async_send, handle.get()); + } +}; + class eventloop { public: eventloop(); diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 94f10166..e4fb8849 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -158,7 +158,7 @@ void controller::trigger_update(bool force) { void controller::trigger_notification() { if (m_eloop_ready) { - UV(uv_async_send, m_notifier.get()); + m_notifier->send(); } } @@ -237,10 +237,6 @@ void controller::notifier_handler() { } } -static void notifier_cb_wrapper(uv_async_t* handle) { - static_cast(handle->data)->notifier_handler(); -} - void controller::screenshot_handler() { m_sig.emit(signals::ui::request_snapshot{move(m_snapshot_dst)}); trigger_update(true); @@ -280,9 +276,7 @@ void controller::read_events(bool confwatch) { ipc_handle->start(m_ipc->get_file_descriptor()); } - m_notifier = std::make_unique(); - UV(uv_async_init, loop, m_notifier.get(), notifier_cb_wrapper); - m_notifier->data = this; + m_notifier = std::make_unique(loop, [this]() { notifier_handler(); }); if (!m_snapshot_dst.empty()) { screenshot_timer_handle = std::make_unique(loop, [this]() { screenshot_handler(); });