1
0
Fork 0
mirror of https://github.com/9fans/plan9port.git synced 2025-01-21 11:40:03 +00:00
plan9port/src/libdraw/x11-keyboard.c
rsc 5a8e63b2f0 Fighting the good fight.
Move libfmt, libutf into subdirectories of lib9.

Add poll-based socket i/o to libthread, so that we can
avoid using multiple procs when possible, thus removing
dependence on crappy pthreads implementations.

Convert samterm, acme to the single-proc libthread.

Bring libcomplete, acme up-to-date w.r.t. Plan 9 distribution.
2004-02-29 22:10:26 +00:00

79 lines
1.2 KiB
C

#include "x11-inc.h"
#include <u.h>
#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;
int fd;
Keyboardctl *kc;
Rune r;
XEvent xevent;
kc = arg;
threadsetname("kbdproc");
kc->pid = getpid();
fd = XConnectionNumber(_x.kbdcon);
XSelectInput(_x.kbdcon, _x.drawable, KeyPressMask);
for(;;){
while(XCheckWindowEvent(_x.kbdcon, _x.drawable, KeyPressMask, &xevent) == False)
threadfdwait(fd, 'r');
switch(xevent.type){
case KeyPress:
i = _xtoplan9kbd(&xevent);
if(i == -1)
continue;
r = i;
send(kc->c, &r);
while((i=_xtoplan9kbd(nil)) >= 0){
r = i;
send(kc->c, &r);
}
break;
}
}
}
Keyboardctl*
initkeyboard(char *file)
{
Keyboardctl *kc;
threadfdwaitsetup();
kc = mallocz(sizeof(Keyboardctl), 1);
if(kc == nil)
return nil;
kc->c = chancreate(sizeof(Rune), 20);
threadcreate(_ioproc, kc, 4096);
return kc;
}