Peter Maydell | e16f4c8 | 2016-01-29 17:49:51 +0000 | [diff] [blame] | 1 | #include "qemu/osdep.h" |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 2 | #include "sysemu/sysemu.h" |
| 3 | #include "ui/keymaps.h" |
| 4 | #include "ui/input.h" |
| 5 | |
Gerd Hoffmann | 606eb0c | 2017-07-26 17:29:15 +0200 | [diff] [blame] | 6 | #include "standard-headers/linux/input.h" |
| 7 | |
Daniel P. Berrange | 2ec7870 | 2018-01-17 16:47:15 +0000 | [diff] [blame] | 8 | #include "ui/input-keymap-atset1-to-qcode.c" |
Daniel P. Berrange | bcd5ac9 | 2017-09-29 11:11:59 +0100 | [diff] [blame] | 9 | #include "ui/input-keymap-linux-to-qcode.c" |
Daniel P. Berrange | ab8f9d4 | 2018-01-17 16:41:15 +0000 | [diff] [blame^] | 10 | #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. Berrange | bcd5ac9 | 2017-09-29 11:11:59 +0100 | [diff] [blame] | 13 | #include "ui/input-keymap-qcode-to-qnum.c" |
| 14 | #include "ui/input-keymap-qnum-to-qcode.c" |
Owen Smith | de80d78 | 2017-11-03 11:56:28 +0000 | [diff] [blame] | 15 | #include "ui/input-keymap-qcode-to-linux.c" |
Daniel P. Berrange | ed7b262 | 2018-01-17 16:47:14 +0000 | [diff] [blame] | 16 | #include "ui/input-keymap-usb-to-qcode.c" |
Daniel P. Berrange | 2ec7870 | 2018-01-17 16:47:15 +0000 | [diff] [blame] | 17 | #include "ui/input-keymap-win32-to-qcode.c" |
| 18 | #include "ui/input-keymap-x11-to-qcode.c" |
| 19 | #include "ui/input-keymap-xorgevdev-to-qcode.c" |
| 20 | #include "ui/input-keymap-xorgkbd-to-qcode.c" |
| 21 | #include "ui/input-keymap-xorgxquartz-to-qcode.c" |
| 22 | #include "ui/input-keymap-xorgxwin-to-qcode.c" |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 23 | |
Gerd Hoffmann | 606eb0c | 2017-07-26 17:29:15 +0200 | [diff] [blame] | 24 | int qemu_input_linux_to_qcode(unsigned int lnx) |
| 25 | { |
Daniel P. Berrange | bcd5ac9 | 2017-09-29 11:11:59 +0100 | [diff] [blame] | 26 | if (lnx >= qemu_input_map_linux_to_qcode_len) { |
| 27 | return 0; |
| 28 | } |
| 29 | return qemu_input_map_linux_to_qcode[lnx]; |
Gerd Hoffmann | 606eb0c | 2017-07-26 17:29:15 +0200 | [diff] [blame] | 30 | } |
| 31 | |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 32 | int qemu_input_key_value_to_number(const KeyValue *value) |
| 33 | { |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 34 | if (value->type == KEY_VALUE_KIND_QCODE) { |
Daniel P. Berrange | bcd5ac9 | 2017-09-29 11:11:59 +0100 | [diff] [blame] | 35 | if (value->u.qcode.data >= qemu_input_map_qcode_to_qnum_len) { |
| 36 | return 0; |
| 37 | } |
| 38 | return qemu_input_map_qcode_to_qnum[value->u.qcode.data]; |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 39 | } else { |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 40 | assert(value->type == KEY_VALUE_KIND_NUMBER); |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 41 | return value->u.number.data; |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
Daniel P. Berrange | bcd5ac9 | 2017-09-29 11:11:59 +0100 | [diff] [blame] | 45 | int qemu_input_key_number_to_qcode(unsigned int nr) |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 46 | { |
Daniel P. Berrange | bcd5ac9 | 2017-09-29 11:11:59 +0100 | [diff] [blame] | 47 | if (nr >= qemu_input_map_qnum_to_qcode_len) { |
| 48 | return 0; |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 49 | } |
Daniel P. Berrange | bcd5ac9 | 2017-09-29 11:11:59 +0100 | [diff] [blame] | 50 | return qemu_input_map_qnum_to_qcode[nr]; |
Gerd Hoffmann | 11c7fa7 | 2014-05-21 13:28:32 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | int qemu_input_key_value_to_qcode(const KeyValue *value) |
| 54 | { |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 55 | if (value->type == KEY_VALUE_KIND_QCODE) { |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 56 | return value->u.qcode.data; |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 57 | } else { |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 58 | assert(value->type == KEY_VALUE_KIND_NUMBER); |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 59 | return qemu_input_key_number_to_qcode(value->u.number.data); |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | int qemu_input_key_value_to_scancode(const KeyValue *value, bool down, |
| 64 | int *codes) |
| 65 | { |
| 66 | int keycode = qemu_input_key_value_to_number(value); |
| 67 | int count = 0; |
| 68 | |
Eric Blake | 568c73a | 2015-10-26 16:34:58 -0600 | [diff] [blame] | 69 | if (value->type == KEY_VALUE_KIND_QCODE && |
Eric Blake | 32bafa8 | 2016-03-17 16:48:37 -0600 | [diff] [blame] | 70 | value->u.qcode.data == Q_KEY_CODE_PAUSE) { |
Gerd Hoffmann | 02aa76c | 2014-03-11 12:15:39 +0100 | [diff] [blame] | 71 | /* specific case */ |
| 72 | int v = down ? 0 : 0x80; |
| 73 | codes[count++] = 0xe1; |
| 74 | codes[count++] = 0x1d | v; |
| 75 | codes[count++] = 0x45 | v; |
| 76 | return count; |
| 77 | } |
| 78 | if (keycode & SCANCODE_GREY) { |
| 79 | codes[count++] = SCANCODE_EMUL0; |
| 80 | keycode &= ~SCANCODE_GREY; |
| 81 | } |
| 82 | if (!down) { |
| 83 | keycode |= SCANCODE_UP; |
| 84 | } |
| 85 | codes[count++] = keycode; |
| 86 | |
| 87 | return count; |
| 88 | } |