From nobody Sat Jul 25 20:04:12 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=0in.de ARC-Seal: i=1; a=rsa-sha256; t=1784020338; cv=none; d=zohomail.com; s=zohoarc; b=ApH7zKlq4Z30sJrdh4D7F4em/ScQXChHtkc6gzSWosqZ0SYWUjlCwRXhS7svW2YeRH6IOiPZCisI1YNEseUeJFkN4hk4OYZKajeERWV9ZFAZisWRigooGerTvrwU1oKL2kkwYrvH4aSIeDqZDqK8nfAFfjAvhbFbD+YrJQxSIic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784020338; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=B05oU7CqfXppjbVDov9OdQ+GJJ1COHL+Zzy5FvBj5Ng=; b=B5SgUvfrgEr1yx6Qcymui2gN4LSmFpkGYiOne6A0queXVnCfF6YEisyJriN7M4eO/khmwekcDWQy8kOKqL9R/ZmA6F9mjnpT1zJPvuAhAbk35FupCnjqhfNDcyG45cTdgVsp1RA1FJHbwDHKDaDZS8FleioRyqfDdATMKLmEz5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178402033863748.34722680667153; Tue, 14 Jul 2026 02:12:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjZB6-0002eu-Lc; Tue, 14 Jul 2026 05:11:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjZB6-0002em-3u for qemu-devel@nongnu.org; Tue, 14 Jul 2026 05:11:48 -0400 Received: from mout-p-101.mailbox.org ([80.241.56.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjZB3-0006Ir-O3 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 05:11:47 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA512) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4gztph3xYxz8v3J; Tue, 14 Jul 2026 11:11:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0in.de; s=MBO0001; t=1784020300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B05oU7CqfXppjbVDov9OdQ+GJJ1COHL+Zzy5FvBj5Ng=; b=tOPlHm5+edHIOMi/wkLzdC32ubV3hbhizgDTEpdFKaMxZUQW60IZITRp1bxeA+eBKEweIZ 11N8u6VPanO8FDMRQs+wtF1y4DycXHC+iE2uGmgmaOryxNR1eWD0Ub4A851doiXTPBfa2P Soe+ZB6G3OBiRcAGqTcSGHmOqajEwQPOHQYcFU3IbBcR+zRixPeV5J00ibU526m2kviLB8 DfNXqXTkO1S7GBx3hRdctuKRLxqxyhBxlb1cWZIq2Z8g+wBdJEwgfTnlbpAQJdwlZ2LW7n +x7uzsY2jrUkPfs01qsc6majoRaFc+VIwhTkWy8bMhr4PSlnn9rJ224shPSjKA== From: kernel@0in.de To: qemu-devel@nongnu.org Cc: Eric Blake , Markus Armbruster , Paolo Bonzini , "Daniel P . Berrange" , Marc-Andre Lureau , Justinien Bouron , Maximilian Senftleben Subject: [PATCH v6] input-linux: Add option to not grab device on guest start Date: Tue, 14 Jul 2026 11:10:27 +0200 Message-ID: <20260714091109.63544-1-kernel@0in.de> In-Reply-To: <20240307062823.2377318-1-justinien.bouron@gmail.com> References: <20240307062823.2377318-1-justinien.bouron@gmail.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=80.241.56.151; envelope-from=kernel@0in.de; helo=mout-p-101.mailbox.org X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @0in.de) X-ZM-MESSAGEID: 1784020341915158500 Content-Type: text/plain; charset="utf-8" From: Maximilian Senftleben Some workflows start a guest in the background and do not want evdev devices to be grabbed immediately. In that case, the current behavior is annoying because the host loses control of the keyboard or mouse before the user actually wants to interact with the guest. Add a new boolean input-linux property, grab-on-startup. When true, the device is grabbed during initialization, which keeps the existing behavior. When false, the device remains ungrabbed until the toggle key combination is entered. Also make sure startup grabbing is skipped entirely when grab-on-startup is false, even if keys are already pressed during device initialization. Without this, QEMU could still perform a delayed grab once those keys are released. This revives an earlier patch originally posted by Justinien Bouron and incorporates the follow-up review feedback. Link: https://patchew.org/QEMU/20240403055002.890760-1-justinien.bouron@gma= il.com/ Link: https://lists.gnu.org/archive/html/qemu-devel/2024-03/msg04004.html Signed-off-by: Maximilian Senftleben Acked-by: Markus Armbruster --- This revives Justinien Bouron's earlier input-linux grab-on-startup patch: https://patchew.org/QEMU/20240403055002.890760-1-justinien.bouron@gmai= l.com/ Last known review state: - Marc-Andre Lureau asked for a resend with an updated commit message: https://lists.gnu.org/archive/html/qemu-devel/2024-03/msg04003.html - Markus Armbruster reviewed the QAPI schema and pointed out that the delayed-grab path still needed to be skipped when keys are already pressed at startup and grab-on-startup is false: https://lists.gnu.org/archive/html/qemu-devel/2024-03/msg04004.html - Daniel P. Berrange asked for a clearer motivation for the feature: https://lists.gnu.org/archive/html/qemu-devel/2024-03/msg01969.html Changes since v5: - Fixed patch email line breaks qapi/qom.json | 14 +++++++++++++- ui/input-linux.c | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b/qapi/qom.json index d96cc5aa21..2e15af8259 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -558,13 +558,25 @@ # @grab-toggle: the key or key combination that toggles device grab # (default: ctrl-ctrl) # +# @grab-on-startup: if true, grab the device immediately upon starting +# the guest. Otherwise, don't grab the device until the +# combination is entered. This does not influence other devices +# even if grab_all is true, i.e. in the unlikely scenario where +# device1 has grab_all=3Dtrue + grab-on-startup=3Dtrue and device2 has +# grab-on-startup=3Dfalse, only device1 is grabbed on startup, then, +# once the grab combination is entered, grabbing is toggled off +# for both devices (because device1 enforces the grab_all +# property) until the combination is entered again at which point +# both devices will be grabbed. (default: true) (since 11.1). +# # Since: 2.6 ## { 'struct': 'InputLinuxProperties', 'data': { 'evdev': 'str', '*grab_all': 'bool', '*repeat': 'bool', - '*grab-toggle': 'GrabToggleKeys' }, + '*grab-toggle': 'GrabToggleKeys', + '*grab-on-startup': 'bool' }, 'if': 'CONFIG_LINUX' } =20 ## diff --git a/ui/input-linux.c b/ui/input-linux.c index f4eee1ffd7..767374e99a 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -43,6 +43,7 @@ struct InputLinux { bool grab_request; bool grab_active; bool grab_all; + bool grab_on_startup; bool keydown[KEY_CNT]; int keycount; int wheel; @@ -394,12 +395,17 @@ static void input_linux_complete(UserCreatable *uc, E= rror **errp) } =20 qemu_set_fd_handler(il->fd, input_linux_event, NULL, il); + if (!il->grab_on_startup) { + goto skip_grab; + } if (il->keycount) { /* delay grab until all keys are released */ il->grab_request =3D true; } else { input_linux_toggle_grab(il); } + +skip_grab: QTAILQ_INSERT_TAIL(&inputs, il, next); il->initialized =3D true; return; @@ -487,6 +493,21 @@ static void input_linux_set_grab_toggle(Object *obj, i= nt value, il->grab_toggle =3D value; } =20 +static bool input_linux_get_grab_on_startup(Object *obj, Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + return il->grab_on_startup; +} + +static void input_linux_set_grab_on_startup(Object *obj, bool value, + Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + il->grab_on_startup =3D value; +} + static void input_linux_instance_init(Object *obj) { } @@ -494,6 +515,7 @@ static void input_linux_instance_init(Object *obj) static void input_linux_class_init(ObjectClass *oc, const void *data) { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + ObjectProperty *grab_on_startup_prop; =20 ucc->complete =3D input_linux_complete; =20 @@ -510,6 +532,11 @@ static void input_linux_class_init(ObjectClass *oc, co= nst void *data) &GrabToggleKeys_lookup, input_linux_get_grab_toggle, input_linux_set_grab_toggle); + grab_on_startup_prop =3D object_class_property_add_bool( + oc, "grab-on-startup", + input_linux_get_grab_on_startup, + input_linux_set_grab_on_startup); + object_property_set_default_bool(grab_on_startup_prop, true); } =20 static const TypeInfo input_linux_info =3D { --=20 2.53.0