qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH RFC 4/8] ui/input: Introduce MouseOps for qemu_add_m


From: Andreas Färber
Subject: [Qemu-devel] [PATCH RFC 4/8] ui/input: Introduce MouseOps for qemu_add_mouse_event_handler()
Date: Sun, 16 Jun 2013 05:40:01 +0200

This allows to add callbacks to mouse event handlers without constantly
touching all callers of qemu_add_mouse_event_handler() or
qemu_add_mouse_event_handler() itself.

Signed-off-by: Andreas Färber <address@hidden>
---
 backends/msmouse.c   |  6 +++++-
 hw/char/escc.c       |  6 +++++-
 hw/display/ads7846.c |  6 +++++-
 hw/display/xenfb.c   |  6 +++++-
 hw/input/adb.c       |  6 +++++-
 hw/input/hid.c       |  8 ++++++--
 hw/input/ps2.c       |  6 +++++-
 hw/input/tsc2005.c   |  6 +++++-
 hw/input/tsc210x.c   |  8 ++++++--
 hw/input/vmmouse.c   |  6 +++++-
 hw/usb/dev-wacom.c   | 12 ++++++++++--
 include/ui/console.h | 13 +++++++++++--
 ui/input.c           | 12 ++++++------
 13 files changed, 79 insertions(+), 22 deletions(-)

diff --git a/backends/msmouse.c b/backends/msmouse.c
index 1d24ac6..035b7b4 100644
--- a/backends/msmouse.c
+++ b/backends/msmouse.c
@@ -63,6 +63,10 @@ static void msmouse_chr_close (struct CharDriverState *chr)
     g_free (chr);
 }
 
+static const MouseOps msmouse_mouse_ops = {
+    .put_event = msmouse_event,
+};
+
 CharDriverState *qemu_chr_open_msmouse(void)
 {
     CharDriverState *chr;
@@ -72,7 +76,7 @@ CharDriverState *qemu_chr_open_msmouse(void)
     chr->chr_close = msmouse_chr_close;
     chr->explicit_be_open = true;
 
-    qemu_add_mouse_event_handler(msmouse_event, chr, false,
+    qemu_add_mouse_event_handler(&msmouse_mouse_ops, chr, false,
                                  "QEMU Microsoft Mouse");
 
     return chr;
diff --git a/hw/char/escc.c b/hw/char/escc.c
index 68a49cd..f6592cb 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -867,6 +867,10 @@ void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
     sysbus_mmio_map(s, 0, base);
 }
 
+static const MouseOps sunmouse_mouse_ops = {
+    .put_event = sunmouse_event,
+};
+
 static int escc_init1(SysBusDevice *dev)
 {
     SerialState *s = FROM_SYSBUS(SerialState, dev);
@@ -891,7 +895,7 @@ static int escc_init1(SysBusDevice *dev)
     sysbus_init_mmio(dev, &s->mmio);
 
     if (s->chn[0].type == mouse) {
-        qemu_add_mouse_event_handler(sunmouse_event, &s->chn[0], false,
+        qemu_add_mouse_event_handler(&sunmouse_mouse_ops, &s->chn[0], false,
                                      "QEMU Sun Mouse");
     }
     if (s->chn[1].type == kbd) {
diff --git a/hw/display/ads7846.c b/hw/display/ads7846.c
index 4a02744..9026d97 100644
--- a/hw/display/ads7846.c
+++ b/hw/display/ads7846.c
@@ -133,6 +133,10 @@ static const VMStateDescription vmstate_ads7846 = {
     }
 };
 
+static const MouseOps ads7846_ts_ops = {
+    .put_event = ads7846_ts_event,
+};
+
 static int ads7846_init(SSISlave *dev)
 {
     ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, dev);
@@ -145,7 +149,7 @@ static int ads7846_init(SSISlave *dev)
     s->input[7] = ADS_TEMP1;   /* TEMP1 */
 
     /* We want absolute coordinates */
-    qemu_add_mouse_event_handler(ads7846_ts_event, s, true,
+    qemu_add_mouse_event_handler(&ads7846_ts_ops, s, true,
                                  "QEMU ADS7846-driven Touchscreen");
 
     ads7846_int_update(s);
diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
index f0333a0..14dac45 100644
--- a/hw/display/xenfb.c
+++ b/hw/display/xenfb.c
@@ -366,6 +366,10 @@ static int input_initialise(struct XenDevice *xendev)
     return 0;
 }
 
+static const MouseOps xenfb_mouse_ops = {
+    .put_event = xenfb_mouse_event,
+};
+
 static void input_connected(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
@@ -378,7 +382,7 @@ static void input_connected(struct XenDevice *xendev)
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }
-    in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
+    in->qmouse = qemu_add_mouse_event_handler(&xenfb_mouse_ops, in,
                                              in->abs_pointer_wanted,
                                              "Xen PVFB Mouse");
 }
diff --git a/hw/input/adb.c b/hw/input/adb.c
index 104bfc8..88edf57 100644
--- a/hw/input/adb.c
+++ b/hw/input/adb.c
@@ -529,6 +529,10 @@ static const VMStateDescription vmstate_adb_mouse = {
     }
 };
 
+static const MouseOps adb_mouse_ops = {
+    .put_event = adb_mouse_event,
+};
+
 static void adb_mouse_realizefn(DeviceState *dev, Error **errp)
 {
     MouseState *s = ADB_MOUSE(dev);
@@ -536,7 +540,7 @@ static void adb_mouse_realizefn(DeviceState *dev, Error 
**errp)
 
     amc->parent_realize(dev, errp);
 
-    qemu_add_mouse_event_handler(adb_mouse_event, s, false, "QEMU ADB Mouse");
+    qemu_add_mouse_event_handler(&adb_mouse_ops, s, false, "QEMU ADB Mouse");
 }
 
 static void adb_mouse_initfn(Object *obj)
diff --git a/hw/input/hid.c b/hw/input/hid.c
index 7a3a7a4..4cdc8a9 100644
--- a/hw/input/hid.c
+++ b/hw/input/hid.c
@@ -425,6 +425,10 @@ void hid_free(HIDState *hs)
     hid_del_idle_timer(hs);
 }
 
