diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index a0dc15c30d..1cc8af5237 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -5686,6 +5686,40 @@ static void wifi_scan_callback(retro_task_t *task, } #endif +/** + * Before a refresh, we could have deleted a + * file on disk, causing selection_ptr to + * suddendly be out of range. + * + * Ensure it doesn't overflow. + **/ +static bool menu_displaylist_refresh(struct menu_state *menu_st, file_list_t *list) +{ + size_t list_size = 0; + if (list->size) + menu_entries_build_scroll_indices(menu_st, list); + if (menu_st->entries.list) + list_size = MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size; + + if (list_size) + { + size_t selection = menu_st->selection_ptr; + if (selection >= list_size) + { + size_t idx = list_size - 1; + menu_st->selection_ptr = idx; + if (menu_st->driver_ctx->navigation_set) + menu_st->driver_ctx->navigation_set(menu_st->userdata, true); + } + } + else + { + bool pending_push = true; + menu_driver_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push); + } + return true; +} + bool menu_displaylist_process(menu_displaylist_info_t *info) { #ifdef HAVE_NETWORKING @@ -5748,7 +5782,7 @@ bool menu_displaylist_process(menu_displaylist_info_t *info) } if (info_flags & MD_FLAG_NEED_REFRESH) - menu_entries_ctl(MENU_ENTRIES_CTL_REFRESH, info_list); + menu_displaylist_refresh(menu_st, info_list); if (info_flags & MD_FLAG_NEED_CLEAR) menu_st->selection_ptr = 0; diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 436f7bbb00..328d907c88 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -4380,42 +4380,6 @@ bool menu_entries_ctl(enum menu_entries_ctl_state state, void *data) *idx = menu_st->entries.begin; } break; - case MENU_ENTRIES_CTL_REFRESH: - /** - * Before a refresh, we could have deleted a - * file on disk, causing selection_ptr to - * suddendly be out of range. - * - * Ensure it doesn't overflow. - **/ - { - size_t list_size = 0; - file_list_t *list = (file_list_t*)data; - if (!list) - return false; - if (list->size) - menu_entries_build_scroll_indices(menu_st, list); - if (menu_st->entries.list) - list_size = MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size; - - if (list_size) - { - size_t selection = menu_st->selection_ptr; - if (selection >= list_size) - { - size_t idx = list_size - 1; - menu_st->selection_ptr = idx; - if (menu_st->driver_ctx->navigation_set) - menu_st->driver_ctx->navigation_set(menu_st->userdata, true); - } - } - else - { - bool pending_push = true; - menu_driver_ctl(MENU_NAVIGATION_CTL_CLEAR, &pending_push); - } - } - break; case MENU_ENTRIES_CTL_CLEAR: { unsigned i; diff --git a/menu/menu_entries.h b/menu/menu_entries.h index ff59b25622..0b7966e23a 100644 --- a/menu/menu_entries.h +++ b/menu/menu_entries.h @@ -42,7 +42,6 @@ enum menu_entries_ctl_state MENU_ENTRIES_CTL_SET_START, /* Returns the starting index of the menu entry list. */ MENU_ENTRIES_CTL_START_GET, - MENU_ENTRIES_CTL_REFRESH, MENU_ENTRIES_CTL_CLEAR, MENU_ENTRIES_CTL_SHOW_BACK };