diff options
Diffstat (limited to 'src/libdraw/keyboard.c')
-rw-r--r-- | src/libdraw/keyboard.c | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/src/libdraw/keyboard.c b/src/libdraw/keyboard.c index 0a8ec010..755ffbd3 100644 --- a/src/libdraw/keyboard.c +++ b/src/libdraw/keyboard.c @@ -4,25 +4,18 @@ #include <thread.h> #include <keyboard.h> - void closekeyboard(Keyboardctl *kc) { + Rune r; + if(kc == nil) return; - postnote(PNPROC, kc->pid, "kill"); +/* postnote(PNPROC, kc->pid, "kill"); */ -#ifdef BUG - /* Drain the channel */ - while(?kc->c) - <-kc->c; -#endif - - close(kc->ctlfd); - close(kc->consfd); - free(kc->file); - free(kc->c); + do; while(nbrecv(kc->c, &r) > 0); + chanfree(kc->c); free(kc); } @@ -30,29 +23,15 @@ static void _ioproc(void *arg) { - int m, n; - char buf[20]; Rune r; Keyboardctl *kc; - + kc = arg; threadsetname("kbdproc"); - kc->pid = getpid(); - n = 0; for(;;){ - while(n>0 && fullrune(buf, n)){ - m = chartorune(&r, buf); - n -= m; - memmove(buf, buf+m, n); - send(kc->c, &r); - } - m = read(kc->consfd, buf+n, sizeof buf-n); - if(m <= 0){ - yield(); /* if error is due to exiting, we'll exit here */ - fprint(2, "keyboard read error: %r\n"); - threadexits("error"); - } - n += m; + if(_displayrdkbd(display, &r) < 0) + threadexits("read error"); + send(kc->c, &r); } } @@ -60,44 +39,14 @@ Keyboardctl* initkeyboard(char *file) { Keyboardctl *kc; - char *t; kc = mallocz(sizeof(Keyboardctl), 1); if(kc == nil) return nil; - if(file == nil) - file = "/dev/cons"; - kc->file = strdup(file); - kc->consfd = open(file, ORDWR|OCEXEC); - t = malloc(strlen(file)+16); - if(kc->consfd<0 || t==nil){ -Error1: - free(kc); - return nil; - } - sprint(t, "%sctl", file); - kc->ctlfd = open(t, OWRITE|OCEXEC); - if(kc->ctlfd < 0){ - fprint(2, "initkeyboard: can't open %s: %r\n", t); -Error2: - close(kc->consfd); - free(t); - goto Error1; - } - if(ctlkeyboard(kc, "rawon") < 0){ - fprint(2, "initkeyboard: can't turn on raw mode on %s: %r\n", t); - close(kc->ctlfd); - goto Error2; - } - free(t); + USED(file); kc->c = chancreate(sizeof(Rune), 20); chansetname(kc->c, "kbdc"); - proccreate(_ioproc, kc, 4096); + proccreate(_ioproc, kc, 32*1024); return kc; } -int -ctlkeyboard(Keyboardctl *kc, char *m) -{ - return write(kc->ctlfd, m, strlen(m)); -} |