]> Git Repo - qemu.git/blame - ui/input-legacy.c
target-arm: Add arm_boot_info secure_boot control
[qemu.git] / ui / input-legacy.c
CommitLineData
8f0056b7
PB
1/*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
9c17d615 25#include "sysemu/sysemu.h"
83c9089e 26#include "monitor/monitor.h"
28ecbaee 27#include "ui/console.h"
7b1b5d19 28#include "qapi/error.h"
e235cec3 29#include "qmp-commands.h"
e4c8f004 30#include "qapi-types.h"
b2d1674b 31#include "ui/keymaps.h"
9784e579 32#include "ui/input.h"
8f0056b7 33
72711efb
GH
34struct QEMUPutMouseEntry {
35 QEMUPutMouseEvent *qemu_put_mouse_event;
36 void *qemu_put_mouse_event_opaque;
37 int qemu_put_mouse_event_absolute;
edd85a3d
GH
38
39 /* new input core */
40 QemuInputHandler h;
41 QemuInputHandlerState *s;
42 int axis[INPUT_AXIS_MAX];
43 int buttons;
72711efb
GH
44};
45
5a37532d
GH
46struct QEMUPutKbdEntry {
47 QEMUPutKBDEvent *put_kbd;
48 void *opaque;
9784e579 49 QemuInputHandlerState *s;
5a37532d
GH
50};
51
72711efb
GH
52struct QEMUPutLEDEntry {
53 QEMUPutLEDEvent *put_led;
54 void *opaque;
55 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
56};
57
5a37532d
GH
58static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
59 QTAILQ_HEAD_INITIALIZER(led_handlers);
6fef28ee
AL
60static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
61 QTAILQ_HEAD_INITIALIZER(mouse_handlers);
8f0056b7 62
1048c88f
AK
63int index_from_key(const char *key)
64{
9d537c90 65 int i;
1048c88f
AK
66
67 for (i = 0; QKeyCode_lookup[i] != NULL; i++) {
68 if (!strcmp(key, QKeyCode_lookup[i])) {
69 break;
70 }
71 }
72
1048c88f
AK
73 /* Return Q_KEY_CODE_MAX if the key is invalid */
74 return i;
75}
76
ce53f2f9
GH
77static KeyValue *copy_key_value(KeyValue *src)
78{
79 KeyValue *dst = g_new(KeyValue, 1);
80 memcpy(dst, src, sizeof(*src));
81 return dst;
e4c8f004
AK
82}
83
9f328977 84void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
e4c8f004
AK
85 Error **errp)
86{
9f328977 87 KeyValueList *p;
e37f2024
GH
88 KeyValue **up = NULL;
89 int count = 0;
e4c8f004 90
e4c8f004 91 if (!has_hold_time) {
2e377f17 92 hold_time = 0; /* use default */
e4c8f004
AK
93 }
94
95 for (p = keys; p != NULL; p = p->next) {
ce53f2f9 96 qemu_input_event_send_key(NULL, copy_key_value(p->value), true);
2e377f17 97 qemu_input_event_send_key_delay(hold_time);
e37f2024
GH
98 up = g_realloc(up, sizeof(*up) * (count+1));
99 up[count] = copy_key_value(p->value);
100 count++;
2e377f17 101 }
e37f2024
GH
102 while (count) {
103 count--;
104 qemu_input_event_send_key(NULL, up[count], false);
2e377f17 105 qemu_input_event_send_key_delay(hold_time);
e4c8f004 106 }
e37f2024 107 g_free(up);
e4c8f004
AK
108}
109
9784e579
GH
110static void legacy_kbd_event(DeviceState *dev, QemuConsole *src,
111 InputEvent *evt)
112{
113 QEMUPutKbdEntry *entry = (QEMUPutKbdEntry *)dev;
02aa76c2 114 int scancodes[3], i, count;
9784e579
GH
115
116 if (!entry || !entry->put_kbd) {
117 return;
118 }
02aa76c2
GH
119 count = qemu_input_key_value_to_scancode(evt->key->key,
120 evt->key->down,
121 scancodes);
122 for (i = 0; i < count; i++) {
123 entry->put_kbd(entry->opaque, scancodes[i]);
9784e579 124 }
9784e579
GH
125}
126
127static QemuInputHandler legacy_kbd_handler = {
128 .name = "legacy-kbd",
129 .mask = INPUT_EVENT_MASK_KEY,
130 .event = legacy_kbd_event,
131};
132
5a37532d 133QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
8f0056b7 134{
5a37532d
GH
135 QEMUPutKbdEntry *entry;
136
9784e579 137 entry = g_new0(QEMUPutKbdEntry, 1);
5a37532d
GH
138 entry->put_kbd = func;
139 entry->opaque = opaque;
9784e579
GH
140 entry->s = qemu_input_handler_register((DeviceState *)entry,
141 &legacy_kbd_handler);
7f5e07d9 142 qemu_input_handler_activate(entry->s);
5a37532d 143 return entry;
8f0056b7
PB
144}
145
5a37532d 146void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
46aaebff 147{
9784e579
GH
148 qemu_input_handler_unregister(entry->s);
149 g_free(entry);
46aaebff
JS
150}
151
edd85a3d
GH
152static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
153 InputEvent *evt)
154{
155 static const int bmap[INPUT_BUTTON_MAX] = {
156 [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON,
157 [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
158 [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON,
159 };
160 QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
161
162 switch (evt->kind) {
163 case INPUT_EVENT_KIND_BTN:
164 if (evt->btn->down) {
165 s->buttons |= bmap[evt->btn->button];
166 } else {
167 s->buttons &= ~bmap[evt->btn->button];
168 }
dbb2a132
GH
169 if (evt->btn->down && evt->btn->button == INPUT_BUTTON_WHEEL_UP) {
170 s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
171 s->axis[INPUT_AXIS_X],
172 s->axis[INPUT_AXIS_Y],
173 -1,
174 s->buttons);
175 }
176 if (evt->btn->down && evt->btn->button == INPUT_BUTTON_WHEEL_DOWN) {
177 s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
178 s->axis[INPUT_AXIS_X],
179 s->axis[INPUT_AXIS_Y],
180 1,
181 s->buttons);
182 }
edd85a3d
GH
183 break;
184 case INPUT_EVENT_KIND_ABS:
185 s->axis[evt->abs->axis] = evt->abs->value;
186 break;
187 case INPUT_EVENT_KIND_REL:
188 s->axis[evt->rel->axis] += evt->rel->value;
189 break;
190 default:
191 break;
192 }
193}
194
195static void legacy_mouse_sync(DeviceState *dev)
196{
197 QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
198
199 s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
200 s->axis[INPUT_AXIS_X],
201 s->axis[INPUT_AXIS_Y],
202 0,
203 s->buttons);
204
205 if (!s->qemu_put_mouse_event_absolute) {
206 s->axis[INPUT_AXIS_X] = 0;
207 s->axis[INPUT_AXIS_Y] = 0;
208 }
209}
210
8f0056b7
PB
211QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
212 void *opaque, int absolute,
213 const char *name)
214{
6fef28ee 215 QEMUPutMouseEntry *s;
8f0056b7 216
7267c094 217 s = g_malloc0(sizeof(QEMUPutMouseEntry));
8f0056b7
PB
218
219 s->qemu_put_mouse_event = func;
220 s->qemu_put_mouse_event_opaque = opaque;
221 s->qemu_put_mouse_event_absolute = absolute;
8f0056b7 222
edd85a3d
GH
223 s->h.name = name;
224 s->h.mask = INPUT_EVENT_MASK_BTN |
225 (absolute ? INPUT_EVENT_MASK_ABS : INPUT_EVENT_MASK_REL);
226 s->h.event = legacy_mouse_event;
227 s->h.sync = legacy_mouse_sync;
228 s->s = qemu_input_handler_register((DeviceState *)s,
229 &s->h);
230
8f0056b7
PB
231 return s;
232}
233
6fef28ee 234void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
8f0056b7 235{
edd85a3d 236 qemu_input_handler_activate(entry->s);
6fef28ee 237}
8f0056b7 238
6fef28ee
AL
239void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
240{
edd85a3d
GH
241 qemu_input_handler_unregister(entry->s);
242
7267c094 243 g_free(entry);
8f0056b7
PB
244}
245
03a23a85
GH
246QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
247 void *opaque)
248{
249 QEMUPutLEDEntry *s;
250
7267c094 251 s = g_malloc0(sizeof(QEMUPutLEDEntry));
03a23a85
GH
252
253 s->put_led = func;
254 s->opaque = opaque;
255 QTAILQ_INSERT_TAIL(&led_handlers, s, next);
256 return s;
257}
258
259void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
260{
261 if (entry == NULL)
262 return;
263 QTAILQ_REMOVE(&led_handlers, entry, next);
7267c094 264 g_free(entry);
03a23a85
GH
265}
266
03a23a85
GH
267void kbd_put_ledstate(int ledstate)
268{
269 QEMUPutLEDEntry *cursor;
270
271 QTAILQ_FOREACH(cursor, &led_handlers, next) {
272 cursor->put_led(cursor->opaque, ledstate);
273 }
274}
This page took 0.411387 seconds and 4 git commands to generate.