2003-09-30 17:47:42 +00:00
|
|
|
#include <u.h>
|
2004-03-26 01:59:35 +00:00
|
|
|
#include "x11-inc.h"
|
2003-09-30 17:47:42 +00:00
|
|
|
#include <libc.h>
|
|
|
|
#include <draw.h>
|
|
|
|
#include <thread.h>
|
|
|
|
#include <memdraw.h>
|
|
|
|
#include <keyboard.h>
|
|
|
|
#include "x11-memdraw.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
closekeyboard(Keyboardctl *kc)
|
|
|
|
{
|
|
|
|
if(kc == nil)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* postnote(PNPROC, kc->pid, "kill");
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef BUG
|
|
|
|
/* Drain the channel */
|
|
|
|
while(?kc->c)
|
|
|
|
<-kc->c;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close(kc->ctlfd);
|
|
|
|
close(kc->consfd);
|
|
|
|
free(kc->file);
|
|
|
|
free(kc->c);
|
|
|
|
free(kc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
_ioproc(void *arg)
|
|
|
|
{
|
|
|
|
int i;
|
2004-02-29 22:10:26 +00:00
|
|
|
int fd;
|
2003-09-30 17:47:42 +00:00
|
|
|
Keyboardctl *kc;
|
|
|
|
Rune r;
|
|
|
|
XEvent xevent;
|
|
|
|
|
|
|
|
kc = arg;
|
|
|
|
threadsetname("kbdproc");
|
|
|
|
kc->pid = getpid();
|
2004-02-29 22:10:26 +00:00
|
|
|
fd = XConnectionNumber(_x.kbdcon);
|
2003-10-11 02:47:43 +00:00
|
|
|
XSelectInput(_x.kbdcon, _x.drawable, KeyPressMask);
|
2003-09-30 17:47:42 +00:00
|
|
|
for(;;){
|
2004-12-26 23:24:32 +00:00
|
|
|
XWindowEvent(_x.kbdcon, _x.drawable, KeyPressMask, &xevent);
|
2003-09-30 17:47:42 +00:00
|
|
|
switch(xevent.type){
|
|
|
|
case KeyPress:
|
2003-12-11 17:48:38 +00:00
|
|
|
i = _xtoplan9kbd(&xevent);
|
2003-09-30 17:47:42 +00:00
|
|
|
if(i == -1)
|
|
|
|
continue;
|
|
|
|
r = i;
|
|
|
|
send(kc->c, &r);
|
2003-12-11 17:48:38 +00:00
|
|
|
while((i=_xtoplan9kbd(nil)) >= 0){
|
2003-11-23 18:15:43 +00:00
|
|
|
r = i;
|
|
|
|
send(kc->c, &r);
|
|
|
|
}
|
2003-09-30 17:47:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Keyboardctl*
|
|
|
|
initkeyboard(char *file)
|
|
|
|
{
|
|
|
|
Keyboardctl *kc;
|
|
|
|
|
|
|
|
kc = mallocz(sizeof(Keyboardctl), 1);
|
|
|
|
if(kc == nil)
|
|
|
|
return nil;
|
|
|
|
kc->c = chancreate(sizeof(Rune), 20);
|
2004-12-26 23:24:32 +00:00
|
|
|
chansetname(kc->c, "kbdc");
|
|
|
|
proccreate(_ioproc, kc, 32768);
|
2003-09-30 17:47:42 +00:00
|
|
|
return kc;
|
|
|
|
}
|
|
|
|
|