[14/48] multikeyboard support merge

Submitted by Riku Voipio on March 26, 2010, 4:06 p.m.

Details

Message ID 97ae98621ef1858ee0ba8343b846bab23be32690.1269617186.git.riku.voipio@nokia.com
State New
Headers show

Commit Message

Riku Voipio March 26, 2010, 4:06 p.m.
From: Juha Riihimäki <juha.riihimaki@nokia.com>

On some systems (such as n900), multiple physical devices can create
keyboard events (gpio, lis302dl, twl4030, ..). Add hooks to make it
possible to recieve keyboard input from multiple devices.

merge our version with upstream multikb support

Signed-Off-By: Riku Voipio <riku.voipio@nokia.com>
Signed-Off-By: Juha Riihimäki <juha.riihimaki@nokia.com>

---
 console.h |    8 ++++----
 input.c   |   21 +++++++++++++++------
 2 files changed, 19 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/console.h b/console.h
index b1362ff..a894edf 100644
--- a/console.h
+++ b/console.h
@@ -39,12 +39,13 @@  typedef struct QEMUPutMouseEntry {
     /* used internally by qemu for handling mice */
     QTAILQ_ENTRY(QEMUPutMouseEntry) node;
 } QEMUPutMouseEntry;
+
 typedef struct QEMUPutKBDEntry {
-    QEMUPutKBDEvent *qemu_put_kbd_event;
-    void *qemu_put_kbd_event_opaque;
+    QEMUPutKBDEvent *put_kbd_event;
+    void *opaque;
 
     /* used internally by qemu for handling keyboards */
-    struct QEMUPutKBDEntry *next;
+    QTAILQ_ENTRY(QEMUPutKBDEntry) next;
 } QEMUPutKBDEntry;
 
 typedef struct QEMUPutLEDEntry {
@@ -54,7 +55,6 @@  typedef struct QEMUPutLEDEntry {
 } QEMUPutLEDEntry;
 
 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
-void qemu_remove_kbd_event_handler(QEMUPutKBDEvent *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
                                                 void *opaque, int absolute,
                                                 const char *name);
diff --git a/input.c b/input.c
index 8f0941e..2e860c6 100644
--- a/input.c
+++ b/input.c
@@ -28,8 +28,8 @@ 
 #include "console.h"
 #include "qjson.h"
 
-static QEMUPutKBDEvent *qemu_put_kbd_event;
-static void *qemu_put_kbd_event_opaque;
+static QTAILQ_HEAD(, QEMUPutKBDEntry) kbd_handlers =
+    QTAILQ_HEAD_INITIALIZER(kbd_handlers);
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers);
 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
     QTAILQ_HEAD_INITIALIZER(mouse_handlers);
@@ -38,8 +38,16 @@  static NotifierList mouse_mode_notifiers =
 
 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
 {
-    qemu_put_kbd_event_opaque = opaque;
-    qemu_put_kbd_event = func;
+    QEMUPutKBDEntry *s;
+
+    if (func != NULL) {
+        s = qemu_mallocz(sizeof(QEMUPutKBDEntry));
+
+        s->put_kbd_event = func;
+        s->opaque = opaque;
+
+        QTAILQ_INSERT_TAIL(&kbd_handlers, s, next);
+    }
 }
 
 static void check_mode_change(void)
@@ -123,8 +131,9 @@  void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode)
 {
-    if (qemu_put_kbd_event) {
-        qemu_put_kbd_event(qemu_put_kbd_event_opaque, keycode);
+    QEMUPutKBDEntry *cursor;
+    QTAILQ_FOREACH(cursor, &kbd_handlers, next) {
+        cursor->put_kbd_event(cursor->opaque, keycode);
     }
 }