From f5fce953308e544d3ded4f3052dde8bc3157571f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 20 Apr 2022 23:24:52 +0200 Subject: [PATCH] [#1079]: Option to hide listview elements when not filtered (#1622) * [listview] Optional don't show elements when not filtered (#1079) * [Listview] Fix auto-complete error. --- include/widgets/listview.h | 7 +++++++ source/view.c | 3 +++ source/widgets/listview.c | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/include/widgets/listview.h b/include/widgets/listview.h index 8653f05e..3a10436e 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -267,6 +267,13 @@ void listview_toggle_ellipsizing(listview *lv); */ void listview_set_ellipsize_start(listview *lv); + +/** + * @param lv Handler to the listview object. + * @param filtered boolean indicating if list is filtered. + * + */ +void listview_set_filtered ( listview *lv, gboolean filtered ); /** @} */ #endif // ROFI_LISTVIEW_H diff --git a/source/view.c b/source/view.c index 6aa9504f..b1e267e8 100644 --- a/source/view.c +++ b/source/view.c @@ -1134,6 +1134,8 @@ static gboolean rofi_view_refilter_real(RofiViewState *state) { } TICK_N("Filter tokenize"); if (state->text && strlen(state->text->text) > 0) { + + listview_set_filtered(state->list_view, TRUE); unsigned int j = 0; gchar *pattern = mode_preprocess_input(state->sw, state->text->text); glong plen = pattern ? g_utf8_strlen(pattern, -1) : 0; @@ -1199,6 +1201,7 @@ static gboolean rofi_view_refilter_real(RofiViewState *state) { state->filtered_lines = j; g_free(pattern); } else { + listview_set_filtered(state->list_view, FALSE); for (unsigned int i = 0; i < state->num_lines; i++) { state->line_map[i] = i; } diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 7e07341c..ef57972a 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -98,6 +98,9 @@ struct _listview { unsigned int dynamic; unsigned int eh; unsigned int reverse; + gboolean require_input; + gboolean filtered; + gboolean cycle; gboolean multi_select; @@ -559,6 +562,9 @@ void listview_set_num_elements(listview *lv, unsigned int rows) { } TICK_N("listview_set_num_elements"); lv->req_elements = rows; + if ( lv->require_input && !lv->filtered ) { + lv->req_elements = 0; + } listview_set_selected(lv, lv->selected); TICK_N("Set selected"); listview_recompute_elements(lv); @@ -748,6 +754,8 @@ listview *listview_create(widget *parent, const char *name, lv->fixed_columns = rofi_theme_get_boolean(WIDGET(lv), "fixed-columns", FALSE); + lv->require_input = + rofi_theme_get_boolean(WIDGET(lv), "require-input", FALSE); lv->type = rofi_theme_get_orientation(WIDGET(lv), "layout", ROFI_ORIENTATION_VERTICAL); if (lv->type == LISTVIEW) { @@ -1081,3 +1089,10 @@ void listview_toggle_ellipsizing(listview *lv) { } } } + +void listview_set_filtered ( listview *lv, gboolean filtered ) +{ + if ( lv ) { + lv->filtered = filtered; + } +}