diff --git a/examples/events.cpp b/examples/events.cpp index 549dfeb..4c39951 100644 --- a/examples/events.cpp +++ b/examples/events.cpp @@ -25,9 +25,6 @@ int main() { } }); - // Don't forget this: - conn.prepare_to_event_handling(); - while (true) { conn.handle_event(); } diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index b4c82f9..8b38a25 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -258,12 +258,6 @@ public: */ bool subscribe(const int32_t events); - /** - * Prepare connection to the handling of i3's events - * @note Used only in main() - */ - void prepare_to_event_handling(); - /** * Handle an event from i3 * @note Used only in main() @@ -294,6 +288,8 @@ public: sigc::signal signal_barconfig_update_event; ///< Barconfig update event signal sigc::signal signal_binding_event; ///< Binding event signal sigc::signal&> signal_event; ///< i3 event signal @note Default handler routes event to signal according to type +protected: + void prepare_to_event_handling(); private: const int32_t m_main_socket; int32_t m_event_socket; diff --git a/src/ipc.cpp b/src/ipc.cpp index a1c3f72..23a7ad6 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -329,9 +329,10 @@ void connection::prepare_to_event_handling() { m_event_socket = i3_connect(m_socket_path); this->subscribe(m_subscriptions); } + void connection::handle_event() { if (m_event_socket <= 0) { - throw std::runtime_error("event_socket_fd <= 0"); + this->prepare_to_event_handling(); } auto buf = i3_recv(m_event_socket);