diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index fbe6bae8..168f6491 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -426,8 +426,6 @@ The following options are further explained in the theming section: When searching sort the result based on levenshtein distance. - Note that levenshtein sort is disabled in dmenu mode. - ### Dmenu specific `-sep` *separator* diff --git a/doc/rofi.1 b/doc/rofi.1 index 303f3454..bb7decd2 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -90,7 +90,8 @@ Keybindings can also be specified in the \fB\fCXresources\fR file. \fBrofi\fP can emulate \fB\fCdmenu\fR (a dynamic menu for X) when launched with the \fB\fC\-dmenu\fR flag. .PP The official website for \fB\fCdmenu\fR can be found: -\[la]http://tools.suckless.org/dmenu/\[ra] +.UR http://tools.suckless.org/dmenu/ +.UE .SH OPTIONS .PP \fB\fC\-key\-{mode}\fR \fBKEY\fP @@ -531,8 +532,6 @@ Disable history \fB\fC\-levenshtein\-sort\fR .IP When searching sort the result based on levenshtein distance. -.IP -Note that levenshtein sort is disabled in dmenu mode. .SS Dmenu specific .PP \fB\fC\-sep\fR \fIseparator\fP @@ -810,14 +809,18 @@ Check quotes used on the commandline: e.g. used “ instead of ". .SH WEBSITE .PP \fBrofi\fP website can be found at here -\[la]https://davedavenport.github.io/rofi/\[ra] +.UR https://davedavenport.github.io/rofi/ +.UE .PP \fBrofi\fP bugtracker can be found here -\[la]https://github.com/DaveDavenport/rofi/issues\[ra] +.UR https://github.com/DaveDavenport/rofi/issues +.UE .SH AUTHOR .PP Qball Cow -\[la]qball@gmpclient.org\[ra] +.MT qball@gmpclient.org +.ME .PP Original code based on work by: Sean Pringle -\[la]sean.pringle@gmail.com\[ra] +.MT sean.pringle@gmail.com +.ME diff --git a/include/rofi.h b/include/rofi.h index 593214f1..8f7ff651 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -91,8 +91,9 @@ typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensi * @returns The command issued (see MenuReturn) */ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prompt, - menu_match_cb mmc, void *mmc_data, - int *selected_line, int sorting, get_display_value mgrv, void *mgrv_data ) __attribute__ ( ( nonnull ( 1, 3, 4, 7 ) ) ); + menu_match_cb mmc, void *mmc_data, int *selected_line, int sorting, + get_display_value mgrv, void *mgrv_data, int *next_pos ) __attribute__ ( ( nonnull ( 1, 3, + 4, 7 ) ) ); /** * @param sig The caught signal * diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index d8a70192..059ab914 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -158,9 +158,9 @@ int dmenu_switcher_dialog ( char **input ) } do { - int mretv = menu ( list, length, input, dmenu_prompt, - token_match, NULL, &selected_line, FALSE, get_display_data, list ); - + 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 ); // We normally do not want to restart the loop. restart = FALSE; if ( ( mretv & MENU_OK ) && list[selected_line] != NULL ) { @@ -175,7 +175,7 @@ int dmenu_switcher_dialog ( char **input ) if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. - selected_line = MIN ( selected_line + 1, length - 1 ); + selected_line = MIN ( next_pos, length - 1 ); } retv = TRUE; } @@ -188,7 +188,7 @@ int dmenu_switcher_dialog ( char **input ) if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. - selected_line = MIN ( selected_line + 1, length - 1 ); + selected_line = MIN ( next_pos, length - 1 ); } retv = TRUE; } diff --git a/source/rofi.c b/source/rofi.c index 16ebdda3..8dd321c0 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -311,7 +311,6 @@ typedef struct MenuState Time last_button_press; int quit; - int init; // Return state int *selected_line; MenuReturn retv; @@ -734,16 +733,6 @@ static void menu_refilter ( MenuState *state, char **lines, menu_match_cb mmc, v if ( sorting ) { state->distance[i] = levenshtein ( state->text->text, lines[i] ); } - // Try to look-up the selected line and highlight that. - // This is needed 'hack' to fix the dmenu 'next row' modi. - // int to unsigned int is valid because we check negativeness of - // selected_line - if ( state->init == TRUE && ( state->selected_line ) != NULL && - ( *( state->selected_line ) ) >= 0 && - ( (unsigned int) ( *( state->selected_line ) ) ) == i ) { - state->selected = j; - state->init = FALSE; - } j++; } } @@ -917,7 +906,7 @@ static void menu_paste ( MenuState *state, XSelectionEvent *xse ) MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prompt, menu_match_cb mmc, void *mmc_data, int *selected_line, int sorting, - get_display_value mgrv, void *mgrv_data ) + get_display_value mgrv, void *mgrv_data, int *next_pos ) { int shift = FALSE; MenuState state = { @@ -928,7 +917,6 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom .last_offset = 0, .num_lines = num_lines, .distance = NULL, - .init = TRUE, .quit = FALSE, .filtered_lines = 0, .max_elements = 0, @@ -942,7 +930,10 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom .mgrv_data = mgrv_data }; unsigned int i; - workarea mon; + if ( next_pos ) { + *next_pos = *selected_line; + } + workarea mon; // main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker XWindowAttributes attr; @@ -1258,6 +1249,10 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom g_free ( *input ); *input = g_strdup ( state.text->text ); + if ( next_pos ) { + *( next_pos ) = state.selected + 1; + } + int retv = state.retv; menu_free_state ( &state ); @@ -1287,7 +1282,6 @@ void error_dialog ( const char *msg ) .last_offset = 0, .num_lines = 0, .distance = NULL, - .init = FALSE, .quit = FALSE, .filtered_lines = 0, .columns = 0, @@ -1856,7 +1850,7 @@ SwitcherMode switcher_run ( char **input, Switcher *sw ) &selected_line, config.levenshtein_sort, sw->mgrv, - sw ); + sw, NULL ); SwitcherMode retv = sw->result ( mretv, input, selected_line, sw );