keyboard.c (735B)
1 #include <u.h> 2 #include <libc.h> 3 #include <draw.h> 4 #include <thread.h> 5 #include <keyboard.h> 6 7 void 8 closekeyboard(Keyboardctl *kc) 9 { 10 Rune r; 11 12 if(kc == nil) 13 return; 14 15 /* postnote(PNPROC, kc->pid, "kill"); */ 16 17 do; while(nbrecv(kc->c, &r) > 0); 18 chanfree(kc->c); 19 free(kc); 20 } 21 22 static 23 void 24 _ioproc(void *arg) 25 { 26 Rune r; 27 Keyboardctl *kc; 28 29 kc = arg; 30 threadsetname("kbdproc"); 31 for(;;){ 32 if(_displayrdkbd(display, &r) < 0) 33 threadexits("read error"); 34 send(kc->c, &r); 35 } 36 } 37 38 Keyboardctl* 39 initkeyboard(char *file) 40 { 41 Keyboardctl *kc; 42 43 kc = mallocz(sizeof(Keyboardctl), 1); 44 if(kc == nil) 45 return nil; 46 USED(file); 47 kc->c = chancreate(sizeof(Rune), 20); 48 chansetname(kc->c, "kbdc"); 49 proccreate(_ioproc, kc, 32*1024); 50 return kc; 51 }