mirror of
https://github.com/polybar/polybar.git
synced 2024-10-27 05:23:39 -04:00
controller: Keep only eventloop in try-catch
If an exception is thrown earlier, stopping the eventloop produces an error.
This commit is contained in:
parent
9b1afe7369
commit
6043f856b6
3 changed files with 38 additions and 38 deletions
|
@ -16,7 +16,7 @@ class logger;
|
||||||
namespace cairo {
|
namespace cairo {
|
||||||
class surface;
|
class surface;
|
||||||
class xcb_surface;
|
class xcb_surface;
|
||||||
} // namespace cairo
|
} // namespace cairo
|
||||||
|
|
||||||
class bg_slice {
|
class bg_slice {
|
||||||
public:
|
public:
|
||||||
|
@ -31,7 +31,7 @@ class bg_slice {
|
||||||
*
|
*
|
||||||
* This function is fast, since the current desktop background is cached.
|
* 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();
|
return m_surface.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,45 +238,45 @@ void controller::screenshot_handler() {
|
||||||
void controller::read_events(bool confwatch) {
|
void controller::read_events(bool confwatch) {
|
||||||
m_log.info("Entering event loop (thread-id=%lu)", this_thread::get_id());
|
m_log.info("Entering event loop (thread-id=%lu)", this_thread::get_id());
|
||||||
|
|
||||||
try {
|
if (!m_writeback) {
|
||||||
auto& poll_handle = m_loop.handle<PollHandle>(m_connection.get_file_descriptor());
|
m_bar->start();
|
||||||
poll_handle.start(
|
}
|
||||||
UV_READABLE, [this](const auto&) { conn_cb(); },
|
|
||||||
[this](const auto& e) {
|
auto& poll_handle = m_loop.handle<PollHandle>(m_connection.get_file_descriptor());
|
||||||
m_log.err("libuv error while polling X connection: "s + uv_strerror(e.status));
|
poll_handle.start(
|
||||||
stop(false);
|
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<SignalHandle>();
|
||||||
|
signal_handle.start(s, [this](const auto& e) { signal_handler(e.signum); });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (confwatch) {
|
||||||
|
auto& fs_event_handle = m_loop.handle<FSEventHandle>();
|
||||||
|
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}) {
|
if (!m_snapshot_dst.empty()) {
|
||||||
auto& signal_handle = m_loop.handle<SignalHandle>();
|
// Trigger a single screenshot after 3 seconds
|
||||||
signal_handle.start(s, [this](const auto& e) { signal_handler(e.signum); });
|
auto& timer_handle = m_loop.handle<TimerHandle>();
|
||||||
}
|
timer_handle.start(3000, 0, [this]() { screenshot_handler(); });
|
||||||
|
}
|
||||||
|
|
||||||
if (confwatch) {
|
/*
|
||||||
auto& fs_event_handle = m_loop.handle<FSEventHandle>();
|
* Immediately trigger and update so that the bar displays something.
|
||||||
fs_event_handle.start(
|
*/
|
||||||
m_conf.filepath(), 0, [this](const auto& e) { confwatch_handler(e.path); },
|
trigger_update(true);
|
||||||
[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<TimerHandle>();
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
try {
|
||||||
m_loop.run();
|
m_loop.run();
|
||||||
} catch (const exception& err) {
|
} catch (const exception& err) {
|
||||||
m_log.err("Fatal Error in eventloop: %s", err.what());
|
m_log.err("Fatal Error in eventloop: %s", err.what());
|
||||||
|
|
|
@ -387,7 +387,7 @@ void tray_manager::reconfigure_bg() {
|
||||||
return m_log.err("tray: no context for drawing the background");
|
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) {
|
if (!surface) {
|
||||||
return m_log.err("tray: no root surface");
|
return m_log.err("tray: no root surface");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue