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 void
11 closekeyboard(Keyboardctl *kc)
12 {
13 if(kc == nil)
14 return;
16 /* postnote(PNPROC, kc->pid, "kill");
17 */
19 #ifdef BUG
20 /* Drain the channel */
21 while(?kc->c)
22 <-kc->c;
23 #endif
25 close(kc->ctlfd);
26 close(kc->consfd);
27 free(kc->file);
28 free(kc->c);
29 free(kc);
30 }
32 static
33 void
34 _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 while((i=_xtoplan9kbd(nil)) >= 0){
55 r = i;
56 send(kc->c, &r);
57 }
58 break;
59 }
60 }
61 }
63 Keyboardctl*
64 initkeyboard(char *file)
65 {
66 Keyboardctl *kc;
68 kc = mallocz(sizeof(Keyboardctl), 1);
69 if(kc == nil)
70 return nil;
71 kc->c = chancreate(sizeof(Rune), 20);
72 proccreate(_ioproc, kc, 4096);
73 return kc;
74 }