xref: /openbmc/qemu/ui/input-keymap.c (revision c39f95dc)
1 #include "qemu/osdep.h"
2 #include "sysemu/sysemu.h"
3 #include "ui/keymaps.h"
4 #include "ui/input.h"
5 
6 #include "standard-headers/linux/input.h"
7 
8 #include "ui/input-keymap-linux-to-qcode.c"
9 #include "ui/input-keymap-qcode-to-qnum.c"
10 #include "ui/input-keymap-qnum-to-qcode.c"
11 
12 int qemu_input_linux_to_qcode(unsigned int lnx)
13 {
14     if (lnx >= qemu_input_map_linux_to_qcode_len) {
15         return 0;
16     }
17     return qemu_input_map_linux_to_qcode[lnx];
18 }
19 
20 int qemu_input_key_value_to_number(const KeyValue *value)
21 {
22     if (value->type == KEY_VALUE_KIND_QCODE) {
23         if (value->u.qcode.data >= qemu_input_map_qcode_to_qnum_len) {
24             return 0;
25         }
26         return qemu_input_map_qcode_to_qnum[value->u.qcode.data];
27     } else {
28         assert(value->type == KEY_VALUE_KIND_NUMBER);
29         return value->u.number.data;
30     }
31 }
32 
33 int qemu_input_key_number_to_qcode(unsigned int nr)
34 {
35     if (nr >= qemu_input_map_qnum_to_qcode_len) {
36         return 0;
37     }
38     return qemu_input_map_qnum_to_qcode[nr];
39 }
40 
41 int qemu_input_key_value_to_qcode(const KeyValue *value)
42 {
43     if (value->type == KEY_VALUE_KIND_QCODE) {
44         return value->u.qcode.data;
45     } else {
46         assert(value->type == KEY_VALUE_KIND_NUMBER);
47         return qemu_input_key_number_to_qcode(value->u.number.data);
48     }
49 }
50 
51 int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
52                                      int *codes)
53 {
54     int keycode = qemu_input_key_value_to_number(value);
55     int count = 0;
56 
57     if (value->type == KEY_VALUE_KIND_QCODE &&
58         value->u.qcode.data == Q_KEY_CODE_PAUSE) {
59         /* specific case */
60         int v = down ? 0 : 0x80;
61         codes[count++] = 0xe1;
62         codes[count++] = 0x1d | v;
63         codes[count++] = 0x45 | v;
64         return count;
65     }
66     if (keycode & SCANCODE_GREY) {
67         codes[count++] = SCANCODE_EMUL0;
68         keycode &= ~SCANCODE_GREY;
69     }
70     if (!down) {
71         keycode |= SCANCODE_UP;
72     }
73     codes[count++] = keycode;
74 
75     return count;
76 }
77