shithub: libacme

ref: 44f4cda90919a37dfd1fea113dc3ba02f2c7106c
dir: /window.c/

View raw version
#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, "");
}