mirror of
https://github.com/polybar/polybar.git
synced 2024-11-18 13:55:11 -05:00
Add wrapper for uv_async_t
This commit is contained in:
parent
7b5285b51e
commit
2551ea0205
3 changed files with 13 additions and 10 deletions
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <moodycamel/blockingconcurrentqueue.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
@ -117,7 +116,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
|
|||
* This handle is used to notify the eventloop of changes which are not otherwise covered by other handles.
|
||||
* E.g. click actions.
|
||||
*/
|
||||
std::unique_ptr<uv_async_t> m_notifier{nullptr};
|
||||
std::unique_ptr<AsyncHandle> m_notifier{nullptr};
|
||||
|
||||
/**
|
||||
* Notification data for the controller.
|
||||
|
|
|
@ -138,6 +138,16 @@ struct TimerHandle : public UVHandle<uv_timer_t> {
|
|||
}
|
||||
};
|
||||
|
||||
struct AsyncHandle : public UVHandle<uv_async_t> {
|
||||
AsyncHandle(uv_loop_t* loop, std::function<void(void)> fun) : UVHandle(fun) {
|
||||
UV(uv_async_init, loop, handle.get(), &cb.callback);
|
||||
}
|
||||
|
||||
void send() {
|
||||
UV(uv_async_send, handle.get());
|
||||
}
|
||||
};
|
||||
|
||||
class eventloop {
|
||||
public:
|
||||
eventloop();
|
||||
|
|
|
@ -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<controller*>(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_async_t>();
|
||||
UV(uv_async_init, loop, m_notifier.get(), notifier_cb_wrapper);
|
||||
m_notifier->data = this;
|
||||
m_notifier = std::make_unique<AsyncHandle>(loop, [this]() { notifier_handler(); });
|
||||
|
||||
if (!m_snapshot_dst.empty()) {
|
||||
screenshot_timer_handle = std::make_unique<TimerHandle>(loop, [this]() { screenshot_handler(); });
|
||||
|
|
Loading…
Reference in a new issue