shithub: mpl

Download patch

ref: 4f13cda5bf98bc825ffc7f7ef135f0b919523ad5
parent: 0a1d34375fe8c337100167df74058b0921b8cc03
author: Jacob Moody <[email protected]>
date: Wed Oct 16 07:27:09 EDT 2019

Added missing event source file

--- /dev/null
+++ b/event.c
@@ -1,0 +1,80 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <draw.h>
+#include <mouse.h>
+
+#include "dat.h"
+#include "fncs.h"
+
+Click click[128];
+Click *next;
+int size;
+
+enum{
+	MIN,
+	CIN,
+	ROLL,
+};
+
+Click*
+findpoint(Point xy)
+{
+	int i;
+	for(i=0;i<size;i++)
+		if(ptinrect(xy, click[i].r))
+			return click+i;
+	return nil;
+}
+
+void
+eventthread(void *arg)
+{
+	Mouse m;
+	Click c;
+	Channel **chans = arg;
+	Channel *min = chans[0];
+	Channel *cin = chans[1];
+	Channel *out = chans[2];
+	Channel *roll = chans[3];
+	free(chans);
+
+	Alt alts[] = {
+		{min, &m, CHANRCV},
+		{cin, &c, CHANRCV},
+		{roll, nil, CHANRCV},
+		{nil, nil, CHANEND},
+	};
+	for(;;)
+		switch(alt(alts)){
+		case CIN:
+			size++;
+			assert(size < 128);
+			click[size] = c;
+			break;
+		case MIN:
+			if(m.buttons != 1)
+				continue;
+			next = findpoint(m.xy);
+			if(next != nil)
+				send(out, next);
+			break;
+		case ROLL:
+			size = 0;
+			break;
+		}
+}
+
+void
+spawnevent(Channel *min, Channel *cin, Channel *out, Channel *rollback)
+{
+	Channel **chans;
+	size = 0;
+	chans = emalloc(sizeof(Channel*)*4);
+	chans[0] = min;
+	chans[1] = cin;
+	chans[2] = out;
+	chans[3] = rollback;
+	threadcreate(eventthread, chans, 8192);
+}
+