summaryrefslogtreecommitdiffstats
path: root/source/dialogs/drun.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/dialogs/drun.c')
-rw-r--r--source/dialogs/drun.c97
1 files changed, 83 insertions, 14 deletions
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index 33ce69f8..87efdd54 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -92,6 +92,28 @@ typedef struct
typedef struct
{
+ const char *entry_field_name;
+ gboolean enabled;
+} DRunEntryField;
+
+typedef enum
+{
+ DRUN_MATCH_FIELD_NAME,
+ DRUN_MATCH_FIELD_GENERIC,
+ DRUN_MATCH_FIELD_EXEC,
+ DRUN_MATCH_FIELD_CATEGORIES,
+ DRUN_MATCH_NUM_FIELDS,
+} DRunMatchingFields;
+
+static DRunEntryField matching_entry_fields[DRUN_MATCH_NUM_FIELDS] = {
+ { .entry_field_name = "name", .enabled = TRUE, },
+ { .entry_field_name = "generic", .enabled = TRUE, },
+ { .entry_field_name = "exec", .enabled = TRUE, },
+ { .entry_field_name = "categories", .enabled = TRUE, }
+};
+
+typedef struct
+{
NkXdgThemeContext *xdg_context;
DRunModeEntry *entry_list;
unsigned int cmd_list_length;
@@ -100,9 +122,9 @@ typedef struct
GHashTable *disabled_entries;
unsigned int disabled_entries_length;
GThreadPool *pool;
-
unsigned int expected_line_height;
DRunModeEntry quit_entry;
+
// Theme
const gchar *icon_theme;
} DRunModePrivateData;
@@ -112,6 +134,7 @@ struct RegexEvalArg
DRunModeEntry *e;
gboolean success;
};
+
static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpointer data )
{
// TODO quoting is not right? Find description not very clear, need to check.
@@ -554,6 +577,42 @@ static void drun_icon_fetch ( gpointer data, gpointer user_data )
rofi_view_reload ();
}
+static void drun_mode_parse_entry_fields ()
+{
+ char *savept = NULL;
+ // Make a copy, as strtok will modify it.
+ char *switcher_str = g_strdup ( config.drun_match_fields );
+ const char * const sep = ",#";
+ // Split token on ','. This modifies switcher_str.
+ for ( unsigned int i = 0; i < DRUN_MATCH_NUM_FIELDS; i++ ) {
+ matching_entry_fields[i].enabled = FALSE;
+ }
+ for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL;
+ token = strtok_r ( NULL, sep, &savept ) ) {
+ if ( strcmp ( token, "all" ) == 0 ) {
+ for ( unsigned int i = 0; i < DRUN_MATCH_NUM_FIELDS; i++ ) {
+ matching_entry_fields[i].enabled = TRUE;
+ }
+ break;
+ }
+ else {
+ gboolean matched = FALSE;
+ for ( unsigned int i = 0; i < DRUN_MATCH_NUM_FIELDS; i++ ) {
+ const char * entry_name = matching_entry_fields[i].entry_field_name;
+ if ( strcmp ( token, entry_name ) == 0 ) {
+ matching_entry_fields[i].enabled = TRUE;
+ matched = TRUE;
+ }
+ }
+ if ( !matched ) {
+ g_warning ( "Invalid entry name :%s", token );
+ }
+ }
+ }
+ // Free string that was modified by strtok_r
+ g_free ( switcher_str );
+}
+
static int drun_mode_init ( Mode *sw )
{
if ( mode_get_private_data ( sw ) == NULL ) {
@@ -572,6 +631,7 @@ static int drun_mode_init ( Mode *sw )
pd->xdg_context = nk_xdg_theme_context_new ( drun_icon_fallback_themes, NULL );
nk_xdg_theme_preload_themes_icon ( pd->xdg_context, themes );
get_apps ( pd );
+ drun_mode_parse_entry_fields ();
}
return TRUE;
}
@@ -713,22 +773,30 @@ static int drun_token_match ( const Mode *data, rofi_int_matcher **tokens, unsig
int test = 0;
rofi_int_matcher *ftokens[2] = { tokens[j], NULL };
// Match name
- if ( rmpd->entry_list[index].name ) {
- test = helper_token_match ( ftokens, rmpd->entry_list[index].name );
+ if ( matching_entry_fields[DRUN_MATCH_FIELD_NAME].enabled ) {
+ if ( rmpd->entry_list[index].name ) {
+ test = helper_token_match ( ftokens, rmpd->entry_list[index].name );
+ }
}
- // Match generic name
- if ( test == tokens[j]->invert && rmpd->entry_list[index].generic_name ) {
- test = helper_token_match ( ftokens, rmpd->entry_list[index].generic_name );
+ if ( matching_entry_fields[DRUN_MATCH_FIELD_GENERIC].enabled ) {
+ // Match generic name
+ if ( test == tokens[j]->invert && rmpd->entry_list[index].generic_name ) {
+ test = helper_token_match ( ftokens, rmpd->entry_list[index].generic_name );
+ }
}
- // Match executable name.
- if ( test == tokens[j]->invert ) {
- test = helper_token_match ( ftokens, rmpd->entry_list[index].exec );
+ if ( matching_entry_fields[DRUN_MATCH_FIELD_EXEC].enabled ) {
+ // Match executable name.
+ if ( test == tokens[j]->invert ) {
+ test = helper_token_match ( ftokens, rmpd->entry_list[index].exec );
+ }
}
- // Match against category.
- if ( test == tokens[j]->invert ) {
- gchar **list = rmpd->entry_list[index].categories;
- for ( int iter = 0; test == tokens[j]->invert && list && list[iter]; iter++ ) {
- test = helper_token_match ( ftokens, list[iter] );
+ if ( matching_entry_fields[DRUN_MATCH_FIELD_CATEGORIES].enabled ) {
+ // Match against category.
+ if ( test == tokens[j]->invert ) {
+ gchar **list = rmpd->entry_list[index].categories;
+ for ( int iter = 0; test == tokens[j]->invert && list && list[iter]; iter++ ) {
+ test = helper_token_match ( ftokens, list[iter] );
+ }
}
}
if ( test == 0 ) {
@@ -736,6 +804,7 @@ static int drun_token_match ( const Mode *data, rofi_int_matcher **tokens, unsig
}
}
}
+
return match;
}