plan9port/src/libdraw/keyboard.c

53 lines
737 B
C
Raw Normal View History

2003-09-30 17:47:42 +00:00
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <thread.h>
#include <keyboard.h>
void
closekeyboard(Keyboardctl *kc)
{
2006-06-25 18:59:29 +00:00
Rune r;
2003-09-30 17:47:42 +00:00
if(kc == nil)
return;
2006-06-25 18:59:29 +00:00
/* postnote(PNPROC, kc->pid, "kill"); */
2003-09-30 17:47:42 +00:00
2006-06-25 18:59:29 +00:00
do; while(nbrecv(kc->c, &r) > 0);
chanfree(kc->c);
2003-09-30 17:47:42 +00:00
free(kc);
}
static
void
_ioproc(void *arg)
{
Rune r;
Keyboardctl *kc;
2006-06-25 18:59:29 +00:00
2003-09-30 17:47:42 +00:00
kc = arg;
threadsetname("kbdproc");
for(;;){
2006-06-25 18:59:29 +00:00
if(_displayrdkbd(display, &r) < 0)
threadexits("read error");
send(kc->c, &r);
2003-09-30 17:47:42 +00:00
}
}
Keyboardctl*
initkeyboard(char *file)
{
Keyboardctl *kc;
kc = mallocz(sizeof(Keyboardctl), 1);
if(kc == nil)
return nil;
2006-06-25 18:59:29 +00:00
USED(file);
2003-09-30 17:47:42 +00:00
kc->c = chancreate(sizeof(Rune), 20);
2004-12-26 23:24:32 +00:00
chansetname(kc->c, "kbdc");
2006-06-25 18:59:29 +00:00
proccreate(_ioproc, kc, 32*1024);
2003-09-30 17:47:42 +00:00
return kc;
}