[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
- [Qemu-devel] [PATCH 19/42] input: mouse: add helpers functions to core, (continued)
- [Qemu-devel] [PATCH 19/42] input: mouse: add helpers functions to core, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 16/42] input: keyboard: switch vnc ui to new core, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 21/42] input: mouse: add qemu_input_is_absolute(), Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 23/42] input: mouse: switch gtk ui to new core, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 29/42] input: keyboard: switch cocoa ui to new core [untested], Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 13/42] input: keyboard: switch gtk ui to new core, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 32/42] input-legacy: remove kbd_put_keycode, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 20/42] input: mouse: add graphic_rotate support, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 35/42] input-legacy: remove kbd_mouse_event, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new core,
Gerd Hoffmann <=
- [Qemu-devel] [PATCH 27/42] input: mouse: switch spice ui to new core, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 08/42] input: qapi: add pause key, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0), Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 28/42] input: mouse: switch monitor to new core, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 24/42] input: mouse: switch sdl ui to new core, Gerd Hoffmann, 2013/12/16
- [Qemu-devel] [PATCH 36/42] input: move mouse mode notifier to new core, Gerd Hoffmann, 2013/12/16