#include #include #include #include #include #include typedef struct X10 X10; struct X10 { char *name; char *file; Panel* g; int on; int err; int locked; }; X10 x10[50]; int nx10; char *dir = "/devs/x10"; Panel*gtop; void addx10(char* f) { int i, j, fd, nr; Dir* d; Dir* pd; char* fn; char xname[50]; if((fd = open(f, OREAD)) < 0) return; d = dirfstat(fd); if (d == nil){ close(fd); return; } if (d->qid.type&QTDIR){ nr = dirreadall(fd, &pd); for(i=0; ipanel && !x10[i].locked){ x10[i].on = !x10[i].on; writex10(i); drawx10(); break; } } void protect(Oev* g) { int i; char nam[40]; for (i = 0; i < nx10; i++) if (x10[i].g == g->panel){ x10togglelock(i); openpanel(x10[i].g, OWRITE|OTRUNC); if(x10[i].locked){ seprint(nam, nam+sizeof(nam), "[%s]", x10[i].name); writepanel(x10[i].g, nam, strlen(nam)); } else writepanel(x10[i].g, x10[i].name, strlen(x10[i].name)); closepanel(x10[i].g); drawx10(); break; } } void timerproc(void*a) { Channel*tc = a; for(;;){ sleep(3*1000); sendul(tc, 0); } } void usage(void) { fprint(2, "usage: x10/gui [file...]\n"); exits("usage"); } int omerogone(void) { sysfatal("gone"); return 0; } void threadmain(int argc, char *argv[]) { Oev e; int t; Alt a[] = { {nil, &e, CHANRCV}, {nil, &t, CHANRCV}, {nil, nil, CHANEND}, }; ARGBEGIN{ default: usage(); }ARGEND; gtop = createpanel("x10", "col", nil); if (gtop == nil) sysfatal("initgraph"); if (argc == 0) addx10("/devs/x10"); else while(argc--) addx10(*argv++); closepanelctl(gtop); a[0].c = omeroeventchan(nil); a[1].c = chancreate(sizeof(ulong), 0); proccreate(timerproc, a[1].c, 8*1024); updatex10(); drawx10(); for(;;){ switch(alt(a)){ case 0: if (!strcmp(e.ev, "look")) protect(&e); else if (!strcmp(e.ev, "exec")) toggle(&e); clearoev(&e); break; case 1: if (updatex10()) drawx10(); break; default: sysfatal("alt"); } } }