#include #include #include #include #include #include #include Controlset *cs; int ctldeletequits = 1; // write volume int wv(int v) { int fd; if((fd = open("/dev/volume", OWRITE)) < 0) return -1; if(fprint(fd, "%d\n", v) < 0){ close(fd); return -1; } close(fd); return 0; } void usage(void) { fprint(2, "usage: %s\n", argv0); threadexitsall("usage"); } void threadmain(int argc, char *argv[]) { char *evs, *tok[4];; Channel *ev; Control *slider; ARGBEGIN{ default: usage(); }ARGEND if(argc != 0) usage(); initdraw(nil, nil, "vol"); initcontrols(); cs = newcontrolset(screen, nil, nil, nil); slider = createslider(cs, "slider"); //chanprint(cs->ctl, "slider border 1"); //chanprint(cs->ctl, "slider vis 8"); chanprint(cs->ctl, "slider absolute 1"); chanprint(cs->ctl, "slider max 100"); chanprint(cs->ctl, "slider value 50"); chanprint(cs->ctl, "slider clamp low 1"); chanprint(cs->ctl, "slider clamp high 0"); wv(50); ev = chancreate(sizeof(char*), 1); controlwire(slider, "event", ev); activate(slider); resizecontrolset(cs); for(evs = recvp(ev); evs != nil; evs = recvp(ev)){ // invert slider value if(tokenize(evs, tok, nelem(tok)) == 3) wv(100 - atoi(tok[2])); free(evs); } threadexitsall(nil); } void resizecontrolset(Controlset*) { Rectangle r; if(getwindow(display, Refnone) < 0) sysfatal("resize failed: %r"); r = insetrect(screen->r, 10); chanprint(cs->ctl, "slider rect %R\nslider show", r); }