blob: db5ccff5ad49a5d7f30cc2019eafde0259276dd0 [file] [log] [blame]
Peter Maydelle16f4c82016-01-29 17:49:51 +00001#include "qemu/osdep.h"
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +01002#include "sysemu/sysemu.h"
Michael S. Tsirkin0041e9a2018-05-03 22:51:00 +03003#include "keymaps.h"
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +01004#include "ui/input.h"
5
Gerd Hoffmann606eb0c2017-07-26 17:29:15 +02006#include "standard-headers/linux/input.h"
7
Daniel P. Berrange2ec78702018-01-17 16:47:15 +00008#include "ui/input-keymap-atset1-to-qcode.c"
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +01009#include "ui/input-keymap-linux-to-qcode.c"
Daniel P. Berrangeab8f9d42018-01-17 16:41:15 +000010#include "ui/input-keymap-qcode-to-atset1.c"
11#include "ui/input-keymap-qcode-to-atset2.c"
12#include "ui/input-keymap-qcode-to-atset3.c"
Daniel P. Berrange5a15e6b2018-01-17 16:41:17 +000013#include "ui/input-keymap-qcode-to-linux.c"
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010014#include "ui/input-keymap-qcode-to-qnum.c"
Daniel P. Berrangee709a612018-01-17 16:41:16 +000015#include "ui/input-keymap-qcode-to-sun.c"
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010016#include "ui/input-keymap-qnum-to-qcode.c"
Daniel P. Berrangeed7b2622018-01-17 16:47:14 +000017#include "ui/input-keymap-usb-to-qcode.c"
Daniel P. Berrange2ec78702018-01-17 16:47:15 +000018#include "ui/input-keymap-win32-to-qcode.c"
19#include "ui/input-keymap-x11-to-qcode.c"
20#include "ui/input-keymap-xorgevdev-to-qcode.c"
21#include "ui/input-keymap-xorgkbd-to-qcode.c"
22#include "ui/input-keymap-xorgxquartz-to-qcode.c"
23#include "ui/input-keymap-xorgxwin-to-qcode.c"
Keno Fischer656282d2018-06-13 19:51:56 -040024#include "ui/input-keymap-osx-to-qcode.c"
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010025
Gerd Hoffmann606eb0c2017-07-26 17:29:15 +020026int qemu_input_linux_to_qcode(unsigned int lnx)
27{
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010028 if (lnx >= qemu_input_map_linux_to_qcode_len) {
29 return 0;
30 }
31 return qemu_input_map_linux_to_qcode[lnx];
Gerd Hoffmann606eb0c2017-07-26 17:29:15 +020032}
33
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010034int qemu_input_key_value_to_number(const KeyValue *value)
35{
Eric Blake568c73a2015-10-26 16:34:58 -060036 if (value->type == KEY_VALUE_KIND_QCODE) {
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010037 if (value->u.qcode.data >= qemu_input_map_qcode_to_qnum_len) {
38 return 0;
39 }
40 return qemu_input_map_qcode_to_qnum[value->u.qcode.data];
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010041 } else {
Eric Blake568c73a2015-10-26 16:34:58 -060042 assert(value->type == KEY_VALUE_KIND_NUMBER);
Eric Blake32bafa82016-03-17 16:48:37 -060043 return value->u.number.data;
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010044 }
45}
46
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010047int qemu_input_key_number_to_qcode(unsigned int nr)
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010048{
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010049 if (nr >= qemu_input_map_qnum_to_qcode_len) {
50 return 0;
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010051 }
Daniel P. Berrangebcd5ac92017-09-29 11:11:59 +010052 return qemu_input_map_qnum_to_qcode[nr];
Gerd Hoffmann11c7fa72014-05-21 13:28:32 +020053}
54
55int qemu_input_key_value_to_qcode(const KeyValue *value)
56{
Eric Blake568c73a2015-10-26 16:34:58 -060057 if (value->type == KEY_VALUE_KIND_QCODE) {
Eric Blake32bafa82016-03-17 16:48:37 -060058 return value->u.qcode.data;
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010059 } else {
Eric Blake568c73a2015-10-26 16:34:58 -060060 assert(value->type == KEY_VALUE_KIND_NUMBER);
Eric Blake32bafa82016-03-17 16:48:37 -060061 return qemu_input_key_number_to_qcode(value->u.number.data);
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010062 }
63}
64
65int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
66 int *codes)
67{
68 int keycode = qemu_input_key_value_to_number(value);
69 int count = 0;
70
Eric Blake568c73a2015-10-26 16:34:58 -060071 if (value->type == KEY_VALUE_KIND_QCODE &&
Eric Blake32bafa82016-03-17 16:48:37 -060072 value->u.qcode.data == Q_KEY_CODE_PAUSE) {
Gerd Hoffmann02aa76c2014-03-11 12:15:39 +010073 /* specific case */
74 int v = down ? 0 : 0x80;
75 codes[count++] = 0xe1;
76 codes[count++] = 0x1d | v;
77 codes[count++] = 0x45 | v;
78 return count;
79 }
80 if (keycode & SCANCODE_GREY) {
81 codes[count++] = SCANCODE_EMUL0;
82 keycode &= ~SCANCODE_GREY;
83 }
84 if (!down) {
85 keycode |= SCANCODE_UP;
86 }
87 codes[count++] = keycode;
88
89 return count;
90}