From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1S1nCm-00062r-L6 for mharc-grub-devel@gnu.org; Sun, 26 Feb 2012 18:08:36 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1nCg-00062i-IV for grub-devel@gnu.org; Sun, 26 Feb 2012 18:08:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S1nCb-0001VW-DK for grub-devel@gnu.org; Sun, 26 Feb 2012 18:08:30 -0500 Received: from mail-ee0-f41.google.com ([74.125.83.41]:34215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1nCb-0001VS-34 for grub-devel@gnu.org; Sun, 26 Feb 2012 18:08:25 -0500 Received: by eeke53 with SMTP id e53so1436125eek.0 for ; Sun, 26 Feb 2012 15:08:23 -0800 (PST) Received-SPF: pass (google.com: domain of futur.andy@googlemail.com designates 10.213.19.194 as permitted sender) client-ip=10.213.19.194; Authentication-Results: mr.google.com; spf=pass (google.com: domain of futur.andy@googlemail.com designates 10.213.19.194 as permitted sender) smtp.mail=futur.andy@googlemail.com; dkim=pass header.i=futur.andy@googlemail.com Received: from mr.google.com ([10.213.19.194]) by 10.213.19.194 with SMTP id c2mr3284493ebb.113.1330297703930 (num_hops = 1); Sun, 26 Feb 2012 15:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type; bh=qF0yLrs5NVaBM4sTH44LGN0pdCU+BJa3YiAqhUmxNv8=; b=yGWahxm8GzXPKuwG6DrGmpT4vE9kQlA8v1Oqn8U6sFOwe1NhQQrBaVy1tJd8Wu8o3X is+SL7RZ1LjsnSBF1dTDMQC+P2XPOcMLVSQMSUa9hvGDirKO5r+gQ0cl9yxV2dI47lGH oY0IrJAx9NKa8JzW1OubmA1gl9C5zsHNttt7Q= Received: by 10.213.19.194 with SMTP id c2mr2468174ebb.113.1330297703810; Sun, 26 Feb 2012 15:08:23 -0800 (PST) Received: from [192.168.178.55] (p5091CA93.dip.t-dialin.net. [80.145.202.147]) by mx.google.com with ESMTPS id r5sm38297837eef.6.2012.02.26.15.08.22 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 26 Feb 2012 15:08:22 -0800 (PST) Message-ID: <4F4ABB64.6020305@googlemail.com> Date: Mon, 27 Feb 2012 00:08:20 +0100 From: Andreas Born User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120220 Thunderbird/10.0.2 MIME-Version: 1.0 To: GRUB2 Devel Subject: Support for different hotkey action than execute Content-Type: multipart/mixed; boundary="------------000803020307090107090408" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.83.41 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Feb 2012 23:08:35 -0000 This is a multi-part message in MIME format. --------------000803020307090107090408 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Attached patch introduces a new environment variable hotkey_action. It can be set to select or execute, whereas the latter is the default. So the default behaviour doesn't change. With select set instead a menu entry is just selected and not executed/booted on hotkey press. This is for example useful for long menus to directly jump to some initial and afterwards select the desired entry without going through the whole menu. One still has to explicitly mark the menu entry to jump to with the hotkey attribute. This patch only allows to change the action to take on hotkey press. Not much code and most is inspired from grub_menu_get_timeout. Applies and works with r3991. Add support to the menu for changing the action on hotkey press: execute (default), select * grub-core/normal/menu.c (DEFAULT_HOTKEY_ACTION): New define. (run_menu): Handle hotkey_action. (grub_menu_get_hotkey_action): New function. * include/grub/menu.h (grub_menu_get_hotkey_action): New prototype. (grub_hotkey_action_type_t): New enum. --------------000803020307090107090408 Content-Type: text/plain; name="hotkey-action.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="hotkey-action.patch" === modified file 'grub-core/normal/menu.c' --- grub-core/normal/menu.c 2012-02-18 18:59:01 +0000 +++ grub-core/normal/menu.c 2012-02-26 22:31:49 +0000 @@ -37,6 +37,10 @@ entry failing to boot. */ #define DEFAULT_ENTRY_ERROR_DELAY_MS 2500 +/* The default action to choose for hotkeys when nothing is explicitly + specified. */ +#define DEFAULT_HOTKEY_ACTION GRUB_HOTKEY_ACTION_TYPE_EXECUTE + grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu, int nested) = NULL; @@ -70,6 +74,35 @@ return e; } +/* Return the hotkey action. If the variable "hotkey_action" is not set + or invalid, return DEFAULT_HOTKEY_ACTION. */ +grub_hotkey_action_type_t +grub_menu_get_hotkey_action (void) +{ + const char *val; + + val = grub_env_get ("hotkey_action"); + + if (val) + { + if (grub_strcasecmp (val, "execute") == 0) + { + return GRUB_HOTKEY_ACTION_TYPE_EXECUTE; + } + else if (grub_strcasecmp (val, "select") == 0) + { + return GRUB_HOTKEY_ACTION_TYPE_SELECT; + } + /* If the value is invalid, unset the variable. */ + else + { + grub_env_unset ("hotkey_action"); + } + } + + return DEFAULT_HOTKEY_ACTION; +} + /* Return the current timeout. If the variable "timeout" is not set or invalid, return -1. */ int @@ -496,6 +529,7 @@ grub_uint64_t saved_time; int default_entry, current_entry; int timeout; + grub_hotkey_action_type_t hotkey_action; default_entry = get_entry_number (menu, "default"); @@ -519,6 +553,7 @@ refresh: menu_init (current_entry, menu, nested); + hotkey_action = grub_menu_get_hotkey_action (); timeout = grub_menu_get_timeout (); if (timeout > 0) @@ -653,10 +688,21 @@ i++, entry = entry->next) if (entry->hotkey == c) { - menu_fini (); - *auto_boot = 0; - return i; - } + switch (hotkey_action) + { + case GRUB_HOTKEY_ACTION_TYPE_SELECT: + current_entry = i; + menu_set_chosen_entry (current_entry); + break; + case GRUB_HOTKEY_ACTION_TYPE_EXECUTE: + menu_fini (); + *auto_boot = 0; + return i; + default: + /* Never reach here */ + break; + } + } } break; } === modified file 'include/grub/menu.h' --- include/grub/menu.h 2011-01-10 22:27:58 +0000 +++ include/grub/menu.h 2012-02-26 22:31:49 +0000 @@ -91,11 +91,20 @@ } *grub_menu_execute_callback_t; +/* Possible actions to perform when a hotkey is pressed */ +typedef enum +{ + GRUB_HOTKEY_ACTION_TYPE_EXECUTE, + GRUB_HOTKEY_ACTION_TYPE_SELECT +} grub_hotkey_action_type_t; + + grub_menu_entry_t grub_menu_get_entry (grub_menu_t menu, int no); int grub_menu_get_timeout (void); void grub_menu_set_timeout (int timeout); void grub_menu_entry_run (grub_menu_entry_t entry); int grub_menu_get_default_entry_index (grub_menu_t menu); +grub_hotkey_action_type_t grub_menu_get_hotkey_action (void); void grub_menu_init (void); void grub_menu_fini (void); --------------000803020307090107090408--