Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jLk9q-0007k9-H5 for mharc-grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55411) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLk9g-0007iI-Ax for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLk9e-0005rJ-Mx for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24656 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 1jLk9a-0005oA-R9 for grub-devel@gnu.org; Tue, 07 Apr 2020 05:04:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586250258; 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=vYmKkSMuqz/AXv2w6ujLrKeNUX+5fSzFx4zouJWwZQ0=; b=Sf8cE1c0bV2IEitFHDI4TRsVmWJ9tWxrf6jLReLR9ovnLtQQ2XYxp/vYx3pvaF9+MiZY0J /4vM/Wrabo4vA6x7Zurnu4tMT8aoBHyLn1PgBW2TSCZCoMwDbw07Yk2ZTEkb6C16D4NdYn 826JaH80j/Fv8cVp8JXpKmGXHXcy8Hk= 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-118-hiC58Lm4OQKofgcCyX5pJQ-1; Tue, 07 Apr 2020 05:04:11 -0400 X-MC-Unique: hiC58Lm4OQKofgcCyX5pJQ-1 Received: by mail-wr1-f69.google.com with SMTP id u16so1421422wrp.14 for ; Tue, 07 Apr 2020 02:04:11 -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=WwFeyTe6OrgO5g7JordQP37+SExBDbFxWeA/fykclLY=; b=iEkYofdzaqY8Bacyk/hkvNN8VnxylGZpXXy/oHaNfvv+RrjMjIUHXxYDf1LQji7m2I FfEp8dPvg0cxUxjn/syCJrCP5bXHqMqrIYc+H8nGqS8uF2Ju4ERfluD/BdwadBoblR3T F4o6ZOeUG1o8B2W4nwOLoWnqVlHWpFfT9YhUdZcP8vg5DHCQbM8VLNQeKT3G4Kltm1RP hkq/Zt0Et/D8Dgswvb9FJIe1C59bjW9aGkjJbkulVcftadQ6K+U+U4Il52T8TwxPXOtt yt6A22KWPXc5TktErvzOosX5zzxHRCKLjVZD+tgOWkYQ+IyuIq2st4Mom8jyuk4q9V9A mHQQ== X-Gm-Message-State: AGi0PuaXuXDBpUkmG4o56uSOQqwY2UkKz5WHYiFhXMKRZEWFLroZGHDi w1d1w9X95vfy4pCywucbBBPEPkt1gK7nfQA2brCjzpw0ZlUPwAYkoH+PQ+TzGV5pmsMQQ+XfjAx 1oNElXQxHmbk= X-Received: by 2002:a7b:cb03:: with SMTP id u3mr1262934wmj.12.1586250249996; Tue, 07 Apr 2020 02:04:09 -0700 (PDT) X-Google-Smtp-Source: APiQypKMhHaEM8DZOC2kaSsGcpAHvUqtH9M5aOTBpOpj0K9ypW9bTkCX+AVPI6QWPX0w65wmqnw/4w== X-Received: by 2002:a7b:cb03:: with SMTP id u3mr1262911wmj.12.1586250249705; Tue, 07 Apr 2020 02:04:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 02:04:09 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Hans de Goede , Daniel Kiper , Javier Martinez Canillas Subject: [PATCH v2 6/6] kern/term: Accept ESC, F4 and holding SHIFT as user interrupt keys Date: Tue, 7 Apr 2020 11:03:51 +0200 Message-Id: <20200407090351.50921-7-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.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: Tue, 07 Apr 2020 09:04:30 -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 --- 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 | 32 ++++++++++++++++---------------- 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, 40 insertions(+), 18 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index 8e6f9acecfa..25e81b6d57a 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,9 @@ Alias for @code{hashsum --hash sha512 arg @dots{}}. S= ee 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 by @key= {ESC}. @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..510fd5b8ddd 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_RSHI= FT)) + 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