Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jOfFt-00072W-EJ for mharc-grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43680) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOfFq-0006va-Rv for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOfFp-0005kt-AF for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:25368 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOfFp-0005jo-5t for grub-devel@gnu.org; Wed, 15 Apr 2020 06:26:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586946408; 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=Q/u3kovDW73jSoVcMwt6qEIAGKbSHImljK/pbC9ot7E=; b=WdV9+hnXKjADOyt2WKPAPZUhlwhACoPMwUwNmohKzPsYY2mwUgByyqNQkZ+piJ9ulrtIgX qzkhbph5YDanbn4oxczVECy9ryN1r+yNbSDjLZOjih2ouKjNJNlrPa6Bg8bl4KBgfH4ORF SFvlb7YjKqyhh9KyPm9uWaB7bw9sYcI= 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-193-IV1qad32OUS7DmVg7cGFMQ-1; Wed, 15 Apr 2020 06:26:46 -0400 X-MC-Unique: IV1qad32OUS7DmVg7cGFMQ-1 Received: by mail-wr1-f69.google.com with SMTP id e5so1751485wrs.23 for ; Wed, 15 Apr 2020 03:26:46 -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=N59vcN+JhrmMBzG1rpNIP8OwQUVp9ADBiDmWFaGYizE=; b=jyrYxLkZNWID5ToRfbWHq/juX8ygOf3wIin1aZQQO4jGDbibGtvwkQP+PePIfodW1e BIuuNTpIH97n/1pzsZRlBuh3JcZ82nThXiWS/6yzw0dhG5iVtnbbgogD93knL+Fw5lsr GQ3F7KwONh03ceQSFoxlL22/Po5tP3qfbiqXwwQtnen5dfsmfN8D5+w3Xi9sktfgCsv1 ZkSATXAxi8H1Sf8LmvCcSZA78PQ6mVOHe98lOqwiwXFw9gka8b2HCkF8j9pX1vm/M8II klu4wP8n8Bp+XdPsbe8DljB8RKaPVlXMgRcV0P2+iHxf/MlgkA4eQRgntuNxLEiaSF5H +rJg== X-Gm-Message-State: AGi0PuZDJepIUFyj/VIN5vBTpQIBstA43tHHTl+JdnQgl8r5kT8llxdc FNan4jTQiRbbF0q9ym96R7rSmOlJSjsIlCEkXu/GWxlmsr6M+F011emedslycF6wVqLpKiPwVKR tORxdnrxwtUc= X-Received: by 2002:adf:ce0a:: with SMTP id p10mr12871546wrn.89.1586946405163; Wed, 15 Apr 2020 03:26:45 -0700 (PDT) X-Google-Smtp-Source: APiQypLlTu05XSuECQf1bUKpcy+MMXPWJ9MdJ2+R+2J8us31tx3086gubdpxYpTGNJQDvVkUzcjLsg== X-Received: by 2002:adf:ce0a:: with SMTP id p10mr12871520wrn.89.1586946404777; Wed, 15 Apr 2020 03:26:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 03:26:43 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Hans de Goede , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH v3 6/6] kern/term: Accept ESC, F4 and holding SHIFT as user interrupt keys Date: Wed, 15 Apr 2020 12:26:22 +0200 Message-Id: <20200415102622.1890550-7-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] [fuzzy] X-Received-From: 207.211.31.120 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:52 -0000 From: Hans de Goede On some devices the ESC key is the hotkey to enter the BIOS/EFI setup screen, making it really hard to time pressing it right. Besides that ESC is also pretty hard to discover for a user who does not know it will unhide the menu. This commit makes F4, which was chosen because is not used as a hotkey to enter the BIOS setup by any vendor, also interrupt sleeps / stop the menu countdown. This solves the ESC gets into the BIOS setup and also somewhat solves the discoverability issue, but leaves the timing issue unresolved. This commit fixes the timing issue by also adding support for keeping SHIFT pressed during boot to stop the menu countdown. This matches what Ubuntu is doing, which should also help with discoverability. Signed-off-by: Hans de Goede Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Kiper --- Changes in v3: - Code style cleanups. - Fix a left over in the documentation. Changes in v2: - Fix commit message that had left overs from when F8 was used instead of F= 4. - Update documentation to explain that F4 and SHIFT are used now besides ES= C. - Also fix comments to reflect that F4 is used now and use proper style. docs/grub.texi | 33 +++++++++++++++++---------------- grub-core/commands/sleep.c | 2 +- grub-core/kern/term.c | 21 +++++++++++++++++++++ grub-core/normal/menu.c | 2 +- include/grub/term.h | 1 + 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index 8e6f9acecfa..24d37421a23 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1330,12 +1330,12 @@ menu and then wait for the timeout set by @samp{GRU= B_TIMEOUT} to expire before booting the default entry. Pressing a key interrupts the timeout. =20 If this option is set to @samp{countdown} or @samp{hidden}, then, before -displaying the menu, GRUB will wait for the timeout set by -@samp{GRUB_TIMEOUT} to expire. If @key{ESC} is pressed during that time, = it -will display the menu and wait for input. If a hotkey associated with a -menu entry is pressed, it will boot the associated menu entry immediately. -If the timeout expires before either of these happens, it will boot the -default entry. In the @samp{countdown} case, it will show a one-line +displaying the menu, GRUB will wait for the timeout set by @samp{GRUB_TIME= OUT} +to expire. If @key{ESC} or @key{F4} are pressed, or @key{SHIFT} is held d= own +during that time, it will display the menu and wait for input. If a hotke= y +associated with a menu entry is pressed, it will boot the associated menu = entry +immediately. If the timeout expires before either of these happens, it wil= l +boot the default entry. In the @samp{countdown} case, it will show a one-= line indication of the remaining time. =20 @item GRUB_DEFAULT_BUTTON @@ -1559,16 +1559,16 @@ configurations, but have better replacements: =20 @table @samp @item GRUB_HIDDEN_TIMEOUT -Wait this many seconds before displaying the menu. If @key{ESC} is presse= d -during that time, display the menu and wait for input according to -@samp{GRUB_TIMEOUT}. If a hotkey associated with a menu entry is pressed, -boot the associated menu entry immediately. If the timeout expires before -either of these happens, display the menu for the number of seconds -specified in @samp{GRUB_TIMEOUT} before booting the default entry. +Wait this many seconds before displaying the menu. If @key{ESC} or @key{F= 4} are +pressed, or @key{SHIFT} is held down during that time, display the menu an= d wait +for input according to @samp{GRUB_TIMEOUT}. If a hotkey associated with a= menu +entry is pressed, boot the associated menu entry immediately. If the time= out +expires before either of these happens, display the menu for the number of +seconds specified in @samp{GRUB_TIMEOUT} before booting the default entry. =20 If you set @samp{GRUB_HIDDEN_TIMEOUT}, you should also set @samp{GRUB_TIMEOUT=3D0} so that the menu is not displayed at all unless -@key{ESC} is pressed. +@key{ESC} or @key{F4} are pressed, or @key{SHIFT} is held down. =20 This option is unset by default, and is deprecated in favour of the less confusing @samp{GRUB_TIMEOUT_STYLE=3Dcountdown} or @@ -5162,9 +5162,10 @@ Alias for @code{hashsum --hash sha512 arg @dots{}}. = See command @command{hashsum =20 @deffn Command sleep [@option{--verbose}] [@option{--interruptible}] count Sleep for @var{count} seconds. If option @option{--interruptible} is given= , -allow @key{ESC} to interrupt sleep. With @option{--verbose} show countdown -of remaining seconds. Exit code is set to 0 if timeout expired and to 1 -if timeout was interrupted by @key{ESC}. +allow pressing @key{ESC}, @key{F4} or holding down @key{SHIFT} to interrup= t +sleep. With @option{--verbose} show countdown of remaining seconds. Exit = code +is set to 0 if timeout expired and to 1 if timeout was interrupted using a= ny +of the mentioned keys. @end deffn =20 =20 diff --git a/grub-core/commands/sleep.c b/grub-core/commands/sleep.c index e77e7900fac..a1370b710c9 100644 --- a/grub-core/commands/sleep.c +++ b/grub-core/commands/sleep.c @@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms) start =3D grub_get_time_ms (); =20 while (grub_get_time_ms () - start < ms) - if (grub_getkey_noblock () =3D=3D GRUB_TERM_ESC) + if (grub_key_is_interrupt (grub_getkey_noblock ())) return 1; =20 return 0; diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c index 93bd3378d18..14d59649832 100644 --- a/grub-core/kern/term.c +++ b/grub-core/kern/term.c @@ -138,6 +138,27 @@ grub_getkeystatus (void) return status; } =20 +int +grub_key_is_interrupt (int key) +{ + /* + * ESC sometimes is the BIOS setup hotkey and may be hard to discover, a= lso + * check F4, which was chosen because is not used as a hotkey to enter t= he + * BIOS setup by any vendor. + */ + if (key =3D=3D GRUB_TERM_ESC || key =3D=3D GRUB_TERM_KEY_F4) + return 1; + + /* + * Pressing keys at the right time during boot is hard to time, also all= ow + * interrupting sleeps / the menu countdown by keeping shift pressed. + */ + if (grub_getkeystatus() & (GRUB_TERM_STATUS_LSHIFT | GRUB_TERM_STATUS_RS= HIFT)) + return 1; + + return 0; +} + void grub_refresh (void) { diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index da66ad89180..8397886fa05 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -623,7 +623,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) =09 if (entry >=3D 0) =09=09break; =09 } -=09 if (key =3D=3D GRUB_TERM_ESC) +=09 if (grub_key_is_interrupt (key)) =09 { =09 timeout =3D -1; =09 break; diff --git a/include/grub/term.h b/include/grub/term.h index 9da03dc751e..3387cb0527c 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -330,6 +330,7 @@ void grub_putcode (grub_uint32_t code, struct grub_term= _output *term); int EXPORT_FUNC(grub_getkey) (void); int EXPORT_FUNC(grub_getkey_noblock) (void); int EXPORT_FUNC(grub_getkeystatus) (void); +int EXPORT_FUNC(grub_key_is_interrupt) (int key); void grub_cls (void); void EXPORT_FUNC(grub_refresh) (void); void grub_puts_terminal (const char *str, struct grub_term_output *term); --=20 2.25.1