virkeycode-mapgen.py 2.0 KB
Newer Older
1
#!/usr/bin/python
L
Lai Jiangshan 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15

"""
Generate the big keycodes table for virkeys.
It read keymaps.csv from stdin and put the generated code to stdout.

Please keep keymaps.csv be exactly the same as:
http://git.gnome.org/browse/gtk-vnc/plain/src/keymaps.csv.
If anything inconsistent happens, please change this file
instead of keymaps.csv which is a mirror.
"""

import sys
import re

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
cols = (
    ["linux", True],
    ["linux", False],
    ["os_x", True],
    ["os_x", False],
    ["atset1", False],

    ["atset2", False],
    ["atset3", False],
    ["xt", False],
    ["xt_kbd", False],
    ["usb", False],

    ["win32", True],
    ["win32", False],
    [None, False],
    [None, False],
    ["rfb", False],
)

36
xtkbdkey_index = 8
L
Lai Jiangshan 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

def quotestring(str):
    if str[0] != '"':
        return '"' + str + '"'
    return str

print '''
/* Generated file, DON'T edit it */

#ifndef VIRT_KEY_INTERNAL
# error do not use this; it is not a public header
#endif

'''

sys.stdin.readline() # eat the fist line.

54 55 56 57
keycodes = []

max = 0

L
Lai Jiangshan 已提交
58
for line in sys.stdin.xreadlines():
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    values = re.match("([^,]*)," * 13 + "([^,]*)$", line[0:-1]).groups()

    data = []
    for v in values:
        data.append(v)

    # RFB keycodes are XT kbd keycodes with a slightly
    # different encoding of 0xe0 scan codes. RFB uses
    # the high bit of the first byte, instead of the low
    # bit of the second byte.
    rfbkey = int(data[xtkbdkey_index] or '0')
    rfbkey = (rfbkey & 0x100) >> 1 | (rfbkey & 0x7f)
    data.append("%d" % rfbkey)

    keycodes.append(data)
    max = max + 1

print "#define VIR_KEYMAP_ENTRY_MAX " + str(max)

for i in range(len(cols)):
    col=cols[i]
    name=col[0]
    isname=col[1]

    if name is None:
        continue

    if isname:
        print "const char *virKeymapNames_" + name + "[] = {"
    else:
M
Michal Privoznik 已提交
89
        print "int virKeymapValues_" + name + "[] = {"
90 91 92 93 94

    for entry in keycodes:
        if isname:
            print "  " + quotestring(entry[i] or "NULL") + ","
        else:
M
Michal Privoznik 已提交
95
            print "  " + (entry[i] or "-1") + ","
96 97

    print "};\n"