Commit 1b10b83a0314acabb354799639043592670b1c45

Thomas de Grivel 2020-05-02T19:43:21

rtbuf-gtk output disconnect

diff --git a/gtk/rtbuf_gtk_output.c b/gtk/rtbuf_gtk_output.c
index 6438838..d7c379e 100644
--- a/gtk/rtbuf_gtk_output.c
+++ b/gtk/rtbuf_gtk_output.c
@@ -23,8 +23,23 @@
 
 void rtbuf_gtk_output_disconnect (RtbufOutputWidget *widget)
 {
-  (void) widget;
+  s_rtbuf *rtbuf;
+  unsigned int out;
+  s_rtbuf_gtk_connection **conn = &modular_connections;
   printf("rtbuf-gtk output disconnect\n");
+  rtbuf = rtbuf_output_widget_get_rtbuf(widget);
+  out = rtbuf_output_widget_get_out(widget);
+  rtbuf_out_unbind(rtbuf, out);
+  while (*conn) {
+    if ((*conn)->output_widget == widget) {
+      s_rtbuf_gtk_connection *tmp = *conn;
+      *conn = tmp->next;
+      rtbuf_gtk_connection_delete(tmp);
+    }
+    else
+      conn = &(*conn)->next;
+  }
+  gtk_widget_queue_draw(GTK_WIDGET(modular_layout));
 }
 
 void rtbuf_gtk_output_menu (RtbufOutputWidget *widget, GdkEvent *event)
diff --git a/librtbuf/include/rtbuf/rtbuf.h b/librtbuf/include/rtbuf/rtbuf.h
index 1d3780d..a9e48b1 100644
--- a/librtbuf/include/rtbuf/rtbuf.h
+++ b/librtbuf/include/rtbuf/rtbuf.h
@@ -51,7 +51,8 @@ int   librtbuf_init ();
 
 int   rtbuf_err (const char *msg);
 int   rtbuf_new (s_rtbuf_proc *rp);
-void  rtbuf_in_unbind (s_rtbuf *rtb, unsigned int var);
+void  rtbuf_in_unbind (s_rtbuf *rtb, unsigned int in);
+void  rtbuf_out_unbind (s_rtbuf *rtb, unsigned int out);
 void  rtbuf_unbind_all (s_rtbuf *rtb);
 void  rtbuf_delete (s_rtbuf *rtb);
 int   rtbuf_clone (s_rtbuf *rtb);
diff --git a/librtbuf/rtbuf.c b/librtbuf/rtbuf.c
index b3ccd71..cbab46c 100644
--- a/librtbuf/rtbuf.c
+++ b/librtbuf/rtbuf.c
@@ -90,6 +90,44 @@ void rtbuf_in_unbind (s_rtbuf *rtb, unsigned int in)
 }
 
 static
+void rtbuf_out_unbind_rtbuf (s_rtbuf *rtb, unsigned int rtb_i,
+                             unsigned int out, s_rtbuf *dest)
+{
+  unsigned int i = 0;
+  unsigned int n;
+  assert(dest);
+  n = dest->in_n;
+  while (i < dest->proc->in_n && n > 0 && rtb->refc) {
+    s_rtbuf_binding *v = &dest->in[i];
+    if (v->rtb >= 0) {
+      if ((unsigned int) v->rtb == rtb_i &&
+          v->out == out)
+        rtbuf_in_unbind(dest, i);
+      n--;
+    }
+    i++;
+  }
+}
+
+void rtbuf_out_unbind (s_rtbuf *rtb, unsigned int out)
+{
+  unsigned int rtb_i;
+  unsigned int i = 0;
+  unsigned int n = g_rtbuf_alloc.n - g_rtbuf_alloc.free_n;
+  assert(rtb);
+  assert(g_rtbuf <= rtb);
+  assert(rtb < g_rtbuf + RTBUF_MAX);
+  rtb_i = rtb - g_rtbuf;
+  while (i < g_rtbuf_alloc.n && n > 0) {
+    if (g_rtbuf[i].data) {
+      rtbuf_out_unbind_rtbuf(rtb, rtb_i, out, &g_rtbuf[i]);
+      n--;
+    }
+    i++;
+  }
+}
+
+static
 void rtbuf_unbind_all_out_rtbuf (s_rtbuf *rtb, unsigned int rtb_i,
                                  s_rtbuf *dest)
 {