]> git.proxmox.com Git - mirror_qemu.git/blame - ui/input-legacy.c
input: mouse: add qemu_input_is_absolute()
[mirror_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;
38 char *qemu_put_mouse_event_name;
39
40 int index;
41
42 /* used internally by qemu for handling mice */
43 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
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);
5a37532d 62static NotifierList mouse_mode_notifiers =
7e581fb3 63 NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
8f0056b7 64
e4c8f004 65static const int key_defs[] = {
1048c88f
AK
66 [Q_KEY_CODE_SHIFT] = 0x2a,
67 [Q_KEY_CODE_SHIFT_R] = 0x36,
68
69 [Q_KEY_CODE_ALT] = 0x38,
70 [Q_KEY_CODE_ALT_R] = 0xb8,
71 [Q_KEY_CODE_ALTGR] = 0x64,
72 [Q_KEY_CODE_ALTGR_R] = 0xe4,
73 [Q_KEY_CODE_CTRL] = 0x1d,
74 [Q_KEY_CODE_CTRL_R] = 0x9d,
75
76 [Q_KEY_CODE_MENU] = 0xdd,
77
78 [Q_KEY_CODE_ESC] = 0x01,
79
80 [Q_KEY_CODE_1] = 0x02,
81 [Q_KEY_CODE_2] = 0x03,
82 [Q_KEY_CODE_3] = 0x04,
83 [Q_KEY_CODE_4] = 0x05,
84 [Q_KEY_CODE_5] = 0x06,
85 [Q_KEY_CODE_6] = 0x07,
86 [Q_KEY_CODE_7] = 0x08,
87 [Q_KEY_CODE_8] = 0x09,
88 [Q_KEY_CODE_9] = 0x0a,
89 [Q_KEY_CODE_0] = 0x0b,
90 [Q_KEY_CODE_MINUS] = 0x0c,
91 [Q_KEY_CODE_EQUAL] = 0x0d,
92 [Q_KEY_CODE_BACKSPACE] = 0x0e,
93
94 [Q_KEY_CODE_TAB] = 0x0f,
95 [Q_KEY_CODE_Q] = 0x10,
96 [Q_KEY_CODE_W] = 0x11,
97 [Q_KEY_CODE_E] = 0x12,
98 [Q_KEY_CODE_R] = 0x13,
99 [Q_KEY_CODE_T] = 0x14,
100 [Q_KEY_CODE_Y] = 0x15,
101 [Q_KEY_CODE_U] = 0x16,
102 [Q_KEY_CODE_I] = 0x17,
103 [Q_KEY_CODE_O] = 0x18,
104 [Q_KEY_CODE_P] = 0x19,
105 [Q_KEY_CODE_BRACKET_LEFT] = 0x1a,
106 [Q_KEY_CODE_BRACKET_RIGHT] = 0x1b,
107 [Q_KEY_CODE_RET] = 0x1c,
108
109 [Q_KEY_CODE_A] = 0x1e,
110 [Q_KEY_CODE_S] = 0x1f,
111 [Q_KEY_CODE_D] = 0x20,
112 [Q_KEY_CODE_F] = 0x21,
113 [Q_KEY_CODE_G] = 0x22,
114 [Q_KEY_CODE_H] = 0x23,
115 [Q_KEY_CODE_J] = 0x24,
116 [Q_KEY_CODE_K] = 0x25,
117 [Q_KEY_CODE_L] = 0x26,
118 [Q_KEY_CODE_SEMICOLON] = 0x27,
119 [Q_KEY_CODE_APOSTROPHE] = 0x28,
120 [Q_KEY_CODE_GRAVE_ACCENT] = 0x29,
121
122 [Q_KEY_CODE_BACKSLASH] = 0x2b,
123 [Q_KEY_CODE_Z] = 0x2c,
124 [Q_KEY_CODE_X] = 0x2d,
125 [Q_KEY_CODE_C] = 0x2e,
126 [Q_KEY_CODE_V] = 0x2f,
127 [Q_KEY_CODE_B] = 0x30,
128 [Q_KEY_CODE_N] = 0x31,
129 [Q_KEY_CODE_M] = 0x32,
130 [Q_KEY_CODE_COMMA] = 0x33,
131 [Q_KEY_CODE_DOT] = 0x34,
132 [Q_KEY_CODE_SLASH] = 0x35,
133
134 [Q_KEY_CODE_ASTERISK] = 0x37,
135
136 [Q_KEY_CODE_SPC] = 0x39,
137 [Q_KEY_CODE_CAPS_LOCK] = 0x3a,
138 [Q_KEY_CODE_F1] = 0x3b,
139 [Q_KEY_CODE_F2] = 0x3c,
140 [Q_KEY_CODE_F3] = 0x3d,
141 [Q_KEY_CODE_F4] = 0x3e,
142 [Q_KEY_CODE_F5] = 0x3f,
143 [Q_KEY_CODE_F6] = 0x40,
144 [Q_KEY_CODE_F7] = 0x41,
145 [Q_KEY_CODE_F8] = 0x42,
146 [Q_KEY_CODE_F9] = 0x43,
147 [Q_KEY_CODE_F10] = 0x44,
148 [Q_KEY_CODE_NUM_LOCK] = 0x45,
149 [Q_KEY_CODE_SCROLL_LOCK] = 0x46,
150
151 [Q_KEY_CODE_KP_DIVIDE] = 0xb5,
152 [Q_KEY_CODE_KP_MULTIPLY] = 0x37,
153 [Q_KEY_CODE_KP_SUBTRACT] = 0x4a,
154 [Q_KEY_CODE_KP_ADD] = 0x4e,
155 [Q_KEY_CODE_KP_ENTER] = 0x9c,
156 [Q_KEY_CODE_KP_DECIMAL] = 0x53,
157 [Q_KEY_CODE_SYSRQ] = 0x54,
158
159 [Q_KEY_CODE_KP_0] = 0x52,
160 [Q_KEY_CODE_KP_1] = 0x4f,
161 [Q_KEY_CODE_KP_2] = 0x50,
162 [Q_KEY_CODE_KP_3] = 0x51,
163 [Q_KEY_CODE_KP_4] = 0x4b,
164 [Q_KEY_CODE_KP_5] = 0x4c,
165 [Q_KEY_CODE_KP_6] = 0x4d,
166 [Q_KEY_CODE_KP_7] = 0x47,
167 [Q_KEY_CODE_KP_8] = 0x48,
168 [Q_KEY_CODE_KP_9] = 0x49,
169
170 [Q_KEY_CODE_LESS] = 0x56,
171
172 [Q_KEY_CODE_F11] = 0x57,
173 [Q_KEY_CODE_F12] = 0x58,
174
175 [Q_KEY_CODE_PRINT] = 0xb7,
176
177 [Q_KEY_CODE_HOME] = 0xc7,
178 [Q_KEY_CODE_PGUP] = 0xc9,
179 [Q_KEY_CODE_PGDN] = 0xd1,
180 [Q_KEY_CODE_END] = 0xcf,
181
182 [Q_KEY_CODE_LEFT] = 0xcb,
183 [Q_KEY_CODE_UP] = 0xc8,
184 [Q_KEY_CODE_DOWN] = 0xd0,
185 [Q_KEY_CODE_RIGHT] = 0xcd,
186
187 [Q_KEY_CODE_INSERT] = 0xd2,
188 [Q_KEY_CODE_DELETE] = 0xd3,
189#ifdef NEED_CPU_H
190#if defined(TARGET_SPARC) && !defined(TARGET_SPARC64)
191 [Q_KEY_CODE_STOP] = 0xf0,
192 [Q_KEY_CODE_AGAIN] = 0xf1,
193 [Q_KEY_CODE_PROPS] = 0xf2,
194 [Q_KEY_CODE_UNDO] = 0xf3,
195 [Q_KEY_CODE_FRONT] = 0xf4,
196 [Q_KEY_CODE_COPY] = 0xf5,
197 [Q_KEY_CODE_OPEN] = 0xf6,
198 [Q_KEY_CODE_PASTE] = 0xf7,
199 [Q_KEY_CODE_FIND] = 0xf8,
200 [Q_KEY_CODE_CUT] = 0xf9,
201 [Q_KEY_CODE_LF] = 0xfa,
202 [Q_KEY_CODE_HELP] = 0xfb,
203 [Q_KEY_CODE_META_L] = 0xfc,
204 [Q_KEY_CODE_META_R] = 0xfd,
205 [Q_KEY_CODE_COMPOSE] = 0xfe,
206#endif
207#endif
208 [Q_KEY_CODE_MAX] = 0,
209};
210
211int index_from_key(const char *key)
212{
9d537c90 213 int i;
1048c88f
AK
214
215 for (i = 0; QKeyCode_lookup[i] != NULL; i++) {
216 if (!strcmp(key, QKeyCode_lookup[i])) {
217 break;
218 }
219 }
220
1048c88f
AK
221 /* Return Q_KEY_CODE_MAX if the key is invalid */
222 return i;
223}
224
225int index_from_keycode(int code)
226{
227 int i;
228
229 for (i = 0; i < Q_KEY_CODE_MAX; i++) {
230 if (key_defs[i] == code) {
231 break;
232 }
233 }
234
235 /* Return Q_KEY_CODE_MAX if the code is invalid */
236 return i;
237}
238
05a3543d
LC
239static int *keycodes;
240static int keycodes_size;
e4c8f004
AK
241static QEMUTimer *key_timer;
242
9f328977
LC
243static int keycode_from_keyvalue(const KeyValue *value)
244{
245 if (value->kind == KEY_VALUE_KIND_QCODE) {
246 return key_defs[value->qcode];
247 } else {
248 assert(value->kind == KEY_VALUE_KIND_NUMBER);
249 return value->number;
250 }
251}
252
253static void free_keycodes(void)
254{
255 g_free(keycodes);
256 keycodes = NULL;
257 keycodes_size = 0;
258}
259
e4c8f004
AK
260static void release_keys(void *opaque)
261{
153d02e3 262 while (keycodes_size > 0) {
d2a92603
GH
263 qemu_input_event_send_key_number(NULL, keycodes[--keycodes_size],
264 false);
e4c8f004 265 }
05a3543d 266
9f328977 267 free_keycodes();
e4c8f004
AK
268}
269
9f328977 270void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
e4c8f004
AK
271 Error **errp)
272{
273 int keycode;
9f328977 274 KeyValueList *p;
e4c8f004
AK
275
276 if (!key_timer) {
bc72ad67 277 key_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, release_keys, NULL);
e4c8f004
AK
278 }
279
280 if (keycodes != NULL) {
bc72ad67 281 timer_del(key_timer);
e4c8f004
AK
282 release_keys(NULL);
283 }
05a3543d 284
e4c8f004
AK
285 if (!has_hold_time) {
286 hold_time = 100;
287 }
288
289 for (p = keys; p != NULL; p = p->next) {
e4c8f004 290 /* key down events */
9f328977
LC
291 keycode = keycode_from_keyvalue(p->value);
292 if (keycode < 0x01 || keycode > 0xff) {
312fd5f2 293 error_setg(errp, "invalid hex keycode 0x%x", keycode);
9f328977
LC
294 free_keycodes();
295 return;
296 }
297
d2a92603 298 qemu_input_event_send_key_number(NULL, keycode, true);
05a3543d
LC
299
300 keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1));
301 keycodes[keycodes_size++] = keycode;
e4c8f004 302 }
e4c8f004
AK
303
304 /* delayed key up events */
bc72ad67 305 timer_mod(key_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
e4c8f004
AK
306 muldiv64(get_ticks_per_sec(), hold_time, 1000));
307}
308
9784e579
GH
309static void legacy_kbd_event(DeviceState *dev, QemuConsole *src,
310 InputEvent *evt)
311{
312 QEMUPutKbdEntry *entry = (QEMUPutKbdEntry *)dev;
313 int keycode = keycode_from_keyvalue(evt->key->key);
314
315 if (!entry || !entry->put_kbd) {
316 return;
317 }
318 if (evt->key->key->kind == KEY_VALUE_KIND_QCODE &&
319 evt->key->key->qcode == Q_KEY_CODE_PAUSE) {
320 /* specific case */
321 int v = evt->key->down ? 0 : 0x80;
322 entry->put_kbd(entry->opaque, 0xe1);
323 entry->put_kbd(entry->opaque, 0x1d | v);
324 entry->put_kbd(entry->opaque, 0x45 | v);
325 return;
326 }
327 if (keycode & SCANCODE_GREY) {
328 entry->put_kbd(entry->opaque, SCANCODE_EMUL0);
329 keycode &= ~SCANCODE_GREY;
330 }
331 if (!evt->key->down) {
332 keycode |= SCANCODE_UP;
333 }
334 entry->put_kbd(entry->opaque, keycode);
335}
336
337static QemuInputHandler legacy_kbd_handler = {
338 .name = "legacy-kbd",
339 .mask = INPUT_EVENT_MASK_KEY,
340 .event = legacy_kbd_event,
341};
342
5a37532d 343QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
8f0056b7 344{
5a37532d
GH
345 QEMUPutKbdEntry *entry;
346
9784e579 347 entry = g_new0(QEMUPutKbdEntry, 1);
5a37532d
GH
348 entry->put_kbd = func;
349 entry->opaque = opaque;
9784e579
GH
350 entry->s = qemu_input_handler_register((DeviceState *)entry,
351 &legacy_kbd_handler);
5a37532d 352 return entry;
8f0056b7
PB
353}
354
5a37532d 355void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
46aaebff 356{
9784e579
GH
357 qemu_input_handler_unregister(entry->s);
358 g_free(entry);
46aaebff
JS
359}
360
7e581fb3
AL
361static void check_mode_change(void)
362{
363 static int current_is_absolute, current_has_absolute;
364 int is_absolute;
365 int has_absolute;
366
367 is_absolute = kbd_mouse_is_absolute();
368 has_absolute = kbd_mouse_has_absolute();
369
370 if (is_absolute != current_is_absolute ||
371 has_absolute != current_has_absolute) {
9e8dd451 372 notifier_list_notify(&mouse_mode_notifiers, NULL);
7e581fb3
AL
373 }
374
375 current_is_absolute = is_absolute;
376 current_has_absolute = has_absolute;
377}
378
8f0056b7
PB
379QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
380 void *opaque, int absolute,
381 const char *name)
382{
6fef28ee
AL
383 QEMUPutMouseEntry *s;
384 static int mouse_index = 0;
8f0056b7 385
7267c094 386 s = g_malloc0(sizeof(QEMUPutMouseEntry));
8f0056b7
PB
387
388 s->qemu_put_mouse_event = func;
389 s->qemu_put_mouse_event_opaque = opaque;
390 s->qemu_put_mouse_event_absolute = absolute;
7267c094 391 s->qemu_put_mouse_event_name = g_strdup(name);
6fef28ee 392 s->index = mouse_index++;
8f0056b7 393
6fef28ee 394 QTAILQ_INSERT_TAIL(&mouse_handlers, s, node);
8f0056b7 395
7e581fb3
AL
396 check_mode_change();
397
8f0056b7
PB
398 return s;
399}
400
6fef28ee 401void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
8f0056b7 402{
6fef28ee
AL
403 QTAILQ_REMOVE(&mouse_handlers, entry, node);
404 QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
8f0056b7 405
6fef28ee
AL
406 check_mode_change();
407}
8f0056b7 408
6fef28ee
AL
409void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
410{
411 QTAILQ_REMOVE(&mouse_handlers, entry, node);
8f0056b7 412
7267c094
AL
413 g_free(entry->qemu_put_mouse_event_name);
414 g_free(entry);
7e581fb3
AL
415
416 check_mode_change();
8f0056b7
PB
417}
418
03a23a85
GH
419QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
420 void *opaque)
421{
422 QEMUPutLEDEntry *s;
423
7267c094 424 s = g_malloc0(sizeof(QEMUPutLEDEntry));
03a23a85
GH
425
426 s->put_led = func;
427 s->opaque = opaque;
428 QTAILQ_INSERT_TAIL(&led_handlers, s, next);
429 return s;
430}
431
432void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
433{
434 if (entry == NULL)
435 return;
436 QTAILQ_REMOVE(&led_handlers, entry, next);
7267c094 437 g_free(entry);
03a23a85
GH
438}
439
8f0056b7
PB
440void kbd_put_keycode(int keycode)
441{
9784e579
GH
442 static bool emul0;
443 bool up;
5a37532d 444
9784e579
GH
445 if (keycode == SCANCODE_EMUL0) {
446 emul0 = true;
99c7f878
GH
447 return;
448 }
9784e579
GH
449 if (keycode & SCANCODE_UP) {
450 keycode &= ~SCANCODE_UP;
451 up = true;
452 } else {
453 up = false;
454 }
455 if (emul0) {
456 keycode |= SCANCODE_GREY;
457 emul0 = false;
8f0056b7 458 }
9784e579
GH
459
460 qemu_input_event_send_key_number(NULL, keycode, !up);
8f0056b7
PB
461}
462
03a23a85
GH
463void kbd_put_ledstate(int ledstate)
464{
465 QEMUPutLEDEntry *cursor;
466
467 QTAILQ_FOREACH(cursor, &led_handlers, next) {
468 cursor->put_led(cursor->opaque, ledstate);
469 }
470}
471
8f0056b7
PB
472void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
473{
6fef28ee 474 QEMUPutMouseEntry *entry;
8f0056b7
PB
475 QEMUPutMouseEvent *mouse_event;
476 void *mouse_event_opaque;
9312805d 477 int width, height;
8f0056b7 478
ad02b96a 479 if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
99c7f878
GH
480 return;
481 }
6fef28ee 482 if (QTAILQ_EMPTY(&mouse_handlers)) {
8f0056b7
PB
483 return;
484 }
485
6fef28ee
AL
486 entry = QTAILQ_FIRST(&mouse_handlers);
487
488 mouse_event = entry->qemu_put_mouse_event;
489 mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
8f0056b7
PB
490
491 if (mouse_event) {
9312805d
VK
492 if (entry->qemu_put_mouse_event_absolute) {
493 width = 0x7fff;
494 height = 0x7fff;
97697373 495 } else {
9312805d
VK
496 width = graphic_width - 1;
497 height = graphic_height - 1;
498 }
499
500 switch (graphic_rotate) {
501 case 0:
502 mouse_event(mouse_event_opaque,
503 dx, dy, dz, buttons_state);
504 break;
505 case 90:
506 mouse_event(mouse_event_opaque,
507 width - dy, dx, dz, buttons_state);
508 break;
509 case 180:
510 mouse_event(mouse_event_opaque,
511 width - dx, height - dy, dz, buttons_state);
512 break;
513 case 270:
514 mouse_event(mouse_event_opaque,
515 dy, height - dx, dz, buttons_state);
516 break;
97697373 517 }
8f0056b7
PB
518 }
519}
520
521int kbd_mouse_is_absolute(void)
522{
6fef28ee 523 if (QTAILQ_EMPTY(&mouse_handlers)) {
8f0056b7 524 return 0;
6fef28ee 525 }
8f0056b7 526
6fef28ee 527 return QTAILQ_FIRST(&mouse_handlers)->qemu_put_mouse_event_absolute;
8f0056b7
PB
528}
529
eb2e259d
AL
530int kbd_mouse_has_absolute(void)
531{
532 QEMUPutMouseEntry *entry;
533
534 QTAILQ_FOREACH(entry, &mouse_handlers, node) {
535 if (entry->qemu_put_mouse_event_absolute) {
536 return 1;
537 }
538 }
539
540 return 0;
541}
542
e235cec3 543MouseInfoList *qmp_query_mice(Error **errp)
8f0056b7 544{
e235cec3 545 MouseInfoList *mice_list = NULL;
8f0056b7 546 QEMUPutMouseEntry *cursor;
e235cec3 547 bool current = true;
8f0056b7 548
e235cec3
LC
549 QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
550 MouseInfoList *info = g_malloc0(sizeof(*info));
551 info->value = g_malloc0(sizeof(*info->value));
552 info->value->name = g_strdup(cursor->qemu_put_mouse_event_name);
553 info->value->index = cursor->index;
554 info->value->absolute = !!cursor->qemu_put_mouse_event_absolute;
555 info->value->current = current;
8f0056b7 556
e235cec3 557 current = false;
6fef28ee 558
e235cec3
LC
559 info->next = mice_list;
560 mice_list = info;
8f0056b7
PB
561 }
562
e235cec3 563 return mice_list;
8f0056b7
PB
564}
565
566void do_mouse_set(Monitor *mon, const QDict *qdict)
567{
568 QEMUPutMouseEntry *cursor;
8f0056b7 569 int index = qdict_get_int(qdict, "index");
6fef28ee 570 int found = 0;
8f0056b7 571
6fef28ee 572 if (QTAILQ_EMPTY(&mouse_handlers)) {
8f0056b7
PB
573 monitor_printf(mon, "No mouse devices connected\n");
574 return;
575 }
576
6fef28ee
AL
577 QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
578 if (cursor->index == index) {
579 found = 1;
580 qemu_activate_mouse_event_handler(cursor);
581 break;
582 }
8f0056b7
PB
583 }
584
6fef28ee 585 if (!found) {
8f0056b7 586 monitor_printf(mon, "Mouse at given index not found\n");
6fef28ee 587 }
7e581fb3
AL
588
589 check_mode_change();
590}
591
592void qemu_add_mouse_mode_change_notifier(Notifier *notify)
593{
594 notifier_list_add(&mouse_mode_notifiers, notify);
595}
596
597void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
598{
31552529 599 notifier_remove(notify);
8f0056b7 600}