shithub: libacme

Download patch

ref: 44f4cda90919a37dfd1fea113dc3ba02f2c7106c
parent: 2f6fbc8ffe5f528721887b7e1c257b643f9b1ef1
author: james palmer <foura@biobuf.link>
date: Wed Jun 2 12:17:43 EDT 2021

implement window functions

--- a/acme.h
+++ b/acme.h
@@ -1,7 +1,7 @@
 #pragma lib "libacme.a"
 
 enum {
-	Eventsz = 256 * UTFMax;
+	Eventsz = 256 * UTFmax,
 };
 
 typedef struct Win Win;
@@ -13,11 +13,12 @@
 	int data;
 };
 
-Win * wincreate();
-void winclose(Win *);
-void wintitle(Win *, char *, ...);
-void winctl(Win *, char *, ...);
-void winclear(Win *);
+Win *	wincreate(void);
+void	winclose(Win *);
+int		winopen(Win *, char *, int);
+void	wintitle(Win *, char *, ...);
+void	winctl(Win *, char *, ...);
+void	winclear(Win *);
 
 typedef struct Event Event;
 struct Event {
@@ -30,5 +31,5 @@
 	char text[Eventsz + 1];
 };
 
-void nextevent(Win *, Event *);
-void sendevent(Win *, Event *);
+void eventnext(Win *, Event *);
+void eventsend(Win *, Event *);
--- a/window.c
+++ b/window.c
@@ -1,0 +1,80 @@
+#include <u.h>
+#include <libc.h>
+
+#include "acme.h"
+
+int
+winopen(Win *w, char *f, int mode)
+{
+	char buf[128];
+	int fd;
+	
+	snprint(buf, sizeof(buf), "/mnt/wsys/%d/%s", w->id, f);
+	if((fd = open(buf, mode|OCEXEC)) < 0)
+		sysfatal("open %s: %r", buf);
+	return fd;
+}
+
+Win *
+wincreate(void)
+{
+	Win *w;
+	char buf[12];
+	
+	w = mallocz(sizeof(Win), 1);
+	w->ctl = open("/mnt/wsys/new/ctl", ORDWR|OCEXEC);
+	if(w->ctl < 0)
+		sysfatal("winopen: %r");
+	if(read(w->ctl, buf, sizeof(buf)) != sizeof(buf))
+		sysfatal("read ctl: %r");
+	
+	w->id = atoi(buf);
+	w->event = winopen(w, "event", ORDWR);
+	w->addr = winopen(w, "addr", ORDWR);
+	w->data = winopen(w, "data", ORDWR);
+	
+	return w;
+}
+
+void
+winclose(Win *w)
+{
+	fprint(w->ctl, "delete");
+	
+	close(w->event);
+	close(w->addr);
+	close(w->data);
+	
+	free(w);
+}
+
+void
+wintitle(Win *w, char *fmt, ...)
+{
+	char *title;
+	va_list args;
+	
+	va_start(args, fmt);
+	title = vsmprint(fmt, args);
+	va_end(args);
+	
+	winctl(w, "name %s\n", title);
+	free(title);
+}
+
+void
+winctl(Win *w, char *fmt, ...)
+{
+	va_list args;
+	
+	va_start(args, fmt);
+	vfprint(w->ctl, fmt, args);
+	va_end(args);
+}
+
+void
+winclear(Win *w)
+{
+	fprint(w->addr, ",");
+	fprint(w->data, "");
+}