Skip to contentSkip to conversation

add input-send-event command

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

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 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  |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       |   31 ++++++++++++++++++++++++++++
 3 files changed, 108 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 +59 -0

62 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) {
#1 lore raw
Quoted 2 lines · Marcelo Tosatti

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

Looks good overall, only minor nits. Will wait for acks from qmp guys before picking into input branch.

Quoted 1 line

Suggested by Gerd Hoffman.

Huh? Signed-off missing ...

qmp-commands.hx line 3607

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

Bad example. Down + up should go as separate commands (so you have a sync inbetween), otherwise it might happen that the guest doesn't see the button event at all.

cheers,
Gerd

#2 lore raw
Quoted 11 lines · Gerd Hoffmann
Quoted 2 lines · Marcelo Tosatti

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

Looks good overall, only minor nits. Will wait for acks from qmp guys before picking into input branch.

Quoted 1 line

Suggested by Gerd Hoffman.

Huh? Signed-off missing ...

Quoted 13 lines

qmp-commands.hx line 3607

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

Bad example. Down + up should go as separate commands (so you have a sync inbetween), otherwise it might happen that the guest doesn't see the button event at all.

Would it be worth adding a command to the union of possible events that adds a pause? As in:

-> { "execute": "input-send-event",

    "arguments": { "console": 0,
                   "events": [
                    { "type": "btn",
                      "data" : { "down": true, "button": "Left" } },
                    { "type": "pause", "data": { "duration": 10 } },
                    { "type": "btn",
                      "data" : { "down": false, "button": "Left" } } ] } }

that sticks a 10 ms delay between the other two events?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
Quoted 38 lines · Eric Blake
Quoted 11 lines · Gerd Hoffmann
Quoted 2 lines · Marcelo Tosatti

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

Looks good overall, only minor nits. Will wait for acks from qmp guys before picking into input branch.

Quoted 1 line

Suggested by Gerd Hoffman.

Huh? Signed-off missing ...

Quoted 13 lines

qmp-commands.hx line 3607

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

Bad example. Down + up should go as separate commands (so you have a sync inbetween), otherwise it might happen that the guest doesn't see the button event at all.

Would it be worth adding a command to the union of possible events that adds a pause? As in:

-> { "execute": "input-send-event",

    "arguments": { "console": 0,
                   "events": [
                    { "type": "btn",
                      "data" : { "down": true, "button": "Left" } },
                    { "type": "pause", "data": { "duration": 10 } },
                    { "type": "btn",
                      "data" : { "down": false, "button": "Left" } } ] } }
Quoted 1 line

that sticks a 10 ms delay between the other two events?

Would rather have the user wait 10 ms in between QMP commands.

#4 lore raw
In reply to Marcelo Tosatti
Quoted 7 lines · Marcelo Tosatti

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

Suggested by Gerd Hoffman.

---

Needs S-o-B.

Quoted 10 lines
 qapi-schema.json |   18 ++++++++++++++++
 qmp-commands.hx  |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       |   31 ++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)

Index: qemu/qapi-schema.json
===================================================================

qapi-schema.json line 4731

Quoted 10 lines
qapi-schema.json +7 -0
@@ -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.

Is it worth requiring console, or can it be optional and default to the first available console (usually console 0)?

qapi-schema.json line 4741

Quoted 10 lines
qapi-schema.json +10 -0
+#
+# @events: List of InputEvent union.
+#
+# Returns: Nothing on success.
+#
+# Since: 2.1
+#
+##
+{ 'command': 'input-send-event',
+  'data': { 'console':'int', 'events': [ 'InputEvent' ] } }

See my other mail about possibly extending the InputEvent union (or creating a new subtype) to add delays into the mix.

qapi-schema.json

Quoted 13 lines
qapi-schema.json +13 -0
+Example (2):
+
+Press ctrl-alt-del.
+
+-> { "execute": "input-send-event",
+     "arguments": { "console": 0, "events": [
+        { "type": "key", "data" : { "down": true,
+          "key": {"type": "qcode", "data": "ctrl" } } },
+        { "type": "key", "data" : { "down": true,
+          "key": {"type": "qcode", "data": "alt" } } },
+        { "type": "key", "data" : { "down": true,
+          "key": {"type": "qcode", "data": "delete" } } } ] } }
+<- { "return": {} }

Don't you also need to send the key-release events (again, possibly after a pause), for this to work?

qapi-schema.json

Quoted 3 lines
qapi-schema.json +3 -0
+        if (!qemu_input_find_handler(1 << event->kind, con)) {
+            error_setg(errp, "Input handler not found for"
+                             "event type %s",

Typo: s/forevent/for event/

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw
Quoted 26 lines · Eric Blake
Quoted 7 lines · Marcelo Tosatti

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

Suggested by Gerd Hoffman.

---

Needs S-o-B.

Quoted 15 lines
 qapi-schema.json |   18 ++++++++++++++++
 qmp-commands.hx  |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input.c       |   31 ++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)

Index: qemu/qapi-schema.json
===================================================================

qapi-schema.json +2 -0
@@ -4722,3 +4722,21 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
Quoted 8 lines

qapi-schema.json line 4731

Quoted 5 lines
qapi-schema.json +5 -0
+# @input-send-event
+#
+# Send input event(s) to guest.
+#
+# @console: Which console to send event(s) to.

Is it worth requiring console, or can it be optional and default to the first available console (usually console 0)?

It is required. Would rather not allow the user to send a command to an console without knowing what console that is.

Quoted 15 lines

qapi-schema.json line 4741

Quoted 10 lines
qapi-schema.json +10 -0
+#
+# @events: List of InputEvent union.
+#
+# Returns: Nothing on success.
+#
+# Since: 2.1
+#
+##
+{ 'command': 'input-send-event',
+  'data': { 'console':'int', 'events': [ 'InputEvent' ] } }

See my other mail about possibly extending the InputEvent union (or creating a new subtype) to add delays into the mix.

Quoted 16 lines

qapi-schema.json

Quoted 13 lines
qapi-schema.json +13 -0
+Example (2):
+
+Press ctrl-alt-del.
+
+-> { "execute": "input-send-event",
+     "arguments": { "console": 0, "events": [
+        { "type": "key", "data" : { "down": true,
+          "key": {"type": "qcode", "data": "ctrl" } } },
+        { "type": "key", "data" : { "down": true,
+          "key": {"type": "qcode", "data": "alt" } } },
+        { "type": "key", "data" : { "down": true,
+          "key": {"type": "qcode", "data": "delete" } } } ] } }
+<- { "return": {} }

Don't you also need to send the key-release events (again, possibly after a pause), for this to work?

No, key signals on "down".

Quoted 5 lines

qapi-schema.json

Quoted 3 lines
qapi-schema.json +3 -0
+        if (!qemu_input_find_handler(1 << event->kind, con)) {
+            error_setg(errp, "Input handler not found for"
+                             "event type %s",

Typo: s/forevent/for event/

Yes there is another missing space, thanks.