From nobody Sun May 12 19:45:41 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1709820224; cv=none; d=zohomail.com; s=zohoarc; b=Dn/KTjz2fLI1hU9Fg2vomSL4YrslZ+J8THaZW/3u55dT7eQMQJx6RO3KJG6FHoB3/zokL2nrM0TJaXAwvMsEphkBoSIJ9UWyQHGxpy0JvtiuMivZJ38TNO3hoAK2PBbwruG9dcZvbfkv/qiCZjiDwPRbhPe8/4JpL9lxHswQSuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709820224; h=Content-Transfer-Encoding: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=iyxR+OpRzCgMTyr69jyOIljZ6vwQoblG0/7Lpey7Y8k=; b=TLJwAAMQwlC0ux8x70mhotlfoEu8vL4tXTc9GtdBtSuUNo8NQtjiV4a7i2KroHFUp6etP96ASM+22f6msSJmrWOYq4I9T6tDe73tvXKZo9jDa3vAB1OoVaMlYUoZuv1hMxi0Tz4a0Xjzy+0fDlZ7x1SbXMiyVUCN3aVKfDRjZtI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709820224084300.7036915228073; Thu, 7 Mar 2024 06:03:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riEKb-00084f-Qj; Thu, 07 Mar 2024 09:02:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ri7Hw-0007n1-Ub for qemu-devel@nongnu.org; Thu, 07 Mar 2024 01:31:32 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ri7Hv-0007qJ-4e for qemu-devel@nongnu.org; Thu, 07 Mar 2024 01:31:32 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e5760eeb7aso391028b3a.1 for ; Wed, 06 Mar 2024 22:31:30 -0800 (PST) Received: from localhost.localdomain (c-24-7-119-110.hsd1.ca.comcast.net. [24.7.119.110]) by smtp.gmail.com with ESMTPSA id m7-20020aa78a07000000b006e319d8c752sm11778013pfa.150.2024.03.06.22.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 22:31:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709793089; x=1710397889; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iyxR+OpRzCgMTyr69jyOIljZ6vwQoblG0/7Lpey7Y8k=; b=jezloXzoe+7V7xeElEKeD75Q5P/M/yh3rn9Wr1Bam/T59P+c8Vj/gtMgry8fn2xFvR MN1wL567ljpoVfJtpG7U2eObDh597/oJaKRepLd56Hn76szjKw96C8oRGLkDatdtIDe6 gsnmyXmdG/XkcMSZgkzhKeOvMOQ5OpNwy+B5mRB7eoJlzXYSYwbDtBSSktosSodw6tHH sGU5XRgpVsTU6kyVCabJ2JIvWdlgMTwPKPSwNYXkHYHOgQe0az6lmIbGSTFlPmf5P95T eD5HLJIY2mAi5yNUtULIj9u88lvhWzhUvkQ7VlRzbrPMM9F4Bb9T+FdgpUE3KeJuRG6T cOmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709793089; x=1710397889; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iyxR+OpRzCgMTyr69jyOIljZ6vwQoblG0/7Lpey7Y8k=; b=nQtfE95RnvpZ1xXi09lTpFxgmxAC0wAdanS7c1qUXUQUwXqQS5wLakjXoYVchyHW7X 5Emf7GcwzJmYq2nAM9sbzt3Wm9p4vJ0dm7NHtvddnxfIs2Wu0LgVEKAMvfteBRwU8rJf GvCae8FNkqYB9g3Zn7Whe7gRzx9OBVIT47nplSQOobRfI1BYqGX3lWxuYkk8hH9e9ebC R7scvO4d8+CIIeDUmCuEqpU5eQMlwvyMRnC/H3W3CGthpnNsdKA1pnE6HA/aqF8nEc5/ 482Rgkg43BuHyRg080lMZqwRu1G3bSZRz72gFnFHcl1DKMu32OMQlaaujFy/q2vOlrD5 oZ6w== X-Forwarded-Encrypted: i=1; AJvYcCX8wmlPftICNJUM1nn2oigbcqIEofpRhdjHiniKs6UkeWWZ1KOhnnVcuoO3SEiOJ3VY0J0TH9gqh5VYENvJH+CUbqlmaSo= X-Gm-Message-State: AOJu0YxUyKGlnyTAlBjf98ZAs0kN+pp/m341TdgG2If2p35/pXknLfzZ 4z33cJVwk07T+6I0zDLiWpyZ8QQPeCW//gA+ULGPmUYDX5A454cT X-Google-Smtp-Source: AGHT+IHOSHoVkxGGJ/afxQ+Ux1zuq/xc1DFYvgtHTlH84qdu6Lt9mPuue8RocXPSKaVQaIoCMMm7wg== X-Received: by 2002:a05:6a20:af87:b0:1a1:4487:ee25 with SMTP id ds7-20020a056a20af8700b001a14487ee25mr6015172pzb.49.1709793089063; Wed, 06 Mar 2024 22:31:29 -0800 (PST) From: Justinien Bouron To: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Eric Blake , Markus Armbruster , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Cc: Justinien Bouron , qemu-devel@nongnu.org Subject: [PATCH] input-linux: Add option to not grab a device upon guest startup Date: Wed, 6 Mar 2024 22:28:22 -0800 Message-ID: <20240307062823.2377318-1-justinien.bouron@gmail.com> X-Mailer: git-send-email 2.43.0 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=justinien.bouron@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 07 Mar 2024 09:02:44 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @gmail.com) X-ZM-MESSAGEID: 1709820226160100003 Content-Type: text/plain; charset="utf-8" Depending on your use-case, it might be inconvenient to have qemu grab the input device immediately upon starting the guest, especially if the guest takes a while to start in which case it may take a few seconds before being able to release the device via the toggle combination. Added a new bool option to input-linux: grab-on-startup. If true, the device is grabbed as soon as the guest is started, otherwise it is not grabbed until the toggle combination is entered. To avoid breaking existing setups, the default value of grab-on-startup is true, ie. same behaviour as before this change. Signed-off-by: Justinien Bouron --- qapi/qom.json | 13 ++++++++++++- ui/input-linux.c | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index 032c6fa037..50e66d55cc 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -508,13 +508,24 @@ # @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 ent= ered. +# This does not influence other devices even if grab_all is true, ie. = in the +# unlikely scenario where device1 has grab_all=3Dtrue + grab-on-startu= p=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 gra= bbed. +# (default: true). + # Since: 2.6 ## { 'struct': 'InputLinuxProperties', 'data': { 'evdev': 'str', '*grab_all': 'bool', '*repeat': 'bool', - '*grab-toggle': 'GrabToggleKeys' } } + '*grab-toggle': 'GrabToggleKeys', + '*grab-on-startup': 'bool'} } =20 ## # @EventLoopBaseProperties: diff --git a/ui/input-linux.c b/ui/input-linux.c index e572a2e905..cf9376ddb0 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -44,6 +44,7 @@ struct InputLinux { bool grab_request; bool grab_active; bool grab_all; + bool grab_on_startup; bool keydown[KEY_CNT]; int keycount; int wheel; @@ -400,7 +401,7 @@ static void input_linux_complete(UserCreatable *uc, Err= or **errp) if (il->keycount) { /* delay grab until all keys are released */ il->grab_request =3D true; - } else { + } else if (il->grab_on_startup) { input_linux_toggle_grab(il); } QTAILQ_INSERT_TAIL(&inputs, il, next); @@ -491,6 +492,19 @@ 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) { } @@ -498,6 +512,7 @@ static void input_linux_instance_init(Object *obj) static void input_linux_class_init(ObjectClass *oc, void *data) { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + ObjectProperty *grab_on_startup_prop; =20 ucc->complete =3D input_linux_complete; =20 @@ -514,6 +529,9 @@ static void input_linux_class_init(ObjectClass *oc, voi= d *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-s= tartup", + 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.43.0