fix: Handle X events before polling for IO ()

* Use m_connection.poll_for_event

* fix: Handle X events before polling for IO

Polling the XCB file descriptor for X events doesn't detect events that
are already in XCB's event queue but not yet handled.

If this happens, the eventloop polls for IO and the queued events wait
until another event arrives, causing some desyncs in the bar.

This can easily happen if something (e.g. a click event) triggers some
xcb calls, which as a consequence buffer some incoming events.

We "fix" this by adding a libuv prepare handle (which runs right before
polling for IO) that processes pending X events.
This commit is contained in:
Patrick Ziegler 2022-09-13 14:21:36 +02:00 committed by GitHub
parent 053a7eb2d8
commit 1d4e30c4be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 7 deletions
include/components

View file

@ -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