aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/keyboard.c
blob: ef7b5802215f0f6d8f58772ae546aabeab02d146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <thread.h>
#include <keyboard.h>

void
closekeyboard(Keyboardctl *kc)
{
	Rune r;

	if(kc == nil)
		return;

/*	postnote(PNPROC, kc->pid, "kill"); */

	do; while(nbrecv(kc->c, &r) > 0);
	chanfree(kc->c);
	free(kc);
}

static
void
_ioproc(void *arg)
{
	Rune r;
	Keyboardctl *kc;

	kc = arg;
	threadsetname("kbdproc");
	for(;;){
		if(_displayrdkbd(display, &r) < 0)
			threadexits("read error");
		send(kc->c, &r);
	}
}

Keyboardctl*
initkeyboard(char *file)
{
	Keyboardctl *kc;

	kc = mallocz(sizeof(Keyboardctl), 1);
	if(kc == nil)
		return nil;
	USED(file);
	kc->c = chancreate(sizeof(Rune), 20);
	chansetname(kc->c, "kbdc");
	proccreate(_ioproc, kc, 32*1024);
	return kc;
}