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 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 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 while(XCheckWindowEvent(_x.kbdcon, _x.drawable, KeyPressMask, &xevent) == False){
49 threadfdwait(fd, 'r');
50 }
51 switch(xevent.type){
52 case KeyPress:
53 i = _xtoplan9kbd(&xevent);
54 if(i == -1)
55 continue;
56 r = i;
57 send(kc->c, &r);
58 while((i=_xtoplan9kbd(nil)) >= 0){
59 r = i;
60 send(kc->c, &r);
61 }
62 break;
63 }
64 }
65 }
67 Keyboardctl*
68 initkeyboard(char *file)
69 {
70 Keyboardctl *kc;
72 threadfdwaitsetup();
73 kc = mallocz(sizeof(Keyboardctl), 1);
74 if(kc == nil)
75 return nil;
76 kc->c = chancreate(sizeof(Rune), 20);
77 threadcreate(_ioproc, kc, 32768);
78 return kc;
79 }