diff --git a/config/config.c b/config/config.c index 2d2347a5c..1b9bccaca 100644 --- a/config/config.c +++ b/config/config.c @@ -128,6 +128,8 @@ Settings config = { .drun_match_fields = "name,generic,exec,categories,keywords", /** Only show entries in this category */ .drun_categories = NULL, + /** Exclude entries in this category */ + .drun_exclude_categories = NULL, /** Desktop entry show actions */ .drun_show_actions = FALSE, /** Desktop format display */ diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index 28be15fb3..3847cde8b 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -374,6 +374,10 @@ Tokenize the input. Only show desktop files that are present in the listed categories. +`-drun-exclude-categories` *category1*,*category2* + +Exclude desktop files that are present in the listed categories. + `-drun-match-fields` *field1*,*field2*,... When using `drun`, match only with the specified Desktop entry fields. diff --git a/include/settings.h b/include/settings.h index a958b4784..971841f4e 100644 --- a/include/settings.h +++ b/include/settings.h @@ -119,6 +119,8 @@ typedef struct { char *drun_match_fields; /** Only show entries in this category */ char *drun_categories; + /** Exclude entries in this category */ + char *drun_exclude_categories; /** Desktop entry show actions */ unsigned int drun_show_actions; /** Desktop format display */ diff --git a/source/modes/drun.c b/source/modes/drun.c index 02454bc5f..4b146fb9b 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -215,6 +215,7 @@ struct _DRunModePrivateData { unsigned int expected_line_height; char **show_categories; + char **exclude_categories; // Theme const gchar *icon_theme; @@ -722,6 +723,19 @@ static void read_desktop_file(DRunModePrivateData *pd, const char *root, } } + if (pd->exclude_categories) { + if (categories == NULL) { + categories = g_key_file_get_locale_string_list( + kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL); + } + if (rofi_strv_contains((const char *const *)categories, + (const char *const *)pd->exclude_categories)) { + g_strfreev(categories); + g_key_file_free(kf); + return; + } + } + size_t nl = ((pd->cmd_list_length) + 1); if (nl >= pd->cmd_list_length_actual) { pd->cmd_list_length_actual += 256; @@ -1320,6 +1334,10 @@ static int drun_mode_init(Mode *sw) { pd->show_categories = g_strsplit(config.drun_categories, ",", 0); } + if (config.drun_exclude_categories && *(config.drun_exclude_categories)) { + pd->exclude_categories = g_strsplit(config.drun_exclude_categories, ",", 0); + } + drun_mode_parse_entry_fields(); drun_mode_parse_display_format(); get_apps(pd); @@ -1473,6 +1491,7 @@ static void drun_mode_destroy(Mode *sw) { g_strfreev(rmpd->current_desktop_list); g_strfreev(rmpd->show_categories); + g_strfreev(rmpd->exclude_categories); g_free(rmpd); mode_set_private_data(sw, NULL); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index e4cbe4afd..692124f90 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -241,6 +241,12 @@ static XrmOption xrmOptions[] = { NULL, "Only show Desktop entry from these categories", CONFIG_DEFAULT}, + {xrm_String, + "drun-exclude-categories", + {.str = &config.drun_exclude_categories}, + NULL, + "Exclude Desktop entries from these categories", + CONFIG_DEFAULT}, {xrm_Boolean, "drun-show-actions", {.num = &config.drun_show_actions},