+static const MouseOps hid_mouse_ops = {
+    .put_event = hid_pointer_event,
+};
+
 void hid_init(HIDState *hs, int kind, HIDEventFunc event)
 {
     hs->kind = kind;
@@ -433,11 +437,11 @@ void hid_init(HIDState *hs, int kind, HIDEventFunc event)
     if (hs->kind == HID_KEYBOARD) {
         hs->kbd.eh_entry = qemu_add_kbd_event_handler(hid_keyboard_event, hs);
     } else if (hs->kind == HID_MOUSE) {
-        hs->ptr.eh_entry = qemu_add_mouse_event_handler(hid_pointer_event,
+        hs->ptr.eh_entry = qemu_add_mouse_event_handler(&hid_mouse_ops,
                                                         hs, false,
                                                         "QEMU HID Mouse");
     } else if (hs->kind == HID_TABLET) {
-        hs->ptr.eh_entry = qemu_add_mouse_event_handler(hid_pointer_event,
+        hs->ptr.eh_entry = qemu_add_mouse_event_handler(&hid_mouse_ops,
                                                         hs, true,
                                                         "QEMU HID Tablet");
     }
diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index e555f74..743e380 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -663,6 +663,10 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void 
*update_arg)
     return s;
 }
 
+static const MouseOps ps2_mouse_ops = {
+    .put_event = ps2_mouse_event,
+};
+
 void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg)
 {
     PS2MouseState *s = (PS2MouseState *)g_malloc0(sizeof(PS2MouseState));
@@ -670,7 +674,7 @@ void *ps2_mouse_init(void (*update_irq)(void *, int), void 
*update_arg)
     s->common.update_irq = update_irq;
     s->common.update_arg = update_arg;
     vmstate_register(NULL, 0, &vmstate_ps2_mouse, s);
-    qemu_add_mouse_event_handler(ps2_mouse_event, s, false, "QEMU PS/2 Mouse");
+    qemu_add_mouse_event_handler(&ps2_mouse_ops, s, false, "QEMU PS/2 Mouse");
     qemu_register_reset(ps2_mouse_reset, s);
     return s;
 }
diff --git a/hw/input/tsc2005.c b/hw/input/tsc2005.c
index b0d9263..69b543c 100644
--- a/hw/input/tsc2005.c
+++ b/hw/input/tsc2005.c
@@ -519,6 +519,10 @@ static int tsc2005_load(QEMUFile *f, void *opaque, int 
version_id)
     return 0;
 }
 
+static const MouseOps tsc2005_touchscreen_ops = {
+    .put_event = tsc2005_touchscreen_event,
+};
+
 void *tsc2005_init(qemu_irq pintdav)
 {
     TSC2005State *s;
@@ -544,7 +548,7 @@ void *tsc2005_init(qemu_irq pintdav)
 
     tsc2005_reset(s);
 
-    qemu_add_mouse_event_handler(tsc2005_touchscreen_event, s, true,
+    qemu_add_mouse_event_handler(&tsc2005_touchscreen_ops, s, true,
                                  "QEMU TSC2005-driven Touchscreen");
 
     qemu_register_reset((void *) tsc2005_reset, s);
diff --git a/hw/input/tsc210x.c b/hw/input/tsc210x.c
index 02d3440..66e18fb 100644
--- a/hw/input/tsc210x.c
+++ b/hw/input/tsc210x.c
@@ -1100,6 +1100,10 @@ static int tsc210x_load(QEMUFile *f, void *opaque, int 
version_id)
     return 0;
 }
 
+static const MouseOps tsc210x_touchscreen_ops = {
+    .put_event = tsc210x_touchscreen_event,
+};
+
 uWireSlave *tsc2102_init(qemu_irq pint)
 {
     TSC210xState *s;
@@ -1137,7 +1141,7 @@ uWireSlave *tsc2102_init(qemu_irq pint)
 
     tsc210x_reset(s);
 
-    qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, true,
+    qemu_add_mouse_event_handler(&tsc210x_touchscreen_ops, s, true,
                                  "QEMU TSC2102-driven Touchscreen");
 
     AUD_register_card(s->name, &s->card);
@@ -1188,7 +1192,7 @@ uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, 
qemu_irq dav)
 
     tsc210x_reset(s);
 
-    qemu_add_mouse_event_handler(tsc210x_touchscreen_event, s, true,
+    qemu_add_mouse_event_handler(&tsc210x_touchscreen_ops, s, true,
                                  "QEMU TSC2301-driven Touchscreen");
 
     AUD_register_card(s->name, &s->card);
diff --git a/hw/input/vmmouse.c b/hw/input/vmmouse.c
index 2b2ea88..ec13a8b 100644
--- a/hw/input/vmmouse.c
+++ b/hw/input/vmmouse.c
@@ -114,6 +114,10 @@ static void vmmouse_remove_handler(VMMouseState *s)
     }
 }
 
+static const MouseOps vmmouse_mouse_ops = {
+    .put_event = vmmouse_mouse_event,
+};
+
 static void vmmouse_update_handler(VMMouseState *s, uint8_t absolute)
 {
     if (s->status != 0) {
@@ -124,7 +128,7 @@ static void vmmouse_update_handler(VMMouseState *s, uint8_t 
absolute)
         vmmouse_remove_handler(s);
     }
     if (s->entry == NULL) {
-        s->entry = qemu_add_mouse_event_handler(vmmouse_mouse_event,
+        s->entry = qemu_add_mouse_event_handler(&vmmouse_mouse_ops,
                                                 s, s->absolute,
                                                 "vmmouse");
         qemu_activate_mouse_event_handler(s->entry);
diff --git a/hw/usb/dev-wacom.c b/hw/usb/dev-wacom.c
index 78563ff..90b7fee 100644
--- a/hw/usb/dev-wacom.c
+++ b/hw/usb/dev-wacom.c
@@ -165,12 +165,16 @@ static inline int int_clamp(int val, int vmin, int vmax)
         return val;
 }
 
+static const MouseOps usb_mouse_ops = {
+    .put_event = usb_mouse_event,
+};
+
 static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, int len)
 {
     int dx, dy, dz, b, l;
 
     if (!s->mouse_grabbed) {
-        s->eh_entry = qemu_add_mouse_event_handler(usb_mouse_event, s, false,
+        s->eh_entry = qemu_add_mouse_event_handler(&usb_mouse_ops, s, false,
                                                    "QEMU PenPartner tablet");
         qemu_activate_mouse_event_handler(s->eh_entry);
         s->mouse_grabbed = 1;
@@ -203,12 +207,16 @@ static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, 
int len)
     return l;
 }
 
+static const MouseOps usb_wacom_ops = {
+    .put_event = usb_wacom_event,
+};
+
 static int usb_wacom_poll(USBWacomState *s, uint8_t *buf, int len)
 {
     int b;
 
     if (!s->mouse_grabbed) {
-        s->eh_entry = qemu_add_mouse_event_handler(usb_wacom_event, s, true,
+        s->eh_entry = qemu_add_mouse_event_handler(&usb_wacom_ops, s, true,
                                                    "QEMU PenPartner tablet");
         qemu_activate_mouse_event_handler(s->eh_entry);
         s->mouse_grabbed = 1;
diff --git a/include/ui/console.h b/include/ui/console.h
index e25879f..30b0451 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -27,7 +27,16 @@
 
 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
 typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
-typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int 
buttons_state);
+typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz,
+                               int buttons_state);
+
+/**
+ * MouseOps:
+ * @put_event: Signals a mouse event to a backend.
+ */
+typedef struct MouseOps {
+    QEMUPutMouseEvent *put_event;
+} MouseOps;
 
 typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
 typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
@@ -36,7 +45,7 @@ typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
 QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
                                             void *opaque);
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
-QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
+QEMUPutMouseEntry *qemu_add_mouse_event_handler(const MouseOps *ops,
                                                 void *opaque, bool absolute,
                                                 const char *name);
 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
diff --git a/ui/input.c b/ui/input.c
index 76ded94..7f1248b 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -31,7 +31,7 @@
 #include "ui/keymaps.h"
 
 struct QEMUPutMouseEntry {
-    QEMUPutMouseEvent *put_event;
+    const MouseOps *ops;
     void *opaque;
     bool absolute;
     char *name;
@@ -346,7 +346,7 @@ static void check_mode_change(void)
     current_has_absolute = has_absolute;
 }
 
-QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
+QEMUPutMouseEntry *qemu_add_mouse_event_handler(const MouseOps *ops,
                                                 void *opaque, bool absolute,
                                                 const char *name)
 {
@@ -355,7 +355,7 @@ QEMUPutMouseEntry 
*qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 
     s = g_malloc0(sizeof(QEMUPutMouseEntry));
 
-    s->put_event = func;
+    s->ops = ops;
     s->opaque = opaque;
     s->absolute = absolute;
     s->name = g_strdup(name);
@@ -443,7 +443,7 @@ void kbd_mouse_event(int dx, int dy, int dz, int 
buttons_state)
 
     entry = QTAILQ_FIRST(&mouse_handlers);
 
-    if (entry->put_event) {
+    if (entry->ops->put_event) {
         if (entry->absolute) {
             width = 0x7fff;
             height = 0x7fff;
@@ -472,8 +472,8 @@ void kbd_mouse_event(int dx, int dy, int dz, int 
buttons_state)
         default:
             return;
         }
-        entry->put_event(entry->opaque,
-                         rotated_dx, rotated_dy, dz, buttons_state);
+        entry->ops->put_event(entry->opaque,
+                              rotated_dx, rotated_dy, dz, buttons_state);
     }
 }
 
-- 
1.8.1.4




reply via email to

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