Commit d2a6b43af4aeb75c89d09f1a61d0247a4c63bb8f
1 parent
9aebe6a3
Add support for multiple simultaneously used keyboard devices.
Signed-off-by: Filip Navara <filip.navara@gmail.com>
Showing
2 changed files
with
63 additions
and
8 deletions
console.h
... | ... | @@ -25,7 +25,16 @@ typedef struct QEMUPutMouseEntry { |
25 | 25 | struct QEMUPutMouseEntry *next; |
26 | 26 | } QEMUPutMouseEntry; |
27 | 27 | |
28 | -void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque); | |
28 | +typedef struct QEMUPutKeyboardEntry { | |
29 | + QEMUPutKBDEvent *qemu_put_kbd_event; | |
30 | + void *qemu_put_kbd_event_opaque; | |
31 | + | |
32 | + /* used internally by qemu for handling mice */ | |
33 | + struct QEMUPutKeyboardEntry *next; | |
34 | +} QEMUPutKeyboardEntry; | |
35 | + | |
36 | +QEMUPutKeyboardEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque); | |
37 | +void qemu_remove_kbd_event_handler(QEMUPutKeyboardEntry *entry); | |
29 | 38 | QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, |
30 | 39 | void *opaque, int absolute, |
31 | 40 | const char *name); | ... | ... |
vl.c
... | ... | @@ -340,15 +340,57 @@ ram_addr_t qemu_balloon_status(void) |
340 | 340 | /***********************************************************/ |
341 | 341 | /* keyboard/mouse */ |
342 | 342 | |
343 | -static QEMUPutKBDEvent *qemu_put_kbd_event; | |
344 | -static void *qemu_put_kbd_event_opaque; | |
343 | +static QEMUPutKeyboardEntry *qemu_put_kbd_event_head; | |
345 | 344 | static QEMUPutMouseEntry *qemu_put_mouse_event_head; |
346 | 345 | static QEMUPutMouseEntry *qemu_put_mouse_event_current; |
347 | 346 | |
348 | -void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) | |
347 | +QEMUPutKeyboardEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) | |
349 | 348 | { |
350 | - qemu_put_kbd_event_opaque = opaque; | |
351 | - qemu_put_kbd_event = func; | |
349 | + QEMUPutKeyboardEntry *s, *cursor; | |
350 | + | |
351 | + s = qemu_mallocz(sizeof(QEMUPutKeyboardEntry)); | |
352 | + | |
353 | + s->qemu_put_kbd_event = func; | |
354 | + s->qemu_put_kbd_event_opaque = opaque; | |
355 | + s->next = NULL; | |
356 | + | |
357 | + if (!qemu_put_kbd_event_head) { | |
358 | + qemu_put_kbd_event_head = s; | |
359 | + return s; | |
360 | + } | |
361 | + | |
362 | + cursor = qemu_put_kbd_event_head; | |
363 | + while (cursor->next != NULL) | |
364 | + cursor = cursor->next; | |
365 | + | |
366 | + cursor->next = s; | |
367 | + | |
368 | + return s; | |
369 | +} | |
370 | + | |
371 | +void qemu_remove_kbd_event_handler(QEMUPutKeyboardEntry *entry) | |
372 | +{ | |
373 | + QEMUPutKeyboardEntry *prev = NULL, *cursor; | |
374 | + | |
375 | + if (!qemu_put_kbd_event_head || entry == NULL) | |
376 | + return; | |
377 | + | |
378 | + cursor = qemu_put_kbd_event_head; | |
379 | + while (cursor != NULL && cursor != entry) { | |
380 | + prev = cursor; | |
381 | + cursor = cursor->next; | |
382 | + } | |
383 | + | |
384 | + if (cursor == NULL) // does not exist or list empty | |
385 | + return; | |
386 | + else if (prev == NULL) { // entry is head | |
387 | + qemu_put_kbd_event_head = cursor->next; | |
388 | + qemu_free(entry); | |
389 | + return; | |
390 | + } | |
391 | + | |
392 | + prev->next = entry->next; | |
393 | + qemu_free(entry); | |
352 | 394 | } |
353 | 395 | |
354 | 396 | QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, |
... | ... | @@ -415,8 +457,12 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry) |
415 | 457 | |
416 | 458 | void kbd_put_keycode(int keycode) |
417 | 459 | { |
418 | - if (qemu_put_kbd_event) { | |
419 | - qemu_put_kbd_event(qemu_put_kbd_event_opaque, keycode); | |
460 | + QEMUPutKeyboardEntry *cursor; | |
461 | + | |
462 | + cursor = qemu_put_kbd_event_head; | |
463 | + while (cursor != NULL) { | |
464 | + cursor->qemu_put_kbd_event(cursor->qemu_put_kbd_event_opaque, keycode); | |
465 | + cursor = cursor->next; | |
420 | 466 | } |
421 | 467 | } |
422 | 468 | ... | ... |