diff --git a/config/config.c b/config/config.c index 56845381..ecb1e2fe 100644 --- a/config/config.c +++ b/config/config.c @@ -94,7 +94,7 @@ Settings config = { /** Sort the displayed list */ .sort = FALSE, /** Use levenshtein sorting when matching */ - .levenshtein_sort = FALSE, + .sorting_method = SORT_NORMAL, /** Case sensitivity of the search */ .case_sensitive = FALSE, /** Cycle through in the element list */ diff --git a/doc/rofi-theme-selector.1 b/doc/rofi-theme-selector.1 index 73012322..eec5302a 100644 --- a/doc/rofi-theme-selector.1 +++ b/doc/rofi-theme-selector.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ROFI\-THEME\-SELECTOR" "1" "December 2017" "" "" +.TH "ROFI\-THEME\-SELECTOR" "1" "June 2018" "" "" . .SH "NAME" \fBrofi\-theme\-selector\fR \- Preview and apply themes for \fBrofi\fR diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index 0f8a34b2..fe5e894b 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ROFI\-THEME" "5" "February 2018" "" "" +.TH "ROFI\-THEME" "5" "June 2018" "" "" . .SH "NAME" \fBrofi\-theme\fR \- Rofi theme format files @@ -888,7 +888,7 @@ nametotextbox selected\.active { .IP "" 0 . .P -Sets all selected textboxes marked active to the given foreground and background color\. Note that a state modifies the original element, it therefore contains all the properties of that element\. +Sets all selected textboxes marked active to the given text and background color\. Note that a state modifies the original element, it therefore contains all the properties of that element\. . .SS "Scrollbar" The scrollbar uses the \fBhandle\fR state when drawing the small scrollbar handle\. This allows the colors used for drawing the handle to be set independently\. @@ -911,10 +911,10 @@ The following properties are currently supported: \fBborder\-radius\fR: padding Sets a radius on the corners of the borders\. . .IP "\(bu" 4 -\fBbackground\fR: color Background color +\fBbackground\-color\fR: color Background color . .IP "\(bu" 4 -\fBforeground\fR: color Foreground color +\fBborder\-color\fR: color Color of the border . .IP "\(bu" 4 \fBindex\fR: integer (This one does not inherit it value from the parent widget) @@ -927,7 +927,7 @@ The following properties are currently supported: \fBfont\fR: string The font used in the window . .IP "\(bu" 4 -\fBtransparency\fR: string Indicating if transparency should be used and what type: \fBreal\fR \- True transparency\. Only works with a compositor\. \fBbackground\fR \- Take a screenshot of the background image and use that\. \fBscreenshot\fR \- Take a screenshot of the screen and use that\. \fBPath\fR to png file \- Use an image\. +\fBtransparency\fR: string Indicating if transparency should be used and what type: \fBreal\fR \- True transparency\. Only works with a compositor\. \fBbackground\-color\fR \- Take a screenshot of the background image and use that\. \fBscreenshot\fR \- Take a screenshot of the screen and use that\. \fBPath\fR to png file \- Use an image\. . .IP "\(bu" 4 \fBlocation\fR: position The place of the anchor on the monitor @@ -978,10 +978,10 @@ The following properties are currently supported: .SS "textbox:" . .IP "\(bu" 4 -\fBbackground\fR: color +\fBbackground\-color\fR: color . .IP "\(bu" 4 -\fBforeground\fR: color +\fBborder\-color\fR: the color used for the border around the widget\. . .IP "\(bu" 4 \fBfont\fR: the font used by this textbox (string) @@ -996,7 +996,7 @@ The following properties are currently supported: \fBhorizontal\-align\fR: horizontal alignment of the text (\fB0\fR left, \fB1\fR right) . .IP "\(bu" 4 -\fBtext\fR: the text color to use (falls back to foreground if not set) +\fBtext\-color\fR: the text color to use . .IP "\(bu" 4 \fBhighlight\fR: text style {color} color is optional, multiple highlight styles can be added like: bold underline italic #000000; @@ -1221,7 +1221,7 @@ Content \- The content of the widget\. Padding \- Clears an area around the widget\. The padding shows the background color of the widget\. . .IP "\(bu" 4 -Border \- A border that goes around the padding and content\. The border use the foreground color of the widget\. +Border \- A border that goes around the padding and content\. The border use the border\-color of the widget\. . .IP "\(bu" 4 Margin \- Clears an area outside the border\. The margin is transparent\. diff --git a/doc/rofi.1 b/doc/rofi.1 index a650073f..f88c98aa 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ROFI" "1" "December 2017" "" "" +.TH "ROFI" "1" "June 2018" "" "" . .SH "NAME" \fBrofi\fR \- A window switcher, application launcher, ssh dialog and dmenu replacement @@ -347,10 +347,10 @@ Specify the directory where \fBrofi\fR should look for plugins\. Show application icons in drun and window modes\. . .P -\fB\-drun\-icon\-theme\fR +\fB\-icon\-theme\fR . .P -Specify icon theme to be used in drun mode if show\-icons setting is enabled\. If not specified default theme from DE is used, \fIAdwaita\fR and \fIgnome\fR themes act as fallback themes\. +Specify icon theme to be used\. If not specified default theme from DE is used, \fIAdwaita\fR and \fIgnome\fR themes act as fallback themes\. . .SS "Matching" \fB\-matching\fR \fImethod\fR @@ -825,13 +825,18 @@ Disable history Enable, disable sorting\. This setting can be changed at runtime (see \fB\-kb\-toggle\-sort\fR)\. . .P -\fB\-levenshtein\-sort\fR to enable \fB\-no\-levenshtein\-sort\fR to disable +\fB\-sort\-method\fR \'method\' to specify the sorting method\. . .P -When searching, always sort the result based on levenshtein distance\. If disabled, fzf sorting is used when fuzzy matching is used\. If enabled, levenshtein sorting is used event fuzzy matching is used\. +There are 2 sorting method: . -.P -For other matching modes sorting is always done via levenshtein\-sort\. +.IP "\(bu" 4 +levenshtein (Default) +. +.IP "\(bu" 4 +fzf sorting\. +. +.IP "" 0 . .SS "Dmenu specific" \fB\-sep\fR \fIseparator\fR @@ -1345,7 +1350,7 @@ Transparency can be used within \fBrofi\fR, for example if the selected backgrou \fBgrave\fR: Toggle case sensitivity\. . .IP "\(bu" 4 -\fBAlt\-grave\fR: Toggle levenshtein sorting\. +\fBAlt\-grave\fR: Toggle sorting\. . .IP "\(bu" 4 \fBAlt\-Shift\-S\fR: Take a screenshot and store it in the Pictures directory\. diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index b1a1984b..7fa5574e 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -491,14 +491,13 @@ Disable history Enable, disable sorting. This setting can be changed at runtime (see `-kb-toggle-sort`). -`-levenshtein-sort` to enable -`-no-levenshtein-sort` to disable +`-sort-method` 'method' to specify the sorting method. -When searching, always sort the result based on levenshtein distance. -If disabled, fzf sorting is used when fuzzy matching is used. -If enabled, levenshtein sorting is used event fuzzy matching is used. +There are 2 sorting method: + + * levenshtein (Default) + * fzf sorting. -For other matching modes sorting is always done via levenshtein-sort. ### Dmenu specific @@ -791,7 +790,7 @@ of the window will be visible through it. * `Ctrl-space`: Set selected item as input text. * `Shift-Del`: Delete entry from history. * `grave`: Toggle case sensitivity. - * `Alt-grave`: Toggle levenshtein sorting. + * `Alt-grave`: Toggle sorting. * `Alt-Shift-S`: Take a screenshot and store it in the Pictures directory. To get a full list of key bindings on the commandline, see `rofi -h`. diff --git a/doc/test_xr.txt b/doc/test_xr.txt index 3c0ee77c..2b3bd585 100644 --- a/doc/test_xr.txt +++ b/doc/test_xr.txt @@ -46,8 +46,8 @@ rofi.window-command: xkill -id {window} rofi.disable-history: false ! "Use sorting" Set from: Default ! rofi.sort: false -! "Use levenshtein sorting also for fuzzy matching" Set from: File -rofi.levenshtein-sort: false +! "Choose the strategy used for sorting: normal (levenshtein) or fzf." Set from: Default +! rofi.sorting-method: ! "Set case-sensitivity" Set from: File rofi.case-sensitive: false ! "Cycle through the results list" Set from: File diff --git a/include/settings.h b/include/settings.h index 66729597..cfd1aaf6 100644 --- a/include/settings.h +++ b/include/settings.h @@ -43,6 +43,12 @@ typedef enum MM_FUZZY = 3 } MatchingMethod; +typedef enum +{ + SORT_NORMAL = 0, + SORT_FZF = 1 +} SortingMethod; + /** * Settings structure holding all (static) configurable options. * @ingroup CONFIGURATION @@ -104,10 +110,12 @@ typedef struct unsigned int disable_history; /** Toggle to enable sorting. */ unsigned int sort; + /** Sorting method. */ + SortingMethod sorting_method_enum; + /** Sorting method. */ + char * sorting_method; /** Desktop entries to match in drun */ char * drun_match_fields; - /** Use levenshtein sorting when matching */ - unsigned int levenshtein_sort; /** Search case sensitivity */ unsigned int case_sensitive; /** Cycle through in the element list */ diff --git a/source/helper.c b/source/helper.c index 55e688db..52922912 100644 --- a/source/helper.c +++ b/source/helper.c @@ -578,6 +578,22 @@ int config_sanity_check ( void ) GString *msg = g_string_new ( "The configuration failed to validate:\n" ); + if ( config.sorting_method ) { + if ( g_strcmp0 ( config.sorting_method, "normal" ) == 0 ) { + config.sorting_method_enum = SORT_NORMAL; + } + else if ( g_strcmp0 ( config.sorting_method, "levenshtein" ) == 0 ) { + config.sorting_method_enum = SORT_NORMAL; + } + else if ( g_strcmp0 ( config.sorting_method, "fzf" ) == 0 ) { + config.sorting_method_enum = SORT_FZF; + } else { + g_string_append_printf ( msg, "\tconfig.sorting_method=%s is not a valid sorting strategy.\nValid options are: normal or fzf.\n", + config.sorting_method ); + found_error = 1; + } + } + if ( config.matching ) { if ( g_strcmp0 ( config.matching, "regex" ) == 0 ) { config.matching_method = MM_REGEX; diff --git a/source/view.c b/source/view.c index 0a67893a..1d8bcdcf 100644 --- a/source/view.c +++ b/source/view.c @@ -607,11 +607,15 @@ static void filter_elements ( thread_state *ts, G_GNUC_UNUSED gpointer user_data // This is inefficient, need to fix it. char * str = mode_get_completion ( t->state->sw, i ); glong slen = g_utf8_strlen ( str, -1 ); - if ( config.levenshtein_sort || config.matching_method != MM_FUZZY ) { - t->state->distance[i] = levenshtein ( t->pattern, t->plen, str, slen ); - } - else { - t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( t->pattern, t->plen, str, slen ); + switch ( config.sorting_method_enum ) + { + case SORT_FZF: + t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( t->pattern, t->plen, str, slen ); + break; + case SORT_NORMAL: + default: + t->state->distance[i] = levenshtein ( t->pattern, t->plen, str, slen ); + break; } g_free ( str ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index e66c78d9..3b07cb8c 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -139,8 +139,8 @@ static XrmOption xrmOptions[] = { "Disable history in run/ssh", CONFIG_DEFAULT }, { xrm_Boolean, "sort", { .num = &config.sort }, NULL, "Use sorting", CONFIG_DEFAULT }, - { xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL, - "Use levenshtein sorting also for fuzzy matching", CONFIG_DEFAULT }, + { xrm_String, "sorting-method", { .str = &config.sorting_method }, NULL, + "Choose the strategy used for sorting: normal (levenshtein) or fzf.", CONFIG_DEFAULT }, { xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, "Set case-sensitivity", CONFIG_DEFAULT }, { xrm_Boolean, "cycle", { .num = &config.cycle }, NULL,