From 52a39616026924ce54b6e4e16387f401f9f719d9 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 13 Sep 2021 18:24:29 +0200
Subject: [PATCH] Poll for X events in while loop
Otherwise we would only read a single event, even if multiple were
available causing delays.
---
src/components/controller.cpp | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/components/controller.cpp b/src/components/controller.cpp
index 68a8cc0b..e04a2843 100644
--- a/src/components/controller.cpp
+++ b/src/components/controller.cpp
@@ -165,28 +165,30 @@ void controller::stop(bool reload) {
void controller::conn_cb(uv_poll_event) {
int xcb_error = m_connection.connection_has_error();
- if ((xcb_error = m_connection.connection_has_error()) > 0) {
+ if ((xcb_error = m_connection.connection_has_error()) != 0) {
m_log.err("X connection error, terminating... (what: %s)", m_connection.error_str(xcb_error));
stop(false);
return;
}
shared_ptr evt{};
- if ((evt = shared_ptr(xcb_poll_for_event(m_connection), free)) != nullptr) {
+ while ((evt = shared_ptr(xcb_poll_for_event(m_connection), free)) != nullptr) {
try {
m_connection.dispatch_event(evt);
} catch (xpp::connection_error& err) {
m_log.err("X connection error, terminating... (what: %s)", m_connection.error_str(err.code()));
+ stop(false);
} catch (const exception& err) {
m_log.err("Error in X event loop: %s", err.what());
- }
- } else {
- if ((xcb_error = m_connection.connection_has_error()) > 0) {
- m_log.err("X connection error, terminating... (what: %s)", m_connection.error_str(xcb_error));
stop(false);
- return;
}
}
+
+ if ((xcb_error = m_connection.connection_has_error()) != 0) {
+ m_log.err("X connection error, terminating... (what: %s)", m_connection.error_str(xcb_error));
+ stop(false);
+ return;
+ }
}
void controller::signal_handler(int signum) {