Blob
1 #include <u.h>2 #include "x11-inc.h"3 #include <libc.h>4 #include <draw.h>5 #include <thread.h>6 #include <memdraw.h>7 #include <keyboard.h>8 #include "x11-memdraw.h"10 void11 closekeyboard(Keyboardctl *kc)12 {13 if(kc == nil)14 return;16 /* postnote(PNPROC, kc->pid, "kill");17 */19 #ifdef BUG20 /* Drain the channel */21 while(?kc->c)22 <-kc->c;23 #endif25 close(kc->ctlfd);26 close(kc->consfd);27 free(kc->file);28 free(kc->c);29 free(kc);30 }32 static33 void34 _ioproc(void *arg)35 {36 int i;37 int fd;38 Keyboardctl *kc;39 Rune r;40 XEvent xevent;42 kc = arg;43 threadsetname("kbdproc");44 kc->pid = getpid();45 fd = XConnectionNumber(_x.kbdcon);46 XSelectInput(_x.kbdcon, _x.drawable, KeyPressMask);47 for(;;){48 XWindowEvent(_x.kbdcon, _x.drawable, KeyPressMask, &xevent);49 switch(xevent.type){50 case KeyPress:51 i = _xtoplan9kbd(&xevent);52 if(i == -1)53 continue;54 r = i;55 send(kc->c, &r);56 while((i=_xtoplan9kbd(nil)) >= 0){57 r = i;58 send(kc->c, &r);59 }60 break;61 }62 }63 }65 Keyboardctl*66 initkeyboard(char *file)67 {68 Keyboardctl *kc;70 kc = mallocz(sizeof(Keyboardctl), 1);71 if(kc == nil)72 return nil;73 kc->c = chancreate(sizeof(Rune), 20);74 chansetname(kc->c, "kbdc");75 proccreate(_ioproc, kc, 32768);76 return kc;77 }