Merge remote-tracking branch 'upstream/master' into tray-child-window
This commit is contained in:
commit
8ec9807145
@ -390,12 +390,27 @@ namespace eventloop {
|
||||
cb_connect connect_callback;
|
||||
};
|
||||
|
||||
class PrepareHandle : public Handle<PrepareHandle, uv_prepare_t> {
|
||||
public:
|
||||
using Handle::Handle;
|
||||
using cb = cb_void;
|
||||
|
||||
void init();
|
||||
void start(cb user_cb);
|
||||
|
||||
private:
|
||||
static void connect_cb(uv_connect_t* req, int status);
|
||||
|
||||
cb callback;
|
||||
};
|
||||
|
||||
class loop : public non_copyable_mixin, public non_movable_mixin {
|
||||
public:
|
||||
loop();
|
||||
~loop();
|
||||
void run();
|
||||
void stop();
|
||||
uint64_t now() const;
|
||||
|
||||
template <typename H, typename... Args>
|
||||
H& handle(Args... args) {
|
||||
@ -404,13 +419,12 @@ namespace eventloop {
|
||||
return ptr->leak(std::move(ptr));
|
||||
}
|
||||
|
||||
protected:
|
||||
uv_loop_t* get() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<uv_loop_t> m_loop{nullptr};
|
||||
};
|
||||
|
||||
} // namespace eventloop
|
||||
} // namespace eventloop
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
2
lib/xpp
2
lib/xpp
@ -1 +1 @@
|
||||
Subproject commit 7a9960bbb912f0ed66929c978aaeb1c30acf4bfd
|
||||
Subproject commit 343dc77d50bedab3c84b6e7cab70e1af2309eb0e
|
@ -1,7 +1,5 @@
|
||||
#include "components/controller.hpp"
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include <csignal>
|
||||
#include <utility>
|
||||
|
||||
@ -152,7 +150,7 @@ void controller::conn_cb() {
|
||||
}
|
||||
|
||||
shared_ptr<xcb_generic_event_t> evt{};
|
||||
while ((evt = shared_ptr<xcb_generic_event_t>(xcb_poll_for_event(m_connection), free)) != nullptr) {
|
||||
while ((evt = m_connection.poll_for_event()) != nullptr) {
|
||||
try {
|
||||
m_connection.dispatch_event(evt);
|
||||
} catch (xpp::connection_error& err) {
|
||||
@ -256,14 +254,25 @@ void controller::read_events(bool confwatch) {
|
||||
|
||||
start_modules();
|
||||
|
||||
auto& poll_handle = m_loop.handle<PollHandle>(m_connection.get_file_descriptor());
|
||||
poll_handle.start(
|
||||
auto& x_poll_handle = m_loop.handle<PollHandle>(m_connection.get_file_descriptor());
|
||||
x_poll_handle.start(
|
||||
UV_READABLE, [this](const auto&) { conn_cb(); },
|
||||
[this](const auto& e) {
|
||||
m_log.err("libuv error while polling X connection: "s + uv_strerror(e.status));
|
||||
stop(false);
|
||||
});
|
||||
|
||||
auto& x_prepare_handle = m_loop.handle<PrepareHandle>();
|
||||
x_prepare_handle.start([this]() {
|
||||
/*
|
||||
* We have to also handle events in the prepare handle (which runs right
|
||||
* before polling for IO) to process any already queued X events which
|
||||
* wouldn't trigger the uv_poll handle.
|
||||
*/
|
||||
conn_cb();
|
||||
m_connection.flush();
|
||||
});
|
||||
|
||||
for (auto s : {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGALRM}) {
|
||||
auto& signal_handle = m_loop.handle<SignalHandle>();
|
||||
signal_handle.start(s, [this](const auto& e) { signal_handler(e.signum); });
|
||||
|
@ -38,6 +38,9 @@ namespace eventloop {
|
||||
case UV_NAMED_PIPE:
|
||||
static_cast<PipeHandle*>(handle->data)->close();
|
||||
break;
|
||||
case UV_PREPARE:
|
||||
static_cast<PrepareHandle*>(handle->data)->close();
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
@ -157,6 +160,17 @@ namespace eventloop {
|
||||
}
|
||||
// }}}
|
||||
|
||||
// PrepareHandle {{{
|
||||
void PrepareHandle::init() {
|
||||
UV(uv_prepare_init, loop(), get());
|
||||
}
|
||||
|
||||
void PrepareHandle::start(cb user_cb) {
|
||||
this->callback = user_cb;
|
||||
UV(uv_prepare_start, get(), void_event_cb<&PrepareHandle::callback>);
|
||||
}
|
||||
// }}}
|
||||
|
||||
// eventloop {{{
|
||||
static void close_walk_cb(uv_handle_t* handle, void*) {
|
||||
if (!uv_is_closing(handle)) {
|
||||
@ -201,11 +215,15 @@ namespace eventloop {
|
||||
uv_stop(m_loop.get());
|
||||
}
|
||||
|
||||
uint64_t loop::now() const {
|
||||
return uv_now(m_loop.get());
|
||||
}
|
||||
|
||||
uv_loop_t* loop::get() const {
|
||||
return m_loop.get();
|
||||
}
|
||||
// }}}
|
||||
|
||||
} // namespace eventloop
|
||||
} // namespace eventloop
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
Loading…
Reference in New Issue
Block a user