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