From nobody Wed Nov 5 12:59:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534988095031457.64044448368804; Wed, 22 Aug 2018 18:34:55 -0700 (PDT) Received: from localhost ([::1]:33899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fseWD-0008DF-O3 for importer@patchew.org; Wed, 22 Aug 2018 21:34:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fseVE-0006fD-QJ for qemu-devel@nongnu.org; Wed, 22 Aug 2018 21:33:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fseLX-0002Fg-Gg for qemu-devel@nongnu.org; Wed, 22 Aug 2018 21:23:38 -0400 Received: from mail-40136.protonmail.ch ([185.70.40.136]:56562) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fseLW-0002EE-VD for qemu-devel@nongnu.org; Wed, 22 Aug 2018 21:23:35 -0400 Date: Thu, 23 Aug 2018 01:23:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1534987410; bh=XW6n0o3/vjVgasys3kDryUUkJyxnXVvxYZ9GDiX9Nwk=; h=Date:To:From:Reply-To:Subject:Feedback-ID:From; b=TMQO/hPfhBbn8fTSUnkcUmMjUA/o6BwqJ6IYCpRP5PngC9oThPZ481stUS/OifqJq ngwhb/uC4Nz+TOmJTVr/aH2TGoA7cI0OS7k48Wg6OAfYavZ3aE4PxzpBqx+xU3zCoM k8OF/TLGVsN9xNEDjvwllT0BozHlDuoSKSeou4Mw= To: "qemu-devel@nongnu.org" , "kraxel@redhat.com" Message-ID: Feedback-ID: bQ1YSMeFIHAUAn-uQLnVQcD6sUw_KdWbXPbLTy5DSY-qJoKk-ALPWbW_iVWAtXYm4PkoUPhIOhNDcF8xb3qjMA==:Ext:ProtonMail MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.70.40.136 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] [PATCH] input-linux: toggle for lock keys X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Ryan El Kochta via Qemu-devel Reply-To: Ryan El Kochta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch introduces three new options on the input-linux commandline: (a) ignore_caps_lock=3D[on|off] (b) ignore_num_lock=3D[on|off] (c) ignore_scroll_lock=3D[on|off] If enabled, the key will be disabled and not forwarded to the guest. There are two main reasons for this: (a) Without keyboard LEDs, it can be difficult to tell whether it is enabled or not (b) Preparation for another patch which will allow changing the keys used to toggle the input device's grab. If you set the key to KEY_SCROLLLOCK for example, it can be frustrating disabling scroll lock in the guest, as it will require pressing the key more than twice. I'm new to this, so if I've made a mistake, let me know ;-) Signed-off-by: Ryan El Kochta --- ui/input-linux.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/ui/input-linux.c b/ui/input-linux.c index 9720333b2c..059d0c02a7 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -63,6 +63,10 @@ struct InputLinux { struct input_event event; int read_offset; + bool ignore_caps_lock; + bool ignore_num_lock; + bool ignore_scroll_lock; + QTAILQ_ENTRY(InputLinux) next; }; @@ -98,6 +102,21 @@ static void input_linux_toggle_grab(InputLinux *il) } } +static bool input_linux_ignore_event(InputLinux *il, + struct input_event *event) +{ + if (il->ignore_caps_lock && event->code =3D=3D KEY_CAPSLOCK) { + return true; + } + if (il->ignore_num_lock && event->code =3D=3D KEY_NUMLOCK) { + return true; + } + if (il->ignore_scroll_lock && event->code =3D=3D KEY_SCROLLLOCK) { + return true; + } + return false; +} + static void input_linux_handle_keyboard(InputLinux *il, struct input_event *event) { @@ -127,8 +146,11 @@ static void input_linux_handle_keyboard(InputLinux *il, il->keycount--; } - /* send event to guest when grab is active */ - if (il->grab_active) { + /* + * send event to guest when grab is active, + * ignoring caps/num/scroll lock when ignore bit set + */ + if (il->grab_active && !input_linux_ignore_event(il, event)) { int qcode =3D qemu_input_linux_to_qcode(event->code); qemu_input_event_send_key_qcode(NULL, qcode, event->value); } @@ -410,6 +432,51 @@ static void input_linux_set_repeat(Object *obj, bool v= alue, il->repeat =3D value; } +static bool input_linux_get_ignore_caps_lock(Object *obj, Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + return il->ignore_caps_lock; +} + +static void input_linux_set_ignore_caps_lock(Object *obj, bool value, + Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + il->ignore_caps_lock =3D value; +} + +static bool input_linux_get_ignore_num_lock(Object *obj, Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + return il->ignore_num_lock; +} + +static void input_linux_set_ignore_num_lock(Object *obj, bool value, + Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + il->ignore_num_lock =3D value; +} + +static bool input_linux_get_ignore_scroll_lock(Object *obj, Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + return il->ignore_scroll_lock; +} + +static void input_linux_set_ignore_scroll_lock(Object *obj, bool value, + Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + il->ignore_scroll_lock =3D value; +} + static void input_linux_instance_init(Object *obj) { object_property_add_str(obj, "evdev", @@ -421,6 +488,15 @@ static void input_linux_instance_init(Object *obj) object_property_add_bool(obj, "repeat", input_linux_get_repeat, input_linux_set_repeat, NULL); + object_property_add_bool(obj, "ignore_caps_lock", + input_linux_get_ignore_caps_lock, + input_linux_set_ignore_caps_lock, NULL); + object_property_add_bool(obj, "ignore_num_lock", + input_linux_get_ignore_num_lock, + input_linux_set_ignore_num_lock, NULL); + object_property_add_bool(obj, "ignore_scroll_lock", + input_linux_get_ignore_scroll_lock, + input_linux_set_ignore_scroll_lock, NULL); } static void input_linux_class_init(ObjectClass *oc, void *data) -- 2.18.0