blob: 1b756a6970c0049942486efff2f8ce61815c3f26 [file] [log] [blame]
Peter Maydelle16f4c82016-01-29 17:49:51 +00001#include "qemu/osdep.h"
Michael S. Tsirkin0041e9a2018-05-03 22:51:00 +03002#include "keymaps.h"
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +01003#include "ui/input.h"
4
Gerd Hoffmann606eb0c2017-07-26 17:29:15 +02005#include "standard-headers/linux/input.h"
6
Paolo Bonzini139c1832020-02-04 12:41:01 +01007#include "ui/input-keymap-atset1-to-qcode.c.inc"
8#include "ui/input-keymap-linux-to-qcode.c.inc"
9#include "ui/input-keymap-qcode-to-atset1.c.inc"
10#include "ui/input-keymap-qcode-to-atset2.c.inc"
11#include "ui/input-keymap-qcode-to-atset3.c.inc"
12#include "ui/input-keymap-qcode-to-linux.c.inc"
13#include "ui/input-keymap-qcode-to-qnum.c.inc"
14#include "ui/input-keymap-qcode-to-sun.c.inc"
15#include "ui/input-keymap-qnum-to-qcode.c.inc"
16#include "ui/input-keymap-usb-to-qcode.c.inc"
17#include "ui/input-keymap-win32-to-qcode.c.inc"
18#include "ui/input-keymap-x11-to-qcode.c.inc"
19#include "ui/input-keymap-xorgevdev-to-qcode.c.inc"
20#include "ui/input-keymap-xorgkbd-to-qcode.c.inc"
21#include "ui/input-keymap-xorgxquartz-to-qcode.c.inc"
22#include "ui/input-keymap-xorgxwin-to-qcode.c.inc"
23#include "ui/input-keymap-osx-to-qcode.c.inc"
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010024
Gerd Hoffmann606eb0c2017-07-26 17:29:15 +020025int qemu_input_linux_to_qcode(unsigned int lnx)
26{
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010027 if (lnx >= qemu_input_map_linux_to_qcode_len) {
28 return 0;
29 }
30 return qemu_input_map_linux_to_qcode[lnx];
Gerd Hoffmann606eb0c2017-07-26 17:29:15 +020031}
32
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010033int qemu_input_key_value_to_number(const KeyValue *value)
34{
Eric Blake568c73a2015-10-26 16:34:58 -060035 if (value->type == KEY_VALUE_KIND_QCODE) {
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010036 if (value->u.qcode.data >= qemu_input_map_qcode_to_qnum_len) {
37 return 0;
38 }
39 return qemu_input_map_qcode_to_qnum[value->u.qcode.data];
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010040 } else {
Eric Blake568c73a2015-10-26 16:34:58 -060041 assert(value->type == KEY_VALUE_KIND_NUMBER);
Eric Blake32bafa82016-03-17 16:48:37 -060042 return value->u.number.data;
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010043 }
44}
45
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010046int qemu_input_key_number_to_qcode(unsigned int nr)
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010047{
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010048 if (nr >= qemu_input_map_qnum_to_qcode_len) {
49 return 0;
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010050 }
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010051 return qemu_input_map_qnum_to_qcode[nr];
Gerd Hoffmann11c7fa72014-05-21 13:28:32 +020052}
53
54int qemu_input_key_value_to_qcode(const KeyValue *value)
55{
Eric Blake568c73a2015-10-26 16:34:58 -060056 if (value->type == KEY_VALUE_KIND_QCODE) {
Eric Blake32bafa82016-03-17 16:48:37 -060057 return value->u.qcode.data;
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010058 } else {
Eric Blake568c73a2015-10-26 16:34:58 -060059 assert(value->type == KEY_VALUE_KIND_NUMBER);
Eric Blake32bafa82016-03-17 16:48:37 -060060 return qemu_input_key_number_to_qcode(value->u.number.data);
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010061 }
62}
63
64int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
65 int *codes)
66{
67 int keycode = qemu_input_key_value_to_number(value);
68 int count = 0;
69
Eric Blake568c73a2015-10-26 16:34:58 -060070 if (value->type == KEY_VALUE_KIND_QCODE &&
Eric Blake32bafa82016-03-17 16:48:37 -060071 value->u.qcode.data == Q_KEY_CODE_PAUSE) {
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010072 /* specific case */
73 int v = down ? 0 : 0x80;
74 codes[count++] = 0xe1;
75 codes[count++] = 0x1d | v;
76 codes[count++] = 0x45 | v;
77 return count;
78 }
79 if (keycode & SCANCODE_GREY) {
80 codes[count++] = SCANCODE_EMUL0;
81 keycode &= ~SCANCODE_GREY;
82 }
83 if (!down) {
84 keycode |= SCANCODE_UP;
85 }
86 codes[count++] = keycode;
87
88 return count;
89}