aboutsummaryrefslogtreecommitdiff
path: root/ui/input-keymap.c
blob: 663986a17baeb1c683d676096d51bb03ffc82183 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "qemu/osdep.h"
#include "sysemu/sysemu.h"
#include "ui/keymaps.h"
#include "ui/input.h"

#include "standard-headers/linux/input.h"

#include "ui/input-keymap-linux-to-qcode.c"
#include "ui/input-keymap-qcode-to-qnum.c"
#include "ui/input-keymap-qnum-to-qcode.c"
#include "ui/input-keymap-qcode-to-linux.c"

int qemu_input_linux_to_qcode(unsigned int lnx)
{
    if (lnx >= qemu_input_map_linux_to_qcode_len) {
        return 0;
    }
    return qemu_input_map_linux_to_qcode[lnx];
}

int qemu_input_key_value_to_number(const KeyValue *value)
{
    if (value->type == KEY_VALUE_KIND_QCODE) {
        if (value->u.qcode.data >= qemu_input_map_qcode_to_qnum_len) {
            return 0;
        }
        return qemu_input_map_qcode_to_qnum[value->u.qcode.data];
    } else {
        assert(value->type == KEY_VALUE_KIND_NUMBER);
        return value->u.number.data;
    }
}

int qemu_input_key_number_to_qcode(unsigned int nr)
{
    if (nr >= qemu_input_map_qnum_to_qcode_len) {
        return 0;
    }
    return qemu_input_map_qnum_to_qcode[nr];
}

int qemu_input_key_value_to_qcode(const KeyValue *value)
{
    if (value->type == KEY_VALUE_KIND_QCODE) {
        return value->u.qcode.data;
    } else {
        assert(value->type == KEY_VALUE_KIND_NUMBER);
        return qemu_input_key_number_to_qcode(value->u.number.data);
    }
}

int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
                                     int *codes)
{
    int keycode = qemu_input_key_value_to_number(value);
    int count = 0;

    if (value->type == KEY_VALUE_KIND_QCODE &&
        value->u.qcode.data == Q_KEY_CODE_PAUSE) {
        /* specific case */
        int v = down ? 0 : 0x80;
        codes[count++] = 0xe1;
        codes[count++] = 0x1d | v;
        codes[count++] = 0x45 | v;
        return count;
    }
    if (keycode & SCANCODE_GREY) {
        codes[count++] = SCANCODE_EMUL0;
        keycode &= ~SCANCODE_GREY;
    }
    if (!down) {
        keycode |= SCANCODE_UP;
    }
    codes[count++] = keycode;

    return count;
}