Skip to content

Commit

Permalink
Add option to exclude categories from drun
Browse files Browse the repository at this point in the history
  • Loading branch information
J0hannes101 committed Feb 20, 2025
1 parent 8639783 commit c8c7230
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
17 changes: 17 additions & 0 deletions source/modes/drun.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ struct _DRunModePrivateData {
unsigned int expected_line_height;

char **show_categories;
char **exclude_categories;

// Theme
const gchar *icon_theme;
Expand Down Expand Up @@ -722,6 +723,17 @@ static void read_desktop_file(DRunModePrivateData *pd, const char *root,
}
}

if (pd->exclude_categories) {
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;
Expand Down Expand Up @@ -1320,6 +1332,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);
Expand Down Expand Up @@ -1473,6 +1489,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);
}
Expand Down
6 changes: 6 additions & 0 deletions source/xrmoptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit c8c7230

Please sign in to comment.