From nobody Tue Jul 14 09:11:51 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=1783969691; cv=none; d=zohomail.com; s=zohoarc; b=OBjQ1g7lVCDIMwPxUQ/MAyEDkrE9J9lllTg9MJzhTgnF3I8n3XKNNU6TDQNqFsi2igswDdc7iKJlDUj5XYpur9tlJcSPZ5YYXYbLN1Y8zxA3dUyv7hpCfFqiHxP1yQsPZ2kG1GtRaMNGQKmg0bYWqbHk64zBAsBdsGDA8OvS/xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783969691; h=Content-Type:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K2D5KzhgtzOWVpAh40HG1UrFqlC5+h1KGVbBsTIt3mI=; b=VnGPNrcgWaPVfUhgxH8q89u1zXR9RCf2IVg8zybrLXKQzy8xdnT7j0/Vz2LJ46H7vNCPBEZzrtWmsegNnZajUc0vpwhvUk1vSCC5BpyNhWQvkGvSDxN9bW2ZkDJ2ijdCVoYmM6/ryg4P1zlXfO7dXCvK04zYUlxYNwUDKqJR40Q= 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 1783969691822207.1617885408524; Mon, 13 Jul 2026 12:08:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjM0I-0007tW-6h; Mon, 13 Jul 2026 15:07:46 -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 1wjM0E-0007tE-In for qemu-devel@nongnu.org; Mon, 13 Jul 2026 15:07:43 -0400 Received: from mout-p-101.mailbox.org ([80.241.56.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1wjM0B-0006H2-Aj for qemu-devel@nongnu.org; Mon, 13 Jul 2026 15:07:42 -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 4gzX4j3mfxz8sYP; Mon, 13 Jul 2026 21:07:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0in.de; s=MBO0001; t=1783969653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=K2D5KzhgtzOWVpAh40HG1UrFqlC5+h1KGVbBsTIt3mI=; b=dtsMy7pD0Fs5JJhIgC2BO2agjKNqnihocYAaKypyv8MUksGngqdYnSdsYHVMaxz6aps6BQ jyCxazUJWxSq0w7lgFk92k1M/tyVr/53fxYo8Cs9HaHa+c6TXgq/h6edi/ebQN4wKjMFrI zfBqrBbh/w9n9C98fIux6mnl4C05K7PlXP+8ydQJaZYaMi05kEv/hBrrTHd1iAWXEzeAX3 Lw9GyA64hGc+g6qNSNXjKDDudBXiPhP+Wdq7qS1d1rlXJJMeoykSELPJrKFRcpgrv/QuwN WJcNZIeu8xPOnOGYA6VUK5rLSVGkEUxqbzYVmLySyv1QDDTOStYIFtYT2z24jg== Date: Mon, 13 Jul 2026 21:07:30 +0200 (CEST) From: Maximilian Senftleben To: qemu-devel@nongnu.org cc: Eric Blake , Markus Armbruster , Paolo Bonzini , "Daniel P. Berrange" , Marc-Andre Lureau , Justinien Bouron , Maximilian Senftleben Subject: [PATCH v5] input-linux: Add option to not grab a device upon guest startup Message-ID: <05e99ebc-5108-b2f1-4b1f-14e8715d0bf4@0in.de> MIME-Version: 1.0 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: 1783969693779158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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:=20 https://patchew.org/QEMU/20240403055002.890760-1-justinien.bouron@gmail.com/ Link: https://lists.gnu.org/archive/html/qemu-devel/2024-03/msg04004.html Signed-off-by: Maximilian Senftleben --- This revives Justinien Bouron's earlier input-linux grab-on-startup patch: =20 https://patchew.org/QEMU/20240403055002.890760-1-justinien.bouron@gmail.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 v4: - Fixed patch indentation 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 dd45ac1087..e3eda5c1ec 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,=20 Error **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,=20 int 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,=20 const 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 { -- 2.53.0