From 52edc2e06954c4285b13fa242a6a925801095d51 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 30 Apr 2026 12:42:01 -0400 Subject: [PATCH] [Feature] allow displaying the WPS/tree hotkey menu with hotkey press add 'Context Menu' item to WPS and Tree hotkeys this allows a user to display a menu of hotkey actions to execute when they press the hotkey items are voiced added 'View Album Art' Change-Id: I2199c4de536f347016e7a8d7f3c063da0b56a9a0 --- apps/onplay.c | 76 +++++++++++++++++++++++++++++++++++++++++--- apps/onplay.h | 2 ++ apps/settings_list.c | 32 ++++++++++++------- 3 files changed, 93 insertions(+), 17 deletions(-) diff --git a/apps/onplay.c b/apps/onplay.c index 82b5ab8931..824b2f38cc 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -1287,6 +1287,7 @@ static int hotkey_tree_run_plugin(void *param) return ONPLAY_RELOAD_DIR; } +static int hotkey_run_menu(void); /* display hotkey items as a menu */ static int hotkey_wps_run_plugin(void) { open_plugin_run(ID2P(LANG_HOTKEY_WPS)); @@ -1297,6 +1298,7 @@ static int hotkey_wps_run_plugin(void) /* Any desired hotkey functions go here, in the enum in onplay.h, and in the settings menu in settings_list.c. The order here is not important. */ + static const struct hotkey_assignment hotkey_items[] = { [0]{ .action = HOTKEY_OFF, .lang_id = LANG_OFF, @@ -1360,6 +1362,18 @@ static const struct hotkey_assignment hotkey_items[] = { .func = HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"), .return_code = ONPLAY_FUNC_RETURN, .flags = HOTKEY_FLAG_TREE }, + { .action = HOTKEY_CONTEXT_MENU, + .lang_id = LANG_ONPLAY_MENU_TITLE, + .func = HOTKEY_FUNC(hotkey_run_menu, NULL), + .return_code = ONPLAY_FUNC_RETURN, + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE }, +#ifdef HAVE_ALBUMART + { .action = HOTKEY_ALBUMART, + .lang_id = LANG_VIEW_ALBUMART, + .func = HOTKEY_FUNC(view_album_art, NULL), + .return_code = ONPLAY_OK, + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS }, +#endif #ifdef HAVE_TAGCACHE { .action = HOTKEY_PICTUREFLOW, .lang_id = LANG_ONPLAY_PICTUREFLOW, @@ -1380,11 +1394,8 @@ const struct hotkey_assignment *get_hotkey(int action) } /* Execute the hotkey function, if listed */ -static int execute_hotkey(bool is_wps) +static int execute_hotkey(int action) { - const int action = (is_wps ? global_settings.hotkey_wps : - global_settings.hotkey_tree); - /* search assignment struct for a match for the hotkey setting */ const struct hotkey_assignment *this_item = get_hotkey(action); @@ -1405,6 +1416,60 @@ static int execute_hotkey(bool is_wps) return func_return; /* Use value returned by function */ return return_code; /* or return the associated value */ } + +static const char* hotkey_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) +{ + (void)buffer; (void)buffer_len; + const struct hotkey_assignment **hk_menu = (const struct hotkey_assignment **)data; + return ID2P(hk_menu[selected_item + 1]->lang_id); /* +1 to skip HOTKEY_OFF */ +} + +static int hotkey_get_talk(int selected_item, void * data) +{ + if (global_settings.talk_menu) + { + const struct hotkey_assignment **hk_menu = (const struct hotkey_assignment **)data; + talk_id(hk_menu[selected_item + 1]->lang_id, false); /* +1 to skip HOTKEY_OFF */ + } + return 0; +} + +static int hotkey_run_menu(void) +{ + intptr_t flag = HOTKEY_FLAG_WPS; + if (selected_file.context != CONTEXT_WPS) + flag = HOTKEY_FLAG_TREE; + + const struct hotkey_assignment *hk_menu[ARRAYLEN(hotkey_items)]; + + struct simplelist_info info; + int count = 0; + for (size_t i = 0; i < ARRAYLEN(hotkey_items); i++) + { + hk_menu[i] = NULL; /*clear all the hk_menu entries prior to setting them */ + if ((hotkey_items[i].flags & flag) == flag) + { + if (hotkey_items[i].action != HOTKEY_CONTEXT_MENU) + { + hk_menu[count++] = &hotkey_items[i]; + } + } + } + + /* count -1 don't display HOTKEY_OFF item */ + simplelist_info_init(&info, str(LANG_ONPLAY_MENU_TITLE), count - 1, (void*)&hk_menu); + info.get_name = hotkey_get_name; + info.get_icon = NULL; + info.get_talk = hotkey_get_talk; + + simplelist_show_list(&info); + if (info.selection >= 0) /* run user selected hotkey item */ + { + return execute_hotkey(hk_menu[info.selection + 1]->action); + } + return ONPLAY_RELOAD_DIR; +} #endif /* HOTKEY */ int onplay(char* file, int attr, int from_context, bool hotkey, int customaction) @@ -1441,7 +1506,8 @@ int onplay(char* file, int attr, int from_context, bool hotkey, int customaction #ifdef HAVE_HOTKEY if (hotkey) - return execute_hotkey(from_context == CONTEXT_WPS); + return execute_hotkey((from_context == CONTEXT_WPS ? + global_settings.hotkey_wps : global_settings.hotkey_tree)); #else (void)hotkey; #endif diff --git a/apps/onplay.h b/apps/onplay.h index 4e5e6eeb69..e811b9b983 100644 --- a/apps/onplay.h +++ b/apps/onplay.h @@ -63,6 +63,8 @@ enum hotkey_action { HOTKEY_INSERT, HOTKEY_INSERT_SHUFFLED, HOTKEY_BOOKMARK_LIST, + HOTKEY_ALBUMART, + HOTKEY_CONTEXT_MENU, /* shows / executes above actions in a menu */ }; enum hotkey_flags { HOTKEY_FLAG_NONE = 0x0, diff --git a/apps/settings_list.c b/apps/settings_list.c index 59fd4537a0..e8508ab099 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -2337,30 +2337,38 @@ const struct settings_list settings[] = { #endif #ifdef HAVE_HOTKEY +/* WPS HOTKEY */ TABLE_SETTING(F_CB_ON_SELECT_ONLY, hotkey_wps, LANG_HOTKEY_WPS, HOTKEY_VIEW_PLAYLIST, "hotkey wps", "off,view playlist,show track info,pitchscreen,open with,delete,bookmark,plugin,bookmark list" - ,UNIT_INT, hotkey_formatter, hotkey_getlang, hotkey_callback,9, HOTKEY_OFF, - HOTKEY_VIEW_PLAYLIST, HOTKEY_SHOW_TRACK_INFO, HOTKEY_PITCHSCREEN, - HOTKEY_OPEN_WITH, HOTKEY_DELETE, HOTKEY_BOOKMARK, HOTKEY_PLUGIN, HOTKEY_BOOKMARK_LIST), +#ifdef HAVE_ALBUMART + ",show_album_art,context menu" + ,UNIT_INT, hotkey_formatter, hotkey_getlang, hotkey_callback,11, +#else + ",context menu" + ,UNIT_INT, hotkey_formatter, hotkey_getlang, hotkey_callback,10, +#endif + HOTKEY_OFF, HOTKEY_VIEW_PLAYLIST, HOTKEY_SHOW_TRACK_INFO, HOTKEY_PITCHSCREEN, + HOTKEY_OPEN_WITH, HOTKEY_DELETE, HOTKEY_BOOKMARK, HOTKEY_PLUGIN, HOTKEY_BOOKMARK_LIST, +#ifdef HAVE_ALBUMART + HOTKEY_ALBUMART, +#endif + HOTKEY_CONTEXT_MENU), +/* TREE HOTKEY */ TABLE_SETTING(0, hotkey_tree, LANG_HOTKEY_FILE_BROWSER, HOTKEY_OFF, "hotkey tree", #ifdef HAVE_TAGCACHE - "off,properties,pictureflow,open with,delete,insert,insert shuffled", + "off,properties,pictureflow,open with,delete,insert,insert shuffled,context menu", + UNIT_INT, hotkey_formatter, hotkey_getlang, NULL, 8, #else - "off,properties,open with,delete,insert,insert shuffled", -#endif - UNIT_INT, hotkey_formatter, hotkey_getlang, NULL, -#ifdef HAVE_TAGCACHE - 7, -#else - 6, + "off,properties,open with,delete,insert,insert shuffled,context menu", + UNIT_INT, hotkey_formatter, hotkey_getlang, NULL, 7, #endif HOTKEY_OFF,HOTKEY_PROPERTIES, #ifdef HAVE_TAGCACHE HOTKEY_PICTUREFLOW, #endif - HOTKEY_OPEN_WITH, HOTKEY_DELETE, HOTKEY_INSERT, HOTKEY_INSERT_SHUFFLED), + HOTKEY_OPEN_WITH, HOTKEY_DELETE, HOTKEY_INSERT, HOTKEY_INSERT_SHUFFLED, HOTKEY_CONTEXT_MENU), #endif /* HAVE_HOTKEY */ INT_SETTING(F_TIME_SETTING, resume_rewind, LANG_RESUME_REWIND, 0,