]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/vnc/kbds.c
fix utf and rune handling in preparation for 32bit runes
[plan9front.git] / sys / src / cmd / vnc / kbds.c
1 #include        <u.h>
2 #include        <libc.h>
3 #include        <keyboard.h>
4 #include        "compat.h"
5 #include        "kbd.h"
6 #include   "ksym2utf.h"
7
8 enum {
9         VKSpecial = 0xff00,
10 };
11
12 static Rune vnckeys[] =
13 {
14 [0x00]  0,      0,      0,      0,      0,      0,      0,      0,
15 [0x08]  '\b',   '\t',   '\r',   0,      0,      '\n',   0,      0,
16 [0x10]  0,      0,      0,      0,      Kscroll,0,      0,      0,
17 [0x18]  0,      0,      0,      Kesc,   0,      0,      0,      0,
18 [0x20]  0,      0,      0,      0,      0,      0,      0,      0,
19 [0x28]  0,      0,      0,      0,      0,      0,      0,      0,
20 [0x30]  0,      0,      0,      0,      0,      0,      0,      0,
21 [0x38]  0,      0,      0,      0,      0,      0,      0,      0,
22 [0x40]  0,      0,      0,      0,      0,      0,      0,      0,
23 [0x48]  0,      0,      0,      0,      0,      0,      0,      0,
24 [0x50]  Khome,  Kleft,  Kup,    Kright, Kdown,  Kpgup,  Kpgdown,0,
25 [0x58]  0,      0,      0,      0,      0,      0,      0,      0,
26 [0x60]  0,      Kprint, 0,      Kins,   0,      0,      0,      0,
27 [0x68]  0,      0,      0,      Kbreak, 0,      0,      0,      0,
28 [0x70]  0,      0,      0,      0,      0,      0,      0,      0,
29 [0x78]  0,      0,      0,      0,      0,      0,      0,      Knum,
30 [0x80]  0,      0,      0,      0,      0,      0,      0,      0,
31 [0x88]  0,      0,      0,      0,      0,      0,      0,      0,
32 [0x90]  0,      0,      0,      0,      0,      0,      0,      0,
33 [0x98]  0,      0,      0,      0,      0,      0,      0,      0,
34 [0xa0]  0,      0,      0,      0,      0,      0,      0,      0,
35 [0xa8]  0,      0,      '*',    '+',    0,      '-',    '.',    '/',
36 [0xb0]  '0',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
37 [0xb8]  '8',    '9',    0,      0,      0,      '=',    0,      0,
38 [0xc0]  0,      0,      0,      0,      0,      0,      0,      0,
39 [0xc8]  0,      0,      0,      0,      0,      0,      0,      0,
40 [0xd0]  0,      0,      0,      0,      0,      0,      0,      0,
41 [0xd8]  0,      0,      0,      0,      0,      0,      0,      0,
42 [0xe0]  0,      Kshift, Kshift, Kctl,   Kctl,   Kcaps,  Kcaps,  0,
43 [0xe8]  0,      Kalt,   Kalt,   0,      0,      0,      0,      0,
44 [0xf0]  0,      0,      0,      0,      0,      0,      0,      0,
45 [0xf8]  0,      0,      0,      0,      0,      0,      0,      Kdel,
46 };
47
48 /*
49  *  keyboard interrupt
50  */
51 void
52 vncputc(int keyup, int c)
53 {
54         char buf[16];
55
56         /*
57          *  character mapping
58          */
59         if((c & VKSpecial) == VKSpecial){
60                 c = vnckeys[c & 0xff];
61                 if(c == 0)
62                         return;
63         }
64         /*
65          * map an xkeysym onto a utf-8 char
66          */
67         if((c & 0xff00) && c < nelem(ksym2utf) && ksym2utf[c] != 0)
68                 c = ksym2utf[c];
69         snprint(buf, sizeof(buf), "r%C", c);
70         if(keyup)
71                 buf[0] = 'R';
72         if(kbdin >= 0)
73                 write(kbdin, buf, strlen(buf)+1);
74 }