From 89d2190f8eadb98493ec04856f3d740188738b32 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 7 May 2015 21:07:15 +0200 Subject: [PATCH] [#158] Patch implementing -only-match mode. --- doc/rofi-manpage.markdown | 5 +++++ source/dialogs/dmenu.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 0f156e96..432ff985 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -507,6 +507,11 @@ The following options are further explained in the theming section: or a set of rows: -u 0,2 Or any combination: -u 0,2-3,9 +`-only-match` + + Only return a selected item, do not allow custom entry. + This mode always returns an entry, or returns directly when no entries given. + ### Message dialog `-e` *message* diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 151f38e7..3a983038 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -157,10 +157,39 @@ int dmenu_switcher_dialog ( char **input ) parse_ranges ( str, &active_list, &num_active_list ); } + int only_selected = FALSE; + if ( find_arg ( "-only-match" ) >= 0 ) { + only_selected = TRUE; + if ( length == 0 ) { + return TRUE; + } + } + do { int next_pos = selected_line; int mretv = menu ( list, length, input, dmenu_prompt, token_match, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos ); + // Special behavior. + if ( only_selected ) { + restart = TRUE; + if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) { + if ( number_mode ) { + fprintf ( stdout, "%d", selected_line ); + } + else { + fputs ( list[selected_line], stdout ); + } + retv = TRUE; + if ( ( mretv & MENU_QUICK_SWITCH ) ) { + retv = 10 + ( mretv & MENU_LOWER_MASK ); + } + fputc ( '\n', stdout ); + fflush ( stdout ); + return retv; + } + selected_line = next_pos - 1; + continue; + } // We normally do not want to restart the loop. restart = FALSE; if ( ( mretv & MENU_OK ) && list[selected_line] != NULL ) {