From: "Rainer Müller" <raimue@codingfarm.de>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Rainer Müller" <raimue@codingfarm.de>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH 2/2] input-linux: Allow to toggle grab from QMP
Date: Sat, 1 May 2021 21:06:22 +0200 [thread overview]
Message-ID: <20210501190622.153901-3-raimue@codingfarm.de> (raw)
In-Reply-To: <20210501190622.153901-1-raimue@codingfarm.de>
This patch allows to boot a guest without the input-linux device being
grabbed immediately from the host. This is useful when the guest is
automatically started, but is supposed to stay in the background until
the user actively switches to it with a key combination.
In this usage example the host continues to own the keyboard until the
user explicitly toggles the grab state with both control keys:
-object input-linux,id=kbd1,evdev=/dev/input/eventX,grab-active=off
When grab-active is not given, input-linux will behave as before and
devices are being grabbed immediately on initialization.
Note that even if grab_all=on is set, other devices will initially be
grabbed according to their own grab-active option. The first toggle
operation on a grab_all=on device will sync state to the other devices.
Furthermore, this new option allows to toggle the grab state from QMP
with the qom-set command. By setting grab-active at runtime, the device
will be grabbed or released as indicated by the passed value.
$ ./scripts/qmp-shell /tmp/qmp.sock
(QEMU) qom-set path=/objects/kbd1 property=grab-active value=true
{"return": {}}
(QEMU) qom-get path=/objects/kbd1 property=grab-active
{"return": true}
For devices with grab_all=on, the action will propagate to other devices
as if the grab toggle hotkey was used.
Signed-off-by: Rainer Müller <raimue@codingfarm.de>
---
qapi/qom.json | 3 +++
ui/input-linux.c | 39 +++++++++++++++++++++++++++++++++++----
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/qapi/qom.json b/qapi/qom.json
index cd0e76d564..51704465ec 100644
--- a/qapi/qom.json
+++ b/qapi/qom.json
@@ -488,6 +488,8 @@
#
# @repeat: enables auto-repeat events (default: false)
#
+# @grab-active: if true, device is grabbed (default: true)
+#
# @grab-toggle: the key or key combination that toggles device grab
# (default: ctrl-ctrl)
#
@@ -497,6 +499,7 @@
'data': { 'evdev': 'str',
'*grab_all': 'bool',
'*repeat': 'bool',
+ '*grab-active': 'bool',
'*grab-toggle': 'GrabToggleKeys' } }
##
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 47d489d738..64efb83e21 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -399,10 +399,9 @@ static void input_linux_complete(UserCreatable *uc, Error **errp)
}
qemu_set_fd_handler(il->fd, input_linux_event, NULL, il);
- if (il->keycount) {
- /* delay grab until all keys are released */
- il->grab_request = true;
- } else {
+ /* delay grab until all keys are released */
+ if (il->grab_request && !il->keycount) {
+ il->grab_request = false;
input_linux_toggle_grab(il);
}
QTAILQ_INSERT_TAIL(&inputs, il, next);
@@ -493,8 +492,37 @@ static void input_linux_set_grab_toggle(Object *obj, int value,
il->grab_toggle = value;
}
+static bool input_linux_get_grab_active(Object *obj, Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ return il->grab_active;
+}
+
+static void input_linux_set_grab_active(Object *obj, bool value,
+ Error **errp)
+{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ if (!il->initialized) {
+ il->grab_request = value;
+ return;
+ }
+
+ if (il->grab_active != value) {
+ if (il->keycount) {
+ il->grab_request = true;
+ } else {
+ input_linux_toggle_grab(il);
+ }
+ }
+}
+
static void input_linux_instance_init(Object *obj)
{
+ InputLinux *il = INPUT_LINUX(obj);
+
+ il->grab_request = true;
}
static void input_linux_class_init(ObjectClass *oc, void *data)
@@ -512,6 +540,9 @@ static void input_linux_class_init(ObjectClass *oc, void *data)
object_class_property_add_bool(oc, "repeat",
input_linux_get_repeat,
input_linux_set_repeat);
+ object_class_property_add_bool(oc, "grab-active",
+ input_linux_get_grab_active,
+ input_linux_set_grab_active);
object_class_property_add_enum(oc, "grab-toggle", "GrabToggleKeys",
&GrabToggleKeys_lookup,
input_linux_get_grab_toggle,
--
2.25.1
next prev parent reply other threads:[~2021-05-01 19:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-01 19:06 [PATCH 0/2] input-linux: Allow to toggle grab from QMP Rainer Müller
2021-05-01 19:06 ` [PATCH 1/2] input-linux: Delay grab toggle if keys are pressed Rainer Müller
2021-05-04 9:14 ` Gerd Hoffmann
2021-05-09 11:43 ` Rainer Müller
2021-05-10 7:30 ` Gerd Hoffmann
2021-05-01 19:06 ` Rainer Müller [this message]
2021-05-04 9:17 ` [PATCH 2/2] input-linux: Allow to toggle grab from QMP Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210501190622.153901-3-raimue@codingfarm.de \
--to=raimue@codingfarm.de \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=ehabkost@redhat.com \
--cc=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).