Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jCpkc-0000o2-Hx for mharc-grub-devel@gnu.org; Fri, 13 Mar 2020 15:13:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39601) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCpkZ-0000nW-Oj for grub-devel@gnu.org; Fri, 13 Mar 2020 15:13:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCpkY-0002tg-E8 for grub-devel@gnu.org; Fri, 13 Mar 2020 15:13:39 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:27011 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 1jCpkY-0002pI-55 for grub-devel@gnu.org; Fri, 13 Mar 2020 15:13:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584126817; 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; bh=MoFFTgGRCZuNIXk+T8fhI6MaUUcwJhjByGC8FdHRjnc=; b=WoqRrDiVhOyhkwSoxziC/LXzLLMVsZqvuI1syfsPE9/ObjbEc3BYuABKjfO8CZn1ZHDU0Y OKVz93/TX6Pmt4+grtnxmaSZmo0B6M40sE26kAWTyRtXXFIclkz7lvyzsJYdTbFulwo+3b qNNCmlqNbCE3OZA2xGOM4jW1wDc/z+g= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-eoEvNfBNOVGsNIi4nuwuuA-1; Fri, 13 Mar 2020 15:13:34 -0400 X-MC-Unique: eoEvNfBNOVGsNIi4nuwuuA-1 Received: by mail-wr1-f70.google.com with SMTP id u18so4719676wrn.11 for ; Fri, 13 Mar 2020 12:13:34 -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:mime-version :content-transfer-encoding; bh=1D3aZynFEiFcjlB8nhfc0GqvqTKJdh2dgg7O1tDFFUk=; b=K7IS6rop+OWQSCxK8C3GwFHXZy2fZIQupF2AsgjcRtzd6GTiszWpyGfHR7agsTPOmG fJ41ZaSs9Es7tHUIE7EQhZUzsP4EpJl3et0gDOt4Qs9beWoytj+dFrlFRU8wLf/PvkA/ 7RBqZCbv9Ng9/CtAnhjaUknHWTWe51S5PiuWClvK7WXgkm2NxqhL/algeJU39pheWivU 2ZlteJBvHrvOxrtBXgalKoytnMFaPaKIoLEO1EEEJHtwTqwWBD5C/WDJE3+OFXuVztxh D1kaueJgcSuI33+B2Yr2dR3wEy7kSotXodQCwIg2e8l9IOvtfbohVHTr7IzYQ/zMbnDl wgYg== X-Gm-Message-State: ANhLgQ1feX3BqgxUTgxG03esr9JlTPZOi9KalGZ6Rdx67+yFD+PmaQ+s sAEEI92IcAxGYcMm9bNCAzYyxFEO+xr5CbXcV3S4shbQCotnQ4RrCLSCyl/Vuy56aY9CSueiyJG wLIHc5rk9knI= X-Received: by 2002:a1c:2045:: with SMTP id g66mr12111582wmg.15.1584126813126; Fri, 13 Mar 2020 12:13:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtb/YaMjyF0/ugw/vVkC55fTeJ0LWjcB8xhgNdlgb9TWdzyxf2nEuWjUcPRPq5fLWkVEG2zVw== X-Received: by 2002:a1c:2045:: with SMTP id g66mr12111571wmg.15.1584126812886; Fri, 13 Mar 2020 12:13:32 -0700 (PDT) Received: from minerva.redhat.com ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id k3sm4943902wro.59.2020.03.13.12.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 12:13:32 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Daniel Kiper , Hans de Goede , Javier Martinez Canillas Subject: [PATCH 04/10] efi/console: Add grub_console_read_key_stroke() helper function Date: Fri, 13 Mar 2020 20:13:24 +0100 Message-Id: <20200313191324.826568-1-javierm@redhat.com> X-Mailer: git-send-email 2.24.1 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] [fuzzy] X-Received-From: 207.211.31.81 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: Fri, 13 Mar 2020 19:13:41 -0000 From: Hans de Goede This is a preparation patch for adding getkeystatus() support to the EFI console terminal input 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 --- 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 16ccd350ee0..11f85e84790 100644 --- a/grub-core/term/efi/console.c +++ b/grub-core/term/efi/console.c @@ -227,27 +227,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; +} + +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; =20 - if (key =3D=3D GRUB_TERM_NO_KEY) + 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.24.1