From patchwork Thu Aug 23 01:23:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10573329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A5121390 for ; Thu, 23 Aug 2018 01:34:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AB512BF9F for ; Thu, 23 Aug 2018 01:34:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CEDD2BFB5; Thu, 23 Aug 2018 01:34:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D04852BF9F for ; Thu, 23 Aug 2018 01:34:22 +0000 (UTC) Received: from localhost ([::1]:33899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fseVx-0008DF-Kb for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Aug 2018 21:34:21 -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 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: , X-Patchwork-Original-From: Ryan El Kochta via Qemu-devel From: "Denis V. Lunev\" via" Reply-To: Ryan El Kochta Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces three new options on the input-linux commandline: (a) ignore_caps_lock=[on|off] (b) ignore_num_lock=[on|off] (c) ignore_scroll_lock=[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(-) -- 2.18.0 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 == KEY_CAPSLOCK) { + return true; + } + if (il->ignore_num_lock && event->code == KEY_NUMLOCK) { + return true; + } + if (il->ignore_scroll_lock && event->code == 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 = 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 value, il->repeat = value; } +static bool input_linux_get_ignore_caps_lock(Object *obj, Error **errp) +{ + InputLinux *il = INPUT_LINUX(obj); + + return il->ignore_caps_lock; +} + +static void input_linux_set_ignore_caps_lock(Object *obj, bool value, + Error **errp) +{ + InputLinux *il = INPUT_LINUX(obj); + + il->ignore_caps_lock = value; +} + +static bool input_linux_get_ignore_num_lock(Object *obj, Error **errp) +{ + InputLinux *il = INPUT_LINUX(obj); + + return il->ignore_num_lock; +} + +static void input_linux_set_ignore_num_lock(Object *obj, bool value, + Error **errp) +{ + InputLinux *il = INPUT_LINUX(obj); + + il->ignore_num_lock = value; +} + +static bool input_linux_get_ignore_scroll_lock(Object *obj, Error **errp) +{ + InputLinux *il = INPUT_LINUX(obj); + + return il->ignore_scroll_lock; +} + +static void input_linux_set_ignore_scroll_lock(Object *obj, bool value, + Error **errp) +{ + InputLinux *il = INPUT_LINUX(obj); + + il->ignore_scroll_lock = 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)