diff --git a/config/config.c b/config/config.c index 78956116..6523e97c 100644 --- a/config/config.c +++ b/config/config.c @@ -62,19 +62,20 @@ Settings config = { .i3_mode = 0, #endif // Key binding - .window_key = "F12", - .run_key = "mod1+F2", - .ssh_key = "mod1+F3", + .window_key = "F12", + .run_key = "mod1+F2", + .ssh_key = "mod1+F3", // Location of the window. WL_CENTER, WL_NORTH_WEST, WL_NORTH,WL_NORTH_EAST, etc. .location = WL_CENTER, // Mode of window, list (Vertical) or dmenu like (Horizontal) .hmode = FALSE, // Padding of the window. - .padding = 5, - .ssh_set_title = TRUE, - .y_offset = 0, - .x_offset = 0, - .fixed_num_lines = FALSE, - .disable_history = FALSE + .padding = 5, + .ssh_set_title = TRUE, + .y_offset = 0, + .x_offset = 0, + .fixed_num_lines = FALSE, + .disable_history = FALSE, + .levenshtein_sort = FALSE }; diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 6c4279e3..d1a3599b 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -14,7 +14,7 @@ SYNOPSIS [ -terminal *terminal* ] [ -loc *position* ] [ -hmode ] [ -fixed-num-lines ] [ -padding *padding* ] [ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ] [ -dmenu [ -p *prompt* ] ] [ -ssh-set-title *true|false* ] [ -now ] [ -rnow ] [ -snow ] [ -version ] [ -help] [ -dump-xresources ] -[ -disable-history ] +[ -disable-history ] [ -levenshtein-sort ] DESCRIPTION ----------- @@ -215,6 +215,10 @@ OPTIONS Disable history +`-levenshtein-sort` + + When searching sort the result based on levenshtein distance. + Switch between modi ------------------- diff --git a/include/rofi.h b/include/rofi.h index 00a96f01..bc962219 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -135,6 +135,8 @@ typedef struct _Settings unsigned int fixed_num_lines; unsigned int disable_history; + + unsigned int levenshtein_sort; } Settings; extern Settings config; diff --git a/source/rofi.c b/source/rofi.c index 36f20b9d..b0c5bbb9 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1095,7 +1095,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi char **filtered = calloc ( num_lines, sizeof ( char* ) ); int *line_map = calloc ( num_lines, sizeof ( int ) ); int *distance = NULL; - if ( config.disable_history ) { + if ( config.levenshtein_sort ) { distance = calloc ( num_lines, sizeof ( int ) ); } unsigned int filtered_lines = 0; @@ -1110,13 +1110,13 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi // If each token was matched, add it to list. if ( match ) { line_map[j] = i; - if ( config.disable_history ) { + if ( config.levenshtein_sort ) { distance[i] = levenshtein ( *input, lines[i] ); } j++; } } - if ( config.disable_history ) { + if ( config.levenshtein_sort ) { qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance ); } for ( i = 0; i < j; i++ ) { @@ -1441,13 +1441,13 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi // If each token was matched, add it to list. if ( match ) { line_map[j] = i; - if ( config.disable_history ) { + if ( config.levenshtein_sort ) { distance[i] = levenshtein ( text->text, lines[i] ); } j++; } } - if ( config.disable_history ) { + if ( config.levenshtein_sort ) { qsort_r ( line_map, j, sizeof ( int ), lev_sort, distance ); } for ( i = 0; i < j; i++ ) { @@ -1901,6 +1901,9 @@ static void parse_cmd_options ( int argc, char ** argv ) if ( find_arg ( argc, argv, "-disable-history" ) >= 0 ) { config.disable_history = TRUE; } + if ( find_arg ( argc, argv, "-levenshtein-sort" ) >= 0 ) { + config.levenshtein_sort = TRUE; + } // Parse commandline arguments about behavior find_arg_str ( argc, argv, "-terminal", &( config.terminal_emulator ) ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 01be247e..093ac86a 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -99,6 +99,7 @@ static XrmOption xrmOptions[] = { { xrm_Boolean, "ssh-set-title", { .num = &config.ssh_set_title }, NULL }, { xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL }, + { xrm_Boolean, "levenshtein-sort",{ .num = &config.levenshtein_sort }, NULL }, /* Key bindings */ { xrm_String, "key", { .str = &config.window_key }, NULL }, { xrm_String, "rkey", { .str = &config.run_key }, NULL },