From 5de38cd7558711ab5ca90452e85bed6f8a08f8e8 Mon Sep 17 00:00:00 2001 From: QC Date: Fri, 2 Oct 2015 20:39:57 +0200 Subject: [PATCH] Add glob version for testing. --- config/config.def.c | 3 ++- include/rofi.h | 1 + source/dialogs/dmenu.c | 8 +++++--- source/helper.c | 19 ++++++++++++++++++- source/xrmoptions.c | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/config/config.def.c b/config/config.def.c index 1afcd483..d25be080 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -129,7 +129,8 @@ Settings config = { /** Modi to combine into one view. */ .combi_modi = "window,run", /** Fuzzy matching. */ - .fuzzy = FALSE, + .fuzzy = FALSE, + .glob = FALSE, /** Monitor */ .monitor = -1, /** set line margin */ diff --git a/include/rofi.h b/include/rofi.h index bf7ee333..dc28bf99 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -230,6 +230,7 @@ typedef struct _Settings char *combi_modi; /** Fuzzy match */ unsigned int fuzzy; + unsigned int glob; /** Monitors */ int monitor; /** Line margin */ diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 1ef5eb2d..3be7a97d 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -59,8 +59,9 @@ typedef struct _DmenuModePrivateData static char **get_dmenu ( unsigned int *length ) { - char buffer[1024]; - char **retv = NULL; + GTimer *t = g_timer_new (); + char buffer[1024]; + char **retv = NULL; *length = 0; @@ -80,7 +81,8 @@ static char **get_dmenu ( unsigned int *length ) return retv; } } - + g_timer_stop ( t ); + printf ( "%.4f\n", g_timer_elapsed ( t, NULL ) ); return retv; } diff --git a/source/helper.c b/source/helper.c index 94b90a28..18270e9c 100644 --- a/source/helper.c +++ b/source/helper.c @@ -345,11 +345,28 @@ static int normal_token_match ( char **tokens, const char *input, int case_sensi g_free ( compk ); return match; } +static int glob_token_match ( char **tokens, const char *input, int case_sensitive ) +{ + int match = 1; + char *compk = token_collate_key ( input, case_sensitive ); + + // Do a tokenized match. + if ( tokens ) { + for ( int j = 0; match && tokens[j]; j++ ) { + match = g_pattern_match_simple ( tokens[j], compk ); + } + } + g_free ( compk ); + return match; +} int token_match ( char **tokens, const char *input, int case_sensitive, __attribute__( ( unused ) ) unsigned int index, __attribute__( ( unused ) ) Switcher *data ) { - if ( config.fuzzy ) { + if ( config.glob ) { + return glob_token_match ( tokens, input, case_sensitive ); + } + else if ( config.fuzzy ) { return fuzzy_token_match ( tokens, input, case_sensitive ); } return normal_token_match ( tokens, input, case_sensitive ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index ffd05115..9422c861 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -122,6 +122,7 @@ static XrmOption xrmOptions[] = { { xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL }, { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL }, { xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL }, + { xrm_Boolean, "glob", { .num = &config.glob }, NULL }, { xrm_Number, "monitor", { .snum = &config.monitor }, NULL }, /* Alias for dmenu compatibility. */ { xrm_SNumber, "m", { .snum = &config.monitor }, NULL },