From nobody Fri May 17 08:24:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1619896816; cv=none; d=zohomail.com; s=zohoarc; b=dfLssAF2uRwnbLfMkDAEiQbf52BxVCQKWV7nS2mZUxnbu3D3AXSJdQFctxNx6j0GBFlV+zrss6XcwqKEoRyv8MmdQOcbXUumSxzoq0SSlmbXiDLjTgLY0SPWmEZ3ETFIEUNKijuClQsnSUSYZcX8SzHpfBZIjFJWB3qrtK6b+yw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619896816; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AlXceREaO8PHquNzD1KqrSGtrkEH3EjANVXIt2H52os=; b=W2a9GEiE6O8HHK9/Dk4oAQTApqS/EZAptR6oKg0qZiK5cXqwlY7f0cG3r7MsdSQ0Df14dX2mXpJBUmHEfjuK6Dwq38Co40N/BWqmZkW0Y7bx5mntbCrGFQvfip+RW0m9QOHovD0p5Kp3Kk1ko5fPVHmDMQZcC/rqQZoblbgDkAs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161989681674963.66292564052833; Sat, 1 May 2021 12:20:16 -0700 (PDT) Received: from localhost ([::1]:54348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcv9z-0000Pr-8f for importer@patchew.org; Sat, 01 May 2021 15:20:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcv56-0005bB-60 for qemu-devel@nongnu.org; Sat, 01 May 2021 15:15:13 -0400 Received: from donkey.codingfarm.de ([2a01:4f8:190:12cf::d:1]:43682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcv53-0007pl-ED for qemu-devel@nongnu.org; Sat, 01 May 2021 15:15:11 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by donkey.codingfarm.de (Postfix) with ESMTPSA id 1BA7280274; Sat, 1 May 2021 21:06:23 +0200 (CEST) Received: by zebra.codingfarm.de (Postfix, from userid 1000) id DF0A744CD7; Sat, 1 May 2021 21:06:22 +0200 (CEST) From: =?UTF-8?q?Rainer=20M=C3=BCller?= To: qemu-devel@nongnu.org Subject: [PATCH 1/2] input-linux: Delay grab toggle if keys are pressed Date: Sat, 1 May 2021 21:06:21 +0200 Message-Id: <20210501190622.153901-2-raimue@codingfarm.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210501190622.153901-1-raimue@codingfarm.de> References: <20210501190622.153901-1-raimue@codingfarm.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a01:4f8:190:12cf::d:1; envelope-from=raimue@zebra.codingfarm.de; helo=donkey.codingfarm.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NO_DNS_FOR_FROM=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , =?UTF-8?q?Rainer=20M=C3=BCller?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" When multiple keyboards are passed to the guest with input-linux, there could still be keys pressed on the other keyboard when toggling grab. Delay toggling grab on the other keyboard until all keys are released, otherwise keys could be stuck on host without a key up event. Signed-off-by: Rainer M=C3=BCller --- ui/input-linux.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/input-linux.c b/ui/input-linux.c index 05c0c98819..47d489d738 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -89,7 +89,12 @@ static void input_linux_toggle_grab(InputLinux *il) continue; } if (item->grab_active !=3D il->grab_active) { - input_linux_toggle_grab(item); + if (item->keycount) { + /* delay grab until all keys are released */ + item->grab_request =3D true; + } else { + input_linux_toggle_grab(item); + } } } } --=20 2.25.1 From nobody Fri May 17 08:24:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1619897072; cv=none; d=zohomail.com; s=zohoarc; b=It0w4PicWB90Aa5scYv5P3JUCyHsgslaX+4xfvg18GolRjDG/ruPnFy3L2lU7X9rChhGAPZ+PMrNExYHb8JcCwO1ZF9oxh56knR2omQRMjKwYoMm+uJ3qP6BekYQwrT2ChX0edHZPsjt6/XJ9UrtW8pN29Z121LkX0xqL/Hhty0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619897072; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dCWFzmgfgcGijhz/CRwk6jbXydyRwOhuAgi1iRrKVwg=; b=GiEscFhabpUZz/B9J2nK0dyjmllWD54b0On+dQQE54qBA33hrmhHIzzcPierf5276ROXbB1XJlUYmFvYQ7NRsjAvM73PZKPBKBwDE5HxEv+Mh7rrLPL1SVMIhBQ0P+i0mOjpMvPE6633F3rI0U3G+uv0ausIdW1aMCrR2aK6Tms= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619897072424735.6086752033515; Sat, 1 May 2021 12:24:32 -0700 (PDT) Received: from localhost ([::1]:36868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcvE7-0004oc-69 for importer@patchew.org; Sat, 01 May 2021 15:24:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcv55-0005b0-7L for qemu-devel@nongnu.org; Sat, 01 May 2021 15:15:11 -0400 Received: from donkey.codingfarm.de ([2a01:4f8:190:12cf::d:1]:43680) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcv53-0007pV-7F for qemu-devel@nongnu.org; Sat, 01 May 2021 15:15:10 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by donkey.codingfarm.de (Postfix) with ESMTPSA id 2E8E780B38; Sat, 1 May 2021 21:06:23 +0200 (CEST) Received: by zebra.codingfarm.de (Postfix, from userid 1000) id 003E844CD9; Sat, 1 May 2021 21:06:22 +0200 (CEST) From: =?UTF-8?q?Rainer=20M=C3=BCller?= To: qemu-devel@nongnu.org Subject: [PATCH 2/2] input-linux: Allow to toggle grab from QMP Date: Sat, 1 May 2021 21:06:22 +0200 Message-Id: <20210501190622.153901-3-raimue@codingfarm.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210501190622.153901-1-raimue@codingfarm.de> References: <20210501190622.153901-1-raimue@codingfarm.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a01:4f8:190:12cf::d:1; envelope-from=raimue@zebra.codingfarm.de; helo=donkey.codingfarm.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NO_DNS_FOR_FROM=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster , =?UTF-8?q?Rainer=20M=C3=BCller?= , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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=3Dkbd1,evdev=3D/dev/input/eventX,grab-active=3Doff 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=3Don is set, other devices will initially be grabbed according to their own grab-active option. The first toggle operation on a grab_all=3Don 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=3D/objects/kbd1 property=3Dgrab-active value=3Dtrue {"return": {}} (QEMU) qom-get path=3D/objects/kbd1 property=3Dgrab-active {"return": true} For devices with grab_all=3Don, the action will propagate to other devices as if the grab toggle hotkey was used. Signed-off-by: Rainer M=C3=BCller --- 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' } } =20 ## 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, Er= ror **errp) } =20 qemu_set_fd_handler(il->fd, input_linux_event, NULL, il); - if (il->keycount) { - /* delay grab until all keys are released */ - il->grab_request =3D true; - } else { + /* delay grab until all keys are released */ + if (il->grab_request && !il->keycount) { + il->grab_request =3D 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, i= nt value, il->grab_toggle =3D value; } =20 +static bool input_linux_get_grab_active(Object *obj, Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + return il->grab_active; +} + +static void input_linux_set_grab_active(Object *obj, bool value, + Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + if (!il->initialized) { + il->grab_request =3D value; + return; + } + + if (il->grab_active !=3D value) { + if (il->keycount) { + il->grab_request =3D true; + } else { + input_linux_toggle_grab(il); + } + } +} + static void input_linux_instance_init(Object *obj) { + InputLinux *il =3D INPUT_LINUX(obj); + + il->grab_request =3D true; } =20 static void input_linux_class_init(ObjectClass *oc, void *data) @@ -512,6 +540,9 @@ static void input_linux_class_init(ObjectClass *oc, voi= d *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, --=20 2.25.1