From 6f8fc1ed7bb28b73418af16ae8afcd0cf11d2312 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Sat, 24 Oct 2015 19:04:00 -0400
Subject: [PATCH] add a hack for sending event notifications out the rightmost
 outlet of [draw group]

---
 pd/src/g_template.c | 11 ++++++++++-
 pd/src/m_obj.c      | 14 ++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/pd/src/g_template.c b/pd/src/g_template.c
index f1da44448..f4d8e2c59 100644
--- a/pd/src/g_template.c
+++ b/pd/src/g_template.c
@@ -1175,6 +1175,8 @@ typedef struct _drawimage
     t_pd *x_attr;
 } t_drawimage;
 
+extern t_outlet *obj_rightmost_outlet(t_object *x);
+
 void draw_notifyforscalar(t_object *x, t_glist *owner,
     t_scalar *sc, t_symbol *s, int argc, t_atom *argv)
 {
@@ -1187,8 +1189,15 @@ void draw_notifyforscalar(t_object *x, t_glist *owner,
     binbuf_add(b, 1, at);
     binbuf_add(b, argc, argv);
     if (x)
-        outlet_anything(x->ob_outlet, s, binbuf_getnatom(b),
+    {
+        t_outlet *out;
+        if (pd_class(&x->te_pd) == canvas_class)
+            out = obj_rightmost_outlet(x);
+        else
+            out = x->ob_outlet;
+        outlet_anything(out, s, binbuf_getnatom(b),
             binbuf_getvec(b));
+    }
     gpointer_unset(&gp);
     binbuf_free(b);
 }
diff --git a/pd/src/m_obj.c b/pd/src/m_obj.c
index 8849a53a3..5fffe35f2 100644
--- a/pd/src/m_obj.c
+++ b/pd/src/m_obj.c
@@ -579,6 +579,20 @@ int obj_noutlets(t_object *x)
     return (n);
 }
 
+/* used for draw_notify */
+t_outlet *obj_rightmost_outlet(t_object *x)
+{
+    t_outlet *o = x->ob_outlet;
+    if (o)
+    {
+        while (o->o_next)
+            o = o->o_next;
+        return o;
+    }
+    else
+        return 0;
+}
+
 int obj_ninlets(t_object *x)
 {
     int n;
-- 
GitLab