Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

onplay hotkey add flags

idea here as discussed with chris_s is to allow flags
in the hotkey_assignment struct to change how items are displayed

Change-Id: Id4cf1d79fbe3ff8f5590b9a863fccf00ddd457f9

+103 -79
+80 -73
apps/onplay.c
··· 1846 1846 open_plugin_run(ID2P(LANG_HOTKEY_WPS)); 1847 1847 return ONPLAY_OK; 1848 1848 } 1849 - 1850 - struct hotkey_assignment { 1851 - int action; /* hotkey_action */ 1852 - int lang_id; /* Language ID */ 1853 - struct menu_func func; /* Function to run if this entry is selected */ 1854 - int return_code; /* What to return after the function is run. */ 1855 - }; /* (Pick ONPLAY_FUNC_RETURN to use function's return value) */ 1856 - 1857 1849 #define HOTKEY_FUNC(func, param) {{(void *)func}, param} 1858 1850 1859 1851 /* Any desired hotkey functions go here, in the enum in onplay.h, 1860 1852 and in the settings menu in settings_list.c. The order here 1861 1853 is not important. */ 1862 - static struct hotkey_assignment hotkey_items[] = { 1863 - { HOTKEY_VIEW_PLAYLIST, LANG_VIEW_DYNAMIC_PLAYLIST, 1864 - HOTKEY_FUNC(NULL, NULL), 1865 - ONPLAY_PLAYLIST }, 1866 - { HOTKEY_SHOW_TRACK_INFO, LANG_MENU_SHOW_ID3_INFO, 1867 - HOTKEY_FUNC(browse_id3_wrapper, NULL), 1868 - ONPLAY_RELOAD_DIR }, 1854 + static const struct hotkey_assignment hotkey_items[] = { 1855 + [0]{ .action = HOTKEY_OFF, 1856 + .lang_id = LANG_OFF, 1857 + .func = HOTKEY_FUNC(NULL,NULL), 1858 + .return_code = ONPLAY_RELOAD_DIR, 1859 + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE }, 1860 + { .action = HOTKEY_VIEW_PLAYLIST, 1861 + .lang_id = LANG_VIEW_DYNAMIC_PLAYLIST, 1862 + .func = HOTKEY_FUNC(NULL, NULL), 1863 + .return_code = ONPLAY_PLAYLIST, 1864 + .flags = HOTKEY_FLAG_WPS }, 1865 + { .action = HOTKEY_SHOW_TRACK_INFO, 1866 + .lang_id = LANG_MENU_SHOW_ID3_INFO, 1867 + .func = HOTKEY_FUNC(browse_id3_wrapper, NULL), 1868 + .return_code = ONPLAY_RELOAD_DIR, 1869 + .flags = HOTKEY_FLAG_WPS }, 1869 1870 #ifdef HAVE_PITCHCONTROL 1870 - { HOTKEY_PITCHSCREEN, LANG_PITCH, 1871 - HOTKEY_FUNC(gui_syncpitchscreen_run, NULL), 1872 - ONPLAY_RELOAD_DIR }, 1871 + { .action = HOTKEY_PITCHSCREEN, 1872 + .lang_id = LANG_PITCH, 1873 + .func = HOTKEY_FUNC(gui_syncpitchscreen_run, NULL), 1874 + .return_code = ONPLAY_RELOAD_DIR, 1875 + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS }, 1873 1876 #endif 1874 - { HOTKEY_OPEN_WITH, LANG_ONPLAY_OPEN_WITH, 1875 - HOTKEY_FUNC(hotkey_open_with, NULL), 1876 - ONPLAY_RELOAD_DIR }, 1877 - { HOTKEY_DELETE, LANG_DELETE, 1878 - HOTKEY_FUNC(hotkey_delete_item, NULL), 1879 - ONPLAY_RELOAD_DIR }, 1880 - { HOTKEY_INSERT, LANG_INSERT, 1881 - HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert), 1882 - ONPLAY_RELOAD_DIR }, 1883 - { HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED, 1884 - HOTKEY_FUNC(hotkey_tree_pl_insert_shuffled, NULL), 1885 - ONPLAY_FUNC_RETURN }, 1886 - { HOTKEY_PLUGIN, LANG_OPEN_PLUGIN, 1887 - HOTKEY_FUNC(hotkey_wps_run_plugin, NULL), 1888 - ONPLAY_FUNC_RETURN }, 1889 - { HOTKEY_BOOKMARK, LANG_BOOKMARK_MENU_CREATE, 1890 - HOTKEY_FUNC(bookmark_create_menu, NULL), 1891 - ONPLAY_OK }, 1892 - { HOTKEY_PROPERTIES, LANG_PROPERTIES, 1893 - HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"), 1894 - ONPLAY_FUNC_RETURN }, 1877 + { .action = HOTKEY_OPEN_WITH, 1878 + .lang_id = LANG_ONPLAY_OPEN_WITH, 1879 + .func = HOTKEY_FUNC(hotkey_open_with, NULL), 1880 + .return_code = ONPLAY_RELOAD_DIR, 1881 + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE }, 1882 + { .action = HOTKEY_DELETE, 1883 + .lang_id = LANG_DELETE, 1884 + .func = HOTKEY_FUNC(hotkey_delete_item, NULL), 1885 + .return_code = ONPLAY_RELOAD_DIR, 1886 + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_TREE }, 1887 + { .action = HOTKEY_INSERT, 1888 + .lang_id = LANG_INSERT, 1889 + .func = HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert), 1890 + .return_code = ONPLAY_RELOAD_DIR, 1891 + .flags = HOTKEY_FLAG_TREE }, 1892 + { .action = HOTKEY_INSERT_SHUFFLED, 1893 + .lang_id = LANG_INSERT_SHUFFLED, 1894 + .func = HOTKEY_FUNC(hotkey_tree_pl_insert_shuffled, NULL), 1895 + .return_code = ONPLAY_FUNC_RETURN, 1896 + .flags = HOTKEY_FLAG_TREE }, 1897 + { .action = HOTKEY_PLUGIN, 1898 + .lang_id = LANG_OPEN_PLUGIN, 1899 + .func = HOTKEY_FUNC(hotkey_wps_run_plugin, NULL), 1900 + .return_code = ONPLAY_FUNC_RETURN, 1901 + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS }, 1902 + { .action = HOTKEY_BOOKMARK, 1903 + .lang_id = LANG_BOOKMARK_MENU_CREATE, 1904 + .func = HOTKEY_FUNC(bookmark_create_menu, NULL), 1905 + .return_code = ONPLAY_OK, 1906 + .flags = HOTKEY_FLAG_WPS | HOTKEY_FLAG_NOSBS }, 1907 + { .action = HOTKEY_PROPERTIES, 1908 + .lang_id = LANG_PROPERTIES, 1909 + .func = HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"properties"), 1910 + .return_code = ONPLAY_FUNC_RETURN, 1911 + .flags = HOTKEY_FLAG_TREE }, 1895 1912 #ifdef HAVE_TAGCACHE 1896 - { HOTKEY_PICTUREFLOW, LANG_ONPLAY_PICTUREFLOW, 1897 - HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"pictureflow"), 1898 - ONPLAY_FUNC_RETURN }, 1913 + { .action = HOTKEY_PICTUREFLOW, 1914 + .lang_id = LANG_ONPLAY_PICTUREFLOW, 1915 + .func = HOTKEY_FUNC(hotkey_tree_run_plugin, (void *)"pictureflow"), 1916 + .return_code = ONPLAY_FUNC_RETURN, 1917 + .flags = HOTKEY_FLAG_TREE }, 1899 1918 #endif 1900 1919 }; 1901 1920 1902 - /* Return the language ID for this action */ 1903 - int get_hotkey_lang_id(int action) 1921 + const struct hotkey_assignment *get_hotkey(int action) 1904 1922 { 1905 - int i = ARRAYLEN(hotkey_items); 1906 - while (i--) 1923 + for (size_t i = ARRAYLEN(hotkey_items) - 1; i < ARRAYLEN(hotkey_items); i--) 1907 1924 { 1908 1925 if (hotkey_items[i].action == action) 1909 - return hotkey_items[i].lang_id; 1926 + return &hotkey_items[i]; 1910 1927 } 1911 - 1912 - return LANG_OFF; 1928 + return &hotkey_items[0]; /* no valid hotkey set, return HOTKEY_OFF*/ 1913 1929 } 1914 1930 1915 1931 /* Execute the hotkey function, if listed */ 1916 1932 static int execute_hotkey(bool is_wps) 1917 1933 { 1918 - int i = ARRAYLEN(hotkey_items); 1919 - struct hotkey_assignment *this_item; 1920 1934 const int action = (is_wps ? global_settings.hotkey_wps : 1921 1935 global_settings.hotkey_tree); 1922 1936 1923 1937 /* search assignment struct for a match for the hotkey setting */ 1924 - while (i--) 1925 - { 1926 - this_item = &hotkey_items[i]; 1927 - if (this_item->action == action) 1928 - { 1929 - /* run the associated function (with optional param), if any */ 1930 - const struct menu_func func = this_item->func; 1931 - int func_return = ONPLAY_RELOAD_DIR; 1932 - if (func.function != NULL) 1933 - { 1934 - if (func.param != NULL) 1935 - func_return = (*func.function_w_param)(func.param); 1936 - else 1937 - func_return = (*func.function)(); 1938 - } 1939 - const int return_code = this_item->return_code; 1938 + const struct hotkey_assignment *this_item = get_hotkey(action); 1940 1939 1941 - if (return_code == ONPLAY_FUNC_RETURN) 1942 - return func_return; /* Use value returned by function */ 1943 - return return_code; /* or return the associated value */ 1944 - } 1940 + /* run the associated function (with optional param), if any */ 1941 + const struct menu_func func = this_item->func; 1942 + 1943 + int func_return = ONPLAY_RELOAD_DIR; 1944 + if (func.function != NULL) 1945 + { 1946 + if (func.param != NULL) 1947 + func_return = (*func.function_w_param)(func.param); 1948 + else 1949 + func_return = (*func.function)(); 1945 1950 } 1951 + const int return_code = this_item->return_code; 1946 1952 1947 - /* no valid hotkey set, ignore hotkey */ 1948 - return ONPLAY_RELOAD_DIR; 1953 + if (return_code == ONPLAY_FUNC_RETURN) 1954 + return func_return; /* Use value returned by function */ 1955 + return return_code; /* or return the associated value */ 1949 1956 } 1950 1957 #endif /* HOTKEY */ 1951 1958
+20 -3
apps/onplay.h
··· 21 21 #ifndef _ONPLAY_H_ 22 22 #define _ONPLAY_H_ 23 23 24 + #ifdef HAVE_HOTKEY 25 + #include "menu.h" 26 + #endif 27 + 24 28 int onplay(char* file, int attr, int from_screen, bool hotkey); 25 29 int get_onplay_context(void); 26 30 ··· 37 41 }; 38 42 39 43 #ifdef HAVE_HOTKEY 40 - int get_hotkey_lang_id(int action); 41 44 42 45 enum hotkey_action { 43 46 HOTKEY_OFF = 0, 44 47 HOTKEY_VIEW_PLAYLIST, 45 48 HOTKEY_PROPERTIES, 46 - #ifdef HAVE_TAGCACHE 47 49 HOTKEY_PICTUREFLOW, 48 - #endif 49 50 HOTKEY_SHOW_TRACK_INFO, 50 51 HOTKEY_PITCHSCREEN, 51 52 HOTKEY_OPEN_WITH, ··· 55 56 HOTKEY_INSERT, 56 57 HOTKEY_INSERT_SHUFFLED, 57 58 }; 59 + enum hotkey_flags { 60 + HOTKEY_FLAG_NONE = 0x0, 61 + HOTKEY_FLAG_WPS = 0x1, 62 + HOTKEY_FLAG_TREE = 0x2, 63 + HOTKEY_FLAG_NOSBS = 0x4, 64 + }; 65 + 66 + struct hotkey_assignment { 67 + int action; /* hotkey_action */ 68 + int lang_id; /* Language ID */ 69 + struct menu_func func; /* Function to run if this entry is selected */ 70 + int16_t return_code; /* What to return after the function is run. */ 71 + uint16_t flags; /* Flags what context, display options */ 72 + }; /* (Pick ONPLAY_FUNC_RETURN to use function's return value) */ 73 + 74 + const struct hotkey_assignment *get_hotkey(int action); 58 75 #endif 59 76 60 77 /* needed for the playlist viewer.. eventually clean this up */
+3 -3
apps/settings_list.c
··· 700 700 { 701 701 if (get_current_activity() != ACTIVITY_QUICKSCREEN) 702 702 { 703 - if (get_hotkey_lang_id(var) == LANG_OPEN_PLUGIN) 703 + if (get_hotkey(var)->action == HOTKEY_PLUGIN) 704 704 open_plugin_browse(ID2P(LANG_HOTKEY_WPS)); 705 705 } 706 706 } ··· 710 710 (void)buffer; 711 711 (void)buffer_size; 712 712 (void)unit; 713 - return str(get_hotkey_lang_id(value)); 713 + return str(get_hotkey(value)->lang_id); 714 714 } 715 715 static int32_t hotkey_getlang(int value, int unit) 716 716 { 717 717 (void)unit; 718 - return get_hotkey_lang_id(value); 718 + return get_hotkey(value)->lang_id; 719 719 } 720 720 #endif /* HAVE_HOTKEY */ 721 721