From 6043f856b67be9289d54bba751a68df653bc00db Mon Sep 17 00:00:00 2001
From: patrick96
Date: Wed, 16 Mar 2022 22:18:18 +0100
Subject: [PATCH] controller: Keep only eventloop in try-catch
If an exception is thrown earlier, stopping the eventloop produces an
error.
---
include/x11/background_manager.hpp | 4 +-
src/components/controller.cpp | 70 +++++++++++++++---------------
src/x11/tray_manager.cpp | 2 +-
3 files changed, 38 insertions(+), 38 deletions(-)
diff --git a/include/x11/background_manager.hpp b/include/x11/background_manager.hpp
index e3ce3ced..dd9b0747 100644
--- a/include/x11/background_manager.hpp
+++ b/include/x11/background_manager.hpp
@@ -16,7 +16,7 @@ class logger;
namespace cairo {
class surface;
class xcb_surface;
-} // namespace cairo
+} // namespace cairo
class bg_slice {
public:
@@ -31,7 +31,7 @@ class bg_slice {
*
* This function is fast, since the current desktop background is cached.
*/
- cairo::surface* get_surface() const {
+ cairo::xcb_surface* get_surface() const {
return m_surface.get();
}
diff --git a/src/components/controller.cpp b/src/components/controller.cpp
index ec856766..100c90c2 100644
--- a/src/components/controller.cpp
+++ b/src/components/controller.cpp
@@ -238,45 +238,45 @@ void controller::screenshot_handler() {
void controller::read_events(bool confwatch) {
m_log.info("Entering event loop (thread-id=%lu)", this_thread::get_id());
- try {
- auto& poll_handle = m_loop.handle(m_connection.get_file_descriptor());
- 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);
+ if (!m_writeback) {
+ m_bar->start();
+ }
+
+ auto& poll_handle = m_loop.handle(m_connection.get_file_descriptor());
+ 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);
+ });
+
+ for (auto s : {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGALRM}) {
+ auto& signal_handle = m_loop.handle();
+ signal_handle.start(s, [this](const auto& e) { signal_handler(e.signum); });
+ }
+
+ if (confwatch) {
+ auto& fs_event_handle = m_loop.handle();
+ fs_event_handle.start(
+ m_conf.filepath(), 0, [this](const auto& e) { confwatch_handler(e.path); },
+ [this, &fs_event_handle](const auto& e) {
+ m_log.err("libuv error while watching config file for changes: %s", uv_strerror(e.status));
+ fs_event_handle.close();
});
+ }
- for (auto s : {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGALRM}) {
- auto& signal_handle = m_loop.handle();
- signal_handle.start(s, [this](const auto& e) { signal_handler(e.signum); });
- }
+ if (!m_snapshot_dst.empty()) {
+ // Trigger a single screenshot after 3 seconds
+ auto& timer_handle = m_loop.handle();
+ timer_handle.start(3000, 0, [this]() { screenshot_handler(); });
+ }
- if (confwatch) {
- auto& fs_event_handle = m_loop.handle();
- fs_event_handle.start(
- m_conf.filepath(), 0, [this](const auto& e) { confwatch_handler(e.path); },
- [this, &fs_event_handle](const auto& e) {
- m_log.err("libuv error while watching config file for changes: %s", uv_strerror(e.status));
- fs_event_handle.close();
- });
- }
-
- if (!m_snapshot_dst.empty()) {
- // Trigger a single screenshot after 3 seconds
- auto& timer_handle = m_loop.handle();
- timer_handle.start(3000, 0, [this]() { screenshot_handler(); });
- }
-
- if (!m_writeback) {
- m_bar->start();
- }
-
- /*
- * Immediately trigger and update so that the bar displays something.
- */
- trigger_update(true);
+ /*
+ * Immediately trigger and update so that the bar displays something.
+ */
+ trigger_update(true);
+ try {
m_loop.run();
} catch (const exception& err) {
m_log.err("Fatal Error in eventloop: %s", err.what());
diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp
index 31080cc0..5a6e1ccb 100644
--- a/src/x11/tray_manager.cpp
+++ b/src/x11/tray_manager.cpp
@@ -387,7 +387,7 @@ void tray_manager::reconfigure_bg() {
return m_log.err("tray: no context for drawing the background");
}
- cairo::surface* surface = m_bg_slice->get_surface();
+ cairo::xcb_surface* surface = m_bg_slice->get_surface();
if (!surface) {
return m_log.err("tray: no root surface");
}