Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jOfFo-0006nf-0K for mharc-grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43629) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOfFk-0006gc-U0 for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOfFj-0005gY-Ma for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:44 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:24367 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOfFj-0005gE-IP for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586946403; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wT+G31Ppitao2IfxDA+RbyAkngDS9HfDuujssO7zk/Q=; b=eResSuqgQWGjEKRzk/JgssdarjQ7RyE7wH9YhCfgj0YXS9Gsz1lZ3/PrsTuu6NMCB1kGkU dZvWLW0YJd1HSCRElM48xbBKF/T5/f3cMKdxlE614YHrS9VUc7NjlRhB0HQiDdPXaZQBuR kJOQL1dmZzHN2AbYni/aMTNusp/MUMc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-JgwmOMTMMvabCPbo6QOPbw-1; Wed, 15 Apr 2020 06:26:41 -0400 X-MC-Unique: JgwmOMTMMvabCPbo6QOPbw-1 Received: by mail-wr1-f69.google.com with SMTP id 11so4029319wrc.3 for ; Wed, 15 Apr 2020 03:26:41 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TP+NRP6i9SdU8C4VbiYKqzBY9P9c/puRr3yaJNoXHyA=; b=cgQ+gV4ts8GtiOjQPCQWoqmMYn6OUlVuzjK0ubu3R6KR0oFTS6mYxNEZLK3ZYqp5a3 SUdrKKYa6HvTqEADWJYCzwJkco/4VvWROEsvcvxTUOIGkhisEnELGDKk5dyrZiBKF4vI RY9I9xJ8aiNDXWLv6Vvlvf97JGgsyXM/O7dcRPf8XLPU7L8024xt6qv+QnqEH7iETVim R298dxzQgDk+r/WX8t/YMGyXcMpBmsWay0N2gNGOETwI+gUKcVIVv09H55vWGoj2vKgk zOuBy2y5KbSbXjlokrSOR5ldcj4hiUqL5Vq7Jx+ZvMcJ5+ywYECe+6UggBz/trqG9ob+ g1kA== X-Gm-Message-State: AGi0PuZNvSOBwEalKY9MAMiJghJADGLApsNgWjqLhNkuvFtH4DOgeeVR XErMuxcffr9rHQ2tI+5nn19dragJR4A7EOKaImG/P6R7+siZ7jv9rijDHLr6+vV3a1/p06nWQYl pqRrQVmDZObA= X-Received: by 2002:adf:fd0a:: with SMTP id e10mr13942102wrr.160.1586946400146; Wed, 15 Apr 2020 03:26:40 -0700 (PDT) X-Google-Smtp-Source: APiQypKXYlGjjeqoive62RtCTypl7FS0AMArHd5WotrryMub242gxADubIZWIXm9y3UbYIthrXYUTw== X-Received: by 2002:adf:fd0a:: with SMTP id e10mr13942084wrr.160.1586946399896; Wed, 15 Apr 2020 03:26:39 -0700 (PDT) Received: from minerva.redhat.com ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id n124sm22803517wma.11.2020.04.15.03.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 03:26:39 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Hans de Goede , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH v3 3/6] efi/console: Add grub_console_read_key_stroke() helper function Date: Wed, 15 Apr 2020 12:26:19 +0200 Message-Id: <20200415102622.1890550-4-javierm@redhat.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200415102622.1890550-1-javierm@redhat.com> References: <20200415102622.1890550-1-javierm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Apr 2020 10:26:46 -0000 From: Hans de Goede This is a preparatory patch for adding getkeystatus() support to the EFI console driver. We can get modifier status through the simple_text_input read_key_stroke method, but if a non-modifier key is (also) pressed the read_key_stroke call will consume that key from the firmware's queue. The new grub_console_read_key_stroke() helper buffers upto 1 key-stroke. If it has a non-modifier key buffered, it will return that one, if its buffer is empty, it will fills its buffer by getting a new key-stroke. If called with consume=3D1 it will empty its buffer after copying the key-data to the callers buffer, this is how getkey() will use it. If called with consume=3D0 it will keep the last key-stroke buffered, this is how getkeystatus() will call it. This means that if a non-modifier key gets pressed, repeated getkeystatus() calls will return the modifiers of that key-press until it is consumed by a getkey() call. Signed-off-by: Hans de Goede Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Kiper --- Changes in v3: - Make grub_console_read_key_stroke() return GRUB_ERR_NONE instead of 0. Changes in v2: None grub-core/term/efi/console.c | 54 ++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c index 59d9604472a..0cb965a9931 100644 --- a/grub-core/term/efi/console.c +++ b/grub-core/term/efi/console.c @@ -193,27 +193,57 @@ grub_console_getkey_con (struct grub_term_input *term= __attribute__ ((unused))) return grub_efi_translate_key(key); } =20 -static int -grub_console_getkey_ex(struct grub_term_input *term) +/* + * When more then just modifiers are pressed, our getkeystatus() consumes = a + * press from the queue, this function buffers the press for the regular + * getkey() so that it does not get lost. + */ +static grub_err_t +grub_console_read_key_stroke ( + grub_efi_simple_text_input_ex_interface_t *text_input, + grub_efi_key_data_t *key_data_ret, int *key_ret, + int consume) { - grub_efi_key_data_t key_data; + static grub_efi_key_data_t key_data; grub_efi_status_t status; - grub_efi_uint32_t kss; - int key =3D -1; + int key; =20 - grub_efi_simple_text_input_ex_interface_t *text_input =3D term->data; + if (!text_input) + return GRUB_ERR_EOF; =20 - status =3D efi_call_2 (text_input->read_key_stroke, text_input, &key_dat= a); + key =3D grub_efi_translate_key (key_data.key); + if (key =3D=3D GRUB_TERM_NO_KEY) { + status =3D efi_call_2 (text_input->read_key_stroke, text_input, &key_d= ata); + if (status !=3D GRUB_EFI_SUCCESS) + return GRUB_ERR_EOF; =20 - if (status !=3D GRUB_EFI_SUCCESS) - return GRUB_TERM_NO_KEY; + key =3D grub_efi_translate_key (key_data.key); + } =20 - kss =3D key_data.key_state.key_shift_state; - key =3D grub_efi_translate_key(key_data.key); + *key_data_ret =3D key_data; + *key_ret =3D key; =20 - if (key =3D=3D GRUB_TERM_NO_KEY) + if (consume) { + key_data.key.scan_code =3D 0; + key_data.key.unicode_char =3D 0; + } + + return GRUB_ERR_NONE; +} + +static int +grub_console_getkey_ex (struct grub_term_input *term) +{ + grub_efi_key_data_t key_data; + grub_efi_uint32_t kss; + grub_err_t err; + int key =3D -1; + + err =3D grub_console_read_key_stroke (term->data, &key_data, &key, 1); + if (err !=3D GRUB_ERR_NONE || key =3D=3D GRUB_TERM_NO_KEY) return GRUB_TERM_NO_KEY; =20 + kss =3D key_data.key_state.key_shift_state; if (kss & GRUB_EFI_SHIFT_STATE_VALID) { if ((kss & GRUB_EFI_LEFT_SHIFT_PRESSED --=20 2.25.1