#include #include i3ipcConnection * construct(GError **err); void on_shutdown(i3ipcConnection *connection, gpointer data); i3ipcConnection * construct(GError **err) { GError *tmp_err = NULL; i3ipcConnection *connection = i3ipc_connection_new(NULL, &tmp_err); if (tmp_err != NULL) { g_propagate_error(err, tmp_err); return NULL; } return connection; } void on_shutdown(i3ipcConnection *connection, gpointer data) { g_object_unref(connection); GError *err = NULL; i3ipcConnection *new_connection = construct(&err); while (NULL != err) { g_error_free(err); err = NULL; new_connection = construct(&err); } g_signal_connect(new_connection, "ipc-shutdown", G_CALLBACK(on_shutdown), NULL); } int main() { GError *err = NULL; i3ipcConnection *connection = construct(&err); g_signal_connect(connection, "ipc-shutdown", G_CALLBACK(on_shutdown), NULL); gtk_main(); return 0; }