From nobody Fri Nov 7 10:16:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547992491169611.1733328693148; Sun, 20 Jan 2019 05:54:51 -0800 (PST) Received: from localhost ([127.0.0.1]:40159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glDYn-00029N-IZ for importer@patchew.org; Sun, 20 Jan 2019 08:54:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gl4Vj-00085Z-VN for qemu-devel@nongnu.org; Sat, 19 Jan 2019 23:15:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gl4Vi-0001Gr-VO for qemu-devel@nongnu.org; Sat, 19 Jan 2019 23:15:03 -0500 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:42860) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gl4Vi-0001G7-QO for qemu-devel@nongnu.org; Sat, 19 Jan 2019 23:15:02 -0500 Received: by mail-qt1-x841.google.com with SMTP id d19so19569587qtq.9 for ; Sat, 19 Jan 2019 20:15:02 -0800 (PST) Received: from earth.fios-router.home (pool-108-28-253-225.washdc.fios.verizon.net. [108.28.253.225]) by smtp.gmail.com with ESMTPSA id q54sm61977891qtb.64.2019.01.19.20.15.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Jan 2019 20:15:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4NcjpcwV3/v1oy8b9llG9C7qVrewmHbfScEtEE17aGA=; b=ZRIFu7oRT4uDM+mErIt6uxClV8xhxv1i08VYkTu7fU5CrT0qq6CZ0EKjyipzf8YtEq SRlcbAObRXLDc99xc7E+eyQA5kX6YWA5OmFUiRwnB8mj+Td8VV6bc1vceEeFfL11zcxy 9Ihu0/mPiY3Pz3G+xr943IGnbMFc+RlLlbmTOymdZCsDypugEJWa3US8AcooULGUcDBO 4IpbaUm0lBLHeiw9ml618lMrExoNPs47vPU4ouOjE4T21O3B7u20A864NLdxFSA3IYJG 1xNyUAth177kth3kvDzi0ly4M9rxO9nO0ihc3bbe4eqCmq+uk4sR+IErhzIuaeHDL0h0 bUNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4NcjpcwV3/v1oy8b9llG9C7qVrewmHbfScEtEE17aGA=; b=JB4ZjlQUmgmdgBzMKmbRd5SrDodHcWR/b+nBiL8KLs/TVBRvMhNlbNJDaI8pIvHo8y 2g1OH8O/AiDJGT6bGZwwIhStvjpTU4bV40Q+wqkucsXDixM5C05kI8UmWRhxuaQ85muJ dTdz1/hDlR4R2BWJnN/8aHjo28iuxhND9vcrt7EnhWDObpZvnBQFHbzK07m4eEMiXnGl iVkpPlXJUZjVWnKYznWEO1MmhZmj1c3xO9nM6cohKMd1/luODnZwSvEKhZKu2neIGDVs XAYR6TZIAzE4HtScOhV1tx+wy0v/r+OjbtbGqKSTzqPOxn66wvflD5xMTFpDpplkoGU7 qe2g== X-Gm-Message-State: AJcUukfNLdANC7da70kqVq9QsCE2johhFaMg1TH1Ie3bWW0hnIXFEGXH 7aDIj8UBiKWpMz9ORW4R2QGPi2ABuLeFUg== X-Google-Smtp-Source: ALg8bN72xNy2KpGH0z/5quyuZZs7PUlX1t9Hh0/jijgUexl+ESrv7kDbTGyHE6feTRJK3yPjy8McTw== X-Received: by 2002:a0c:8aa8:: with SMTP id 37mr21345308qvv.23.1547957701264; Sat, 19 Jan 2019 20:15:01 -0800 (PST) From: Ryan El Kochta To: qemu-devel@nongnu.org, kraxel@redhat.com Date: Sat, 19 Jan 2019 23:14:27 -0500 Message-Id: <20190120041427.21602-1-relkochta@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 X-Mailman-Approved-At: Sun, 20 Jan 2019 08:54:00 -0500 Subject: [Qemu-devel] [PATCH] input-linux: customizable grab toggle keys v4 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: , Cc: Ryan El Kochta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" This patch adds a new option to the input-linux object: grab-toggle=3D[key-combo] The key combination can be one of the following: * ctrl-ctrl * alt-alt * meta-meta * ctrl-alt * scrolllock * ctrl-scrolllock * ctrl-backtick The user can pick any of these key combinations. The VM's grab of the evdev device will be toggled when the key combination is pressed. Any invalid setting will result in an error. No setting will result in the current default of ctrl-ctrl. If scrolllock is selected as one of the grab-toggle keys, it will be entirely disabled and not passed to the guest at all. This is to prevent enabling it while attempting to leave or enter the VM. On the host, scrolllock can be disabled using xmodmap. First, find the modifier that Scroll_Lock is bound to: $ xmodmap -pm Then, remove Scroll_Lock from it, replacing modX with the modifier: $ xmodmap -e 'remove modX =3D Scroll_Lock' If Scroll_Lock is not bound to any modifier, it is already disabled. To save the changes, add them to your xinitrc. Side note - I have changed e-mail addresses from lightn1ngstr1ke@protonmail.com due to issues with git send-mail. I am the same person. Signed-off-by: Ryan El Kochta --- qapi/ui.json | 10 +++++++ ui/input-linux.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/qapi/ui.json b/qapi/ui.json index 5ad1324..487653a 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1016,6 +1016,16 @@ '*head' : 'int', 'events' : [ 'InputEvent' ] } } =20 +## +# @GrabToggleKeys: +# +# Keys to toggle input-linux between host and guest. +# +# Since: 4.0 +# +## +{ 'enum': 'GrabToggleKeys', + 'data': [ 'ctrl-ctrl', 'alt-alt', 'meta-meta', 'ctrl-alt', 'scrolllock',= 'ctrl-scrolllock', 'ctrl-backtick' ] } =20 ## # @DisplayGTK: diff --git a/ui/input-linux.c b/ui/input-linux.c index 9720333..65d1fb9 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -63,6 +63,8 @@ struct InputLinux { struct input_event event; int read_offset; =20 + enum GrabToggleKeys grab_toggle; + QTAILQ_ENTRY(InputLinux) next; }; =20 @@ -98,6 +100,51 @@ static void input_linux_toggle_grab(InputLinux *il) } } =20 +static bool input_linux_check_toggle(InputLinux *il) +{ + switch (il->grab_toggle) { + case GRAB_TOGGLE_KEYS_CTRL_CTRL: + return il->keydown[KEY_LEFTCTRL] && + il->keydown[KEY_RIGHTCTRL]; + + case GRAB_TOGGLE_KEYS_ALT_ALT: + return il->keydown[KEY_LEFTALT] && + il->keydown[KEY_RIGHTALT]; + + case GRAB_TOGGLE_KEYS_META_META: + return il->keydown[KEY_LEFTMETA] && + il->keydown[KEY_RIGHTMETA]; + + case GRAB_TOGGLE_KEYS_CTRL_ALT: + return il->keydown[KEY_LEFTCTRL] && + il->keydown[KEY_LEFTALT]; + + case GRAB_TOGGLE_KEYS_SCROLLLOCK: + return il->keydown[KEY_SCROLLLOCK]; + + case GRAB_TOGGLE_KEYS_CTRL_SCROLLLOCK: + return il->keydown[KEY_LEFTCTRL] && + il->keydown[KEY_SCROLLLOCK]; + + case GRAB_TOGGLE_KEYS_CTRL_BACKTICK: + return il->keydown[KEY_LEFTCTRL] && + il->keydown[KEY_GRAVE]; + + case GRAB_TOGGLE_KEYS__MAX: + /* avoid gcc error */ + break; + } + return false; +} + +static bool input_linux_should_skip(InputLinux *il, + struct input_event *event) +{ + return (il->grab_toggle =3D=3D GRAB_TOGGLE_KEYS_SCROLLLOCK || + il->grab_toggle =3D=3D GRAB_TOGGLE_KEYS_CTRL_SCROLLLOCK) && + event->code =3D=3D KEY_SCROLLLOCK; +} + static void input_linux_handle_keyboard(InputLinux *il, struct input_event *event) { @@ -128,14 +175,13 @@ static void input_linux_handle_keyboard(InputLinux *i= l, } =20 /* send event to guest when grab is active */ - if (il->grab_active) { + if (il->grab_active && !input_linux_should_skip(il, event)) { int qcode =3D qemu_input_linux_to_qcode(event->code); qemu_input_event_send_key_qcode(NULL, qcode, event->value); } =20 /* hotkey -> record switch request ... */ - if (il->keydown[KEY_LEFTCTRL] && - il->keydown[KEY_RIGHTCTRL]) { + if (input_linux_check_toggle(il)) { il->grab_request =3D true; } =20 @@ -410,6 +456,21 @@ static void input_linux_set_repeat(Object *obj, bool v= alue, il->repeat =3D value; } =20 +static int input_linux_get_grab_toggle(Object *obj, Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + return il->grab_toggle; +} + +static void input_linux_set_grab_toggle(Object *obj, int value, + Error **errp) +{ + InputLinux *il =3D INPUT_LINUX(obj); + + il->grab_toggle =3D value; +} + static void input_linux_instance_init(Object *obj) { object_property_add_str(obj, "evdev", @@ -421,6 +482,10 @@ 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_enum(obj, "grab-toggle", "GrabToggleKeys", + &GrabToggleKeys_lookup, + input_linux_get_grab_toggle, + input_linux_set_grab_toggle, NULL); } =20 static void input_linux_class_init(ObjectClass *oc, void *data) --=20 2.20.1