qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new c


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new core
Date: Mon, 16 Dec 2013 11:48:58 +0100

legacy mouse event handlers are registered in the new core,
so they receive events submitted to the new input core.

legacy kbd_mouse_event() continues to use the old code paths.
So new-core event handlers wouldn't see events submitted via
kbd_mouse_event.

This leads to the constrain that we we must transition all
kbd_mouse_event() users first to keep things working.  But
that is easier to handle than translating legacy mouse events
into new-core mouse events ;)

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 ui/input-legacy.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index a4006cc..dd2dec3 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -41,6 +41,12 @@ struct QEMUPutMouseEntry {
 
     /* used internally by qemu for handling mice */
     QTAILQ_ENTRY(QEMUPutMouseEntry) node;
+
+    /* new input core */
+    QemuInputHandler h;
+    QemuInputHandlerState *s;
+    int axis[INPUT_AXIS_MAX];
+    int buttons;
 };
 
 struct QEMUPutKbdEntry {
@@ -376,6 +382,51 @@ static void check_mode_change(void)
     current_has_absolute = has_absolute;
 }
 
+static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
+                               InputEvent *evt)
+{
+    static const int bmap[INPUT_BUTTON_MAX] = {
+        [INPUT_BUTTON_LEFT]   = MOUSE_EVENT_LBUTTON,
+        [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
+        [INPUT_BUTTON_RIGHT]  = MOUSE_EVENT_RBUTTON,
+    };
+    QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+    switch (evt->kind) {
+    case INPUT_EVENT_KIND_BTN:
+        if (evt->btn->down) {
+            s->buttons |= bmap[evt->btn->button];
+        } else {
+            s->buttons &= ~bmap[evt->btn->button];
+        }
+        break;
+    case INPUT_EVENT_KIND_ABS:
+        s->axis[evt->abs->axis] = evt->abs->value;
+        break;
+    case INPUT_EVENT_KIND_REL:
+        s->axis[evt->rel->axis] += evt->rel->value;
+        break;
+    default:
+        break;
+    }
+}
+
+static void legacy_mouse_sync(DeviceState *dev)
+{
+    QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+    s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
+                            s->axis[INPUT_AXIS_X],
+                            s->axis[INPUT_AXIS_Y],
+                            0,
+                            s->buttons);
+
+    if (!s->qemu_put_mouse_event_absolute) {
+        s->axis[INPUT_AXIS_X] = 0;
+        s->axis[INPUT_AXIS_Y] = 0;
+    }
+}
+
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
                                                 void *opaque, int absolute,
                                                 const char *name)
@@ -393,6 +444,14 @@ QEMUPutMouseEntry 
*qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 
     QTAILQ_INSERT_TAIL(&mouse_handlers, s, node);
 
+    s->h.name = name;
+    s->h.mask = INPUT_EVENT_MASK_BTN |
+        (absolute ? INPUT_EVENT_MASK_ABS : INPUT_EVENT_MASK_REL);
+    s->h.event = legacy_mouse_event;
+    s->h.sync = legacy_mouse_sync;
+    s->s = qemu_input_handler_register((DeviceState *)s,
+                                       &s->h);
+
     check_mode_change();
 
     return s;
@@ -403,6 +462,8 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry 
*entry)
     QTAILQ_REMOVE(&mouse_handlers, entry, node);
     QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
 
+    qemu_input_handler_activate(entry->s);
+
     check_mode_change();
 }
 
@@ -410,6 +471,8 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry 
*entry)
 {
     QTAILQ_REMOVE(&mouse_handlers, entry, node);
 
+    qemu_input_handler_unregister(entry->s);
+
     g_free(entry->qemu_put_mouse_event_name);
     g_free(entry);
 
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]