diff --git a/include/components/eventloop.hpp b/include/components/eventloop.hpp index 89694e84..3aeae15a 100644 --- a/include/components/eventloop.hpp +++ b/include/components/eventloop.hpp @@ -128,6 +128,16 @@ struct PipeHandle : public UVHandleGeneric { + TimerHandle(uv_loop_t* loop, std::function fun) : UVHandle(fun) { + UV(uv_timer_init, loop, handle.get()); + } + + void start(uint64_t timeout, uint64_t repeat) { + UV(uv_timer_start, handle.get(), &cb.callback, timeout, repeat); + } +}; + class eventloop { public: eventloop(); diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 18d52fc9..94f10166 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -246,10 +246,6 @@ void controller::screenshot_handler() { trigger_update(true); } -static void screenshot_cb_wrapper(uv_timer_t* handle) { - static_cast(handle->data)->screenshot_handler(); -} - /** * Read events from configured file descriptors */ @@ -261,7 +257,7 @@ void controller::read_events(bool confwatch) { } auto ipc_handle = std::unique_ptr(nullptr); - auto screenshot_timer_handle = std::unique_ptr(nullptr); + auto screenshot_timer_handle = std::unique_ptr(nullptr); try { eloop = std::make_unique(); @@ -289,11 +285,9 @@ void controller::read_events(bool confwatch) { m_notifier->data = this; if (!m_snapshot_dst.empty()) { - screenshot_timer_handle = std::make_unique(); - UV(uv_timer_init, loop, screenshot_timer_handle.get()); - screenshot_timer_handle->data = this; - // Trigger a screenshot after 3 seconds - UV(uv_timer_start, screenshot_timer_handle.get(), screenshot_cb_wrapper, 3000, 0); + screenshot_timer_handle = std::make_unique(loop, [this]() { screenshot_handler(); }); + // Trigger a single screenshot after 3 seconds + screenshot_timer_handle->start(3000, 0); } m_eloop_ready.store(true);