8 closekeyboard(Keyboardctl *kc)
14 kc->consfd = kc->ctlfd = -1;
28 threadsetname("kbdproc");
31 while(kc->consfd >= 0){
32 while(n>0 && fullrune(buf, n)){
33 m = chartorune(&r, buf);
35 memmove(buf, buf+m, n);
36 if(send(kc->c, &r) < 0)
39 if((m = read(kc->consfd, buf+n, sizeof buf-n)) <= 0)
49 initkeyboard(char *file)
54 kc = mallocz(sizeof(Keyboardctl), 1);
59 kc->file = strdup(file);
60 kc->consfd = open(file, ORDWR|OCEXEC);
61 t = malloc(strlen(file)+16);
62 if(kc->consfd<0 || t==nil){
67 sprint(t, "%sctl", file);
68 kc->ctlfd = open(t, OWRITE|OCEXEC);
70 fprint(2, "initkeyboard: can't open %s: %r\n", t);
76 if(ctlkeyboard(kc, "rawon") < 0){
77 fprint(2, "initkeyboard: can't turn on raw mode on %s: %r\n", t);
82 kc->c = chancreate(sizeof(Rune), 20);
83 kc->pid = proccreate(_ioproc, kc, 4096);
88 ctlkeyboard(Keyboardctl *kc, char *m)
90 return write(kc->ctlfd, m, strlen(m));