Blob
1 #include "x11-inc.h"2 #include <u.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 Keyboardctl *kc;38 Rune r;39 XEvent xevent;41 kc = arg;42 threadsetname("kbdproc");43 kc->pid = getpid();44 XSelectInput(_x.kbdcon, _x.drawable, KeyPressMask);45 for(;;){46 XWindowEvent(_x.kbdcon, _x.drawable, KeyPressMask, &xevent);47 switch(xevent.type){48 case KeyPress:49 i = xtoplan9kbd(&xevent);50 if(i == -1)51 continue;52 r = i;53 send(kc->c, &r);54 break;55 }56 }57 }59 Keyboardctl*60 initkeyboard(char *file)61 {62 Keyboardctl *kc;64 kc = mallocz(sizeof(Keyboardctl), 1);65 if(kc == nil)66 return nil;67 kc->c = chancreate(sizeof(Rune), 20);68 proccreate(_ioproc, kc, 4096);69 return kc;70 }