From 5c393fb4120e842d609e6d4366b1e0b822f66d7f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 8 Apr 2023 21:14:20 +0200 Subject: [PATCH] [DRun] Add option to scan desktop for desktop files --- doc/rofi.1 | 4 +++- doc/rofi.1.markdown | 4 +++- source/modes/drun.c | 22 +++++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/doc/rofi.1 b/doc/rofi.1 index e4391873..832f5ff9 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -1437,7 +1437,7 @@ See the debugging section for more info on DRUN mode, this will print why desktop files are discarded. .PP -There are two advanced options to tweak the behaviour: +There are a few advanced options to tweak the behaviour: .PP .RS @@ -1445,6 +1445,8 @@ There are two advanced options to tweak the behaviour: .nf configuration { drun { + /** Scan the current users desktop for desktop files. */ + scan-desktop: true; /** Parse user desktop files. */ parse-user: true; /** Parse system desktop files. */ diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index 052452d5..6801c102 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -961,11 +961,13 @@ applications create invalid desktop files, **rofi** will discard these entries. See the debugging section for more info on DRUN mode, this will print why desktop files are discarded. -There are two advanced options to tweak the behaviour: +There are a few advanced options to tweak the behaviour: ```css configuration { drun { + /** Scan the current users desktop for desktop files. */ + scan-desktop: true; /** Parse user desktop files. */ parse-user: true; /** Parse system desktop files. */ diff --git a/source/modes/drun.c b/source/modes/drun.c index 3e82561b..f8fda7e0 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -712,7 +712,7 @@ static void read_desktop_file(DRunModePrivateData *pd, const char *root, * Internal spider used to get list of executables. */ static void walk_dir(DRunModePrivateData *pd, const char *root, - const char *dirname) { + const char *dirname, const gboolean recursive) { DIR *dir; g_debug("Checking directory %s for desktop files.", dirname); @@ -760,7 +760,9 @@ static void walk_dir(DRunModePrivateData *pd, const char *root, } break; case DT_DIR: - walk_dir(pd, root, filename); + if (recursive) { + walk_dir(pd, root, filename, recursive); + } break; default: break; @@ -1007,13 +1009,23 @@ static void get_apps(DRunModePrivateData *pd) { if (drun_read_cache(pd, cache_file)) { ThemeWidget *wid = rofi_config_find_widget(drun_mode.name, NULL, TRUE); + /** Load desktop entries */ + Property *p = + rofi_theme_find_property(wid, P_BOOLEAN, "scan-desktop", FALSE); + if (p != NULL && (p->type == P_BOOLEAN && p->value.b)) { + const gchar *dir; + // First read the user directory. + dir = g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP); + walk_dir(pd, dir, dir, FALSE); + TICK_N("Get Desktop dir apps"); + } /** Load user entires */ - Property *p = rofi_theme_find_property(wid, P_BOOLEAN, "parse-user", TRUE); + p = rofi_theme_find_property(wid, P_BOOLEAN, "parse-user", TRUE); if (p == NULL || (p->type == P_BOOLEAN && p->value.b)) { gchar *dir; // First read the user directory. dir = g_build_filename(g_get_user_data_dir(), "applications", NULL); - walk_dir(pd, dir, dir); + walk_dir(pd, dir, dir, TRUE); g_free(dir); TICK_N("Get Desktop apps (user dir)"); } @@ -1034,7 +1046,7 @@ static void get_apps(DRunModePrivateData *pd) { // Check, we seem to be getting empty string... if (unique && (**iter) != '\0') { char *dir = g_build_filename(*iter, "applications", NULL); - walk_dir(pd, dir, dir); + walk_dir(pd, dir, dir, TRUE); g_free(dir); } }