Recent changes to struct packing made it so that event names which are too long 
might not fire correctly. This fixes one such collection of events, being those 
pertining to graph vertex / edge selection and deselection by removing the 
graph- prefix from these event names.

This also adds an AG_LEGACY block to AddEvent which causes any events 
instantiated under the previous naming scheme to instead use the new naming 
scheme.

AG_Graph.3 has been updated appropriately.

See attached patch.

~ Charles
diff --git a/core/event.c b/core/event.c
index 54cc4f06e..f3bc6340b 100644
--- a/core/event.c
+++ b/core/event.c
@@ -312,7 +312,27 @@ AG_AddEvent(void *p, const char *name, AG_EventFn fn, const char *fmt, ...)
 		if (evOther != NULL)
 			ev->flags = evOther->flags;
 #endif
-		Strlcpy(ev->name, name, sizeof(ev->name));
+
+#ifdef AG_LEGACY
+		if (strcmp(name, "graph-vertex-selected") == 0) {
+			Strlcpy(ev->name, "vertex-selected", sizeof(ev->name));
+
+		} else if (strcmp(name, "graph-vertex-unselected") == 0) {
+			Strlcpy(ev->name, "vertex-unselected", sizeof(ev->name));
+
+		} else if (strcmp(name, "graph-edge-selected") == 0) {
+			Strlcpy(ev->name, "edge-selected", sizeof(ev->name));
+
+		} else if (strcmp(name, "graph-edge-unselected") == 0) {
+			Strlcpy(ev->name, "edge-unselected", sizeof(ev->name));
+
+		} else {
+#endif
+			Strlcpy(ev->name, name, sizeof(ev->name));
+
+#ifdef AG_LEGACY
+		}
+#endif
 	} else {
 		ev->name[0] = '\0';
 	}
diff --git a/gui/AG_Graph.3 b/gui/AG_Graph.3
index 62c85877c..d6184730c 100644
--- a/gui/AG_Graph.3
+++ b/gui/AG_Graph.3
@@ -226,15 +226,18 @@ The
 widget generates the following events:
 .Pp
 .Bl -tag -compact -width 2n
-.It Fn graph-vertex-selected "AG_GraphVertex *vtx"
+.It Fn vertex-selected "AG_GraphVertex *vtx"
 The specified vertex is now selected.
-.It Fn graph-vertex-unselected "AG_GraphVertex *vtx"
+.It Fn vertex-unselected "AG_GraphVertex *vtx"
 The specified vertex is no longer selected.
-.It Fn graph-edge-selected "AG_GraphEdge *edge"
+.It Fn edge-selected "AG_GraphEdge *edge"
 The specified edge is now selected.
-.It Fn graph-edge-unselected "AG_GraphEdge *edge"
+.It Fn edge-unselected "AG_GraphEdge *edge"
 The specified edge is no longer selected.
 .El
+.Pp
+Prior to Agar 1.6.0, event names were prefixed with "graph-". Support for this
+event naming style can be enabled with AG_LEGACY.
 .Sh STRUCTURE DATA
 For the
 .Ft AG_Graph
diff --git a/gui/graph.c b/gui/graph.c
index 9d9be33cd..e2157524f 100644
--- a/gui/graph.c
+++ b/gui/graph.c
@@ -305,7 +305,7 @@ static void
 UnselectEdge(AG_Graph *gf, AG_GraphEdge *edge)
 {
 	edge->flags &= ~(AG_GRAPH_SELECTED);
-	AG_PostEvent(NULL, gf, "graph-edge-unselected", "%p", edge);
+	AG_PostEvent(NULL, gf, "edge-unselected", "%p", edge);
 	AG_Redraw(gf);
 }
 
@@ -313,7 +313,7 @@ static void
 SelectEdge(AG_Graph *gf, AG_GraphEdge *edge)
 {
 	edge->flags |= AG_GRAPH_SELECTED;
-	AG_PostEvent(NULL, gf, "graph-edge-selected", "%p", edge);
+	AG_PostEvent(NULL, gf, "edge-selected", "%p", edge);
 	AG_Redraw(gf);
 }
 
@@ -321,7 +321,7 @@ static void
 UnselectVertex(AG_Graph *gf, AG_GraphVertex *vtx)
 {
 	vtx->flags &= ~(AG_GRAPH_SELECTED);
-	AG_PostEvent(NULL, gf, "graph-vertex-unselected", "%p", vtx);
+	AG_PostEvent(NULL, gf, "vertex-unselected", "%p", vtx);
 	AG_Redraw(gf);
 }
 
@@ -329,7 +329,7 @@ static void
 SelectVertex(AG_Graph *gf, AG_GraphVertex *vtx)
 {
 	vtx->flags |= AG_GRAPH_SELECTED;
-	AG_PostEvent(NULL, gf, "graph-vertex-selected", "%p", vtx);
+	AG_PostEvent(NULL, gf, "vertex-selected", "%p", vtx);
 	AG_Redraw(gf);
 }
 
_______________________________________________
Agar mailing list
[email protected]
http://libagar.org/lists.html

Reply via email to