Skip to contentSkip to conversation

add input-send-event command

PATCH In review Marcelo Tosatti 2 participants 2 messages Sep 30, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v4 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 | 17 +++++++++++++++++
 qmp-commands.hx  | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
qapi-schema.json +17 -0
index 4bfaf20..2e9e261 100644
@@ -3233,6 +3233,23 @@
               '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.2
+#
+##
+{ 'command': 'input-send-event',
+  'data': { 'console':'int', 'events': [ 'InputEvent' ] } }
+
+##
 # @NumaOptions
 #
 # A discriminated record of NUMA options. (for OptsVisitor)
qmp-commands.hx +63 -0

66 lines not on this page · raw message

ui/input.c +37 -0
index 89d9db7..002831e 100644
@@ -122,6 +122,43 @@ qemu_input_find_handler(uint32_t mask, QemuConsole *con)
     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;
+        }
+    }
+
+    for (e = events; e != NULL; e = e->next) {
+        InputEvent *event = e->value;
+
+        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 v4 1/1
#1 lore raw
Quoted 6 lines · Marcelo Tosatti

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

Suggested by Gerd Hoffman.

Quoted 7 lines
---
 qapi-schema.json | 17 +++++++++++++++++
 qmp-commands.hx  | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org