Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jLk9X-0007ex-Gb for mharc-grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55324) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLk9R-0007aC-9w for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLk9Q-0005fj-4v for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:09 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:47867 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 1jLk9Q-0005fB-1T for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586250247; 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=/cF/dzsF/yA667xtqZ10lH69hjdVyBKqrF3V2NMZezE=; b=NcLff05+4+KodBPqnnvOVEOsXHd9Xsohj1mikEYUnQ2Ae0x2DDpMnj2Jk5W1XHUDPOKTEM 7qQLv1QubMvFPqtZtnJ91Qm+qDH3EtOsbkpIFWdoGth8N88s6tklIgK6/tadsDeUP4z1+6 oZLjvZanSuNZ3IEqhg3MxmcK/wtAfCA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-390-dWWkVCi3P2661XfH6CCe0A-1; Tue, 07 Apr 2020 05:04:06 -0400 X-MC-Unique: dWWkVCi3P2661XfH6CCe0A-1 Received: by mail-wr1-f72.google.com with SMTP id y6so1406623wrq.21 for ; Tue, 07 Apr 2020 02:04:05 -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=fb/nz7zR5GS7VaqvdMCNv/fqfHGELlJM7aeHii4QUAs=; b=N+BNAjAF+8gzZBwwdRTgI7s1jsJb6fjKBL+MAo+vlTmsxT480f8odMIx3kLx23npG7 4gMsP0Y/7uRzBY+UMJov9kE6BnsAiqjDw4B+GobXJNSa2/8249ISVsEIh4Vf3c/+wZ1i 59hekFynAPm8fm0cJJTjdUtt/dRLmFN26avsOMTQF7hPOmMVEF/EArZNgA8/K4BtSXTQ 3k8WHmZitWK12XOAMV97Yx+N6Hw1sjEeZpFiF3XPpo6elA8Db3kLhhPH3xi1Ui4Uw4vU uzu+Coz7mmUryIb40BPKXl9AZ4VVFGNI5BtM5bMDVw6WpYobVFijePLDgjczcaMP8DSP 6Ixg== X-Gm-Message-State: AGi0PubplZs9Zxh/ivknaWaYoTtIggDZpH0eUzsg+BNjUFnGxu3eIvgo 6cXH8Z9tBTfuWAoP/9J298K657qz/LFTmCsWMT+XVpbFaVKrw4WBDjeje1DzOkXRVWfTGZw2YsM TWZqPR4xfj+k= X-Received: by 2002:adf:ee0c:: with SMTP id y12mr1553391wrn.85.1586250244325; Tue, 07 Apr 2020 02:04:04 -0700 (PDT) X-Google-Smtp-Source: APiQypLIR+rfBuTqVuHNWSegOppQbLoDFZGZUgdmp/giota1oUMGN1EMe7CuUvhdmDg9EgEoPs/Nzg== X-Received: by 2002:adf:ee0c:: with SMTP id y12mr1553370wrn.85.1586250244067; Tue, 07 Apr 2020 02:04:04 -0700 (PDT) Received: from minerva.home ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id o13sm7805444wrm.74.2020.04.07.02.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 02:04:03 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Hans de Goede , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH v2 3/6] efi/console: Add grub_console_read_key_stroke() helper function Date: Tue, 7 Apr 2020 11:03:48 +0200 Message-Id: <20200407090351.50921-4-javierm@redhat.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200407090351.50921-1-javierm@redhat.com> References: <20200407090351.50921-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: Tue, 07 Apr 2020 09:04:10 -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 --- Changes in v2: None grub-core/term/efi/console.c | 51 ++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c index 59d9604472a..2145f33c32a 100644 --- a/grub-core/term/efi/console.c +++ b/grub-core/term/efi/console.c @@ -193,27 +193,56 @@ grub_console_getkey_con (struct grub_term_input *term= __attribute__ ((unused))) return grub_efi_translate_key(key); } =20 +/* + * 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 int -grub_console_getkey_ex(struct grub_term_input *term) +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; + + if (consume) { + key_data.key.scan_code =3D 0; + key_data.key.unicode_char =3D 0; + } + + return 0; +} =20 - if (key =3D=3D GRUB_TERM_NO_KEY) +static int +grub_console_getkey_ex (struct grub_term_input *term) +{ + grub_efi_key_data_t key_data; + grub_efi_uint32_t kss; + int key =3D -1; + + if (grub_console_read_key_stroke (term->data, &key_data, &key, 1) || + 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