1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-03-10 17:06:37 -04:00

[DRUN] Add option to exclude categories from drun #2102 (#2104)

* Add option to exclude categories from drun

* Fix memory leak when both -drun-categories and -drun-exclude-categories are used

* update docs
This commit is contained in:
J0hannes101 2025-02-21 16:28:21 +01:00 committed by GitHub
parent 8639783f5f
commit a84f04a14b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 0 deletions

View file

@ -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 */

View file

@ -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.

View file

@ -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 */

View file

@ -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);
}

View file

@ -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},