From bacfca5c3a34c453b665bafff1643a7ec56a5327 Mon Sep 17 00:00:00 2001 From: Mihir Lad Date: Thu, 23 Jul 2020 17:01:06 -0400 Subject: [PATCH] dwm: Sleep before attempting to reconnect to dwm Sleep before trying to reconnect to the dwm socket after a detected disconnection. If dwm is restarted in place, in most cases the reconnect will fail before dwm gets a change to re-setup itself and the socket. A 1-second delay can provide enough time for dwm to reinitalize itself before polybar attempts to reconnect. As a result, the module can recovoer instead of the entire application just quitting. --- src/modules/dwm.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/dwm.cpp b/src/modules/dwm.cpp index be437e10..0d256858 100644 --- a/src/modules/dwm.cpp +++ b/src/modules/dwm.cpp @@ -157,6 +157,7 @@ namespace modules { return m_ipc->handle_event(); } catch (const dwmipc::SocketClosedError& err) { m_log.err("%s: Disconnected from socket: %s", name(), err.what()); + sleep(chrono::duration(1)); return reconnect_dwm(); } catch (const dwmipc::IPCError& err) { m_log.err("%s: Failed to handle event (reason: %s)", name(), err.what()); @@ -248,6 +249,7 @@ namespace modules { return true; } catch (const dwmipc::SocketClosedError& err) { m_log.err("%s: Disconnected from socket: %s", name(), err.what()); + sleep(chrono::duration(1)); reconnect_dwm(); } catch (const dwmipc::IPCError& err) { throw module_error(err.what()); @@ -376,6 +378,7 @@ namespace modules { new_title = m_ipc->get_client(m_focused_client_id)->name; } catch (const dwmipc::SocketClosedError& err) { m_log.err("%s: Disconnected from socket: %s", name(), err.what()); + sleep(chrono::duration(1)); reconnect_dwm(); } catch (const dwmipc::IPCError& err) { throw module_error(err.what()); @@ -390,6 +393,7 @@ namespace modules { m_is_floating = m_ipc->get_client(m_focused_client_id)->states.is_floating; } catch (const dwmipc::SocketClosedError& err) { m_log.err("%s: Disconnected from socket: %s", name(), err.what()); + sleep(chrono::duration(1)); reconnect_dwm(); } catch (const dwmipc::IPCError& err) { throw module_error(err.what());