Skip to contentSkip to conversation

add input-send-event command

PATCH Superseded Marcelo Tosatti 3 participants 3 messages Jun 17, 2014 – Jun 19, 2014

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 add input-send-event command

Which allows specification of absolute/relative,
up/down and console parameters.

Suggested by Gerd Hoffman.

---
 qapi-schema.json |   18 +++++++++++++++
 qmp-commands.hx  |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       |   31 +++++++++++++++++++++++++++
 3 files changed, 112 insertions(+)
qapi-schema.json +18 -0
Index: qemu/qapi-schema.json
===================================================================
@@ -4722,3 +4722,21 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# @input-send-event
+#
+# Send input event(s) to guest.
+#
+# @console: Which console to send event(s) to.
+#
+# @events: List of InputEvent union.
+#
+# Returns: Nothing on success.
+#
+# Since: 2.1
+#
+##
+{ 'command': 'input-send-event',
+  'data': { 'console':'int', 'events': [ 'InputEvent' ] } }
+
qmp-commands.hx +63 -0

66 lines not on this page · raw message

ui/input.c +31 -0
Index: qemu/ui/input.c
===================================================================
@@ -102,6 +102,37 @@
     return NULL;
 }
 
+void qmp_input_send_event(int64_t console, InputEventList *events,
+                          Error **errp)
+{
+    InputEventList *e;
+    QemuConsole *con;
+
+    con = qemu_console_lookup_by_index(console);
+    if (!con) {
+        error_setg(errp, "console %" PRId64 " not found", console);
+        return;
+    }
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        error_setg(errp, "VM not running");
+        return;
+    }
+
+    for (e = events; e != NULL; e = e->next) {
+        InputEvent *event = e->value;
+
+        if (!qemu_input_find_handler(1 << event->kind, con)) {
+            error_setg(errp, "Input handler not found for "
+                             "event type %s",
+                            InputEventKind_lookup[event->kind]);
+            return;
+        }
+        qemu_input_event_send(con, event);
+    }
+    qemu_input_event_sync();
+}
+
 static void qemu_input_transform_abs_rotate(InputEvent *evt)
 {
     switch (graphic_rotate) {
Reviewed-by on v2 1/1
#1 lore raw
Quoted 14 lines · Marcelo Tosatti

Which allows specification of absolute/relative,
up/down and console parameters.

Suggested by Gerd Hoffman.

---
 qapi-schema.json |   18 +++++++++++++++
 qmp-commands.hx  |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       |   31 +++++++++++++++++++++++++++
 3 files changed, 112 insertions(+)

qmp-commands.hx line 3599

Quoted 4 lines
qmp-commands.hx +4 -0
+
+Example (1):
+
+Press left mouse button.

Maybe:

Press, then later release, left mouse button.

qmp-commands.hx line 3611

Quoted 12 lines
qmp-commands.hx +12 -0
+
+-> { "execute": "input-send-event",
+    "arguments": { "console": 0,
+                   "events": [ { "type": "btn",
+                    "data" : { "down": true, "button": "Left" } } } }
+<- { "return": {} }
+
+-> { "execute": "input-send-event",
+    "arguments": { "console": 0,
+                   "events": [ { "type": "btn",
+                    "data" : { "down": false, "button": "Left" } } } }
+<- { "return": {} }

to make it clear that both command/response sequences are part of the same example.

but that's cosmetic, so whether or not you change it, I can live with:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org