[pulseaudio-discuss] [PATCH] modules: support XDG_DATA_DIRS when find desktop files

Iceyer iceyers at gmail.com
Tue Oct 31 03:46:40 UTC 2017


---
 src/modules/module-augment-properties.c | 63 +++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/src/modules/module-augment-properties.c b/src/modules/module-augment-properties.c
index 541f0e79..56217d51 100644
--- a/src/modules/module-augment-properties.c
+++ b/src/modules/module-augment-properties.c
@@ -144,37 +144,54 @@ static void update_rule(struct rule *r) {
         { NULL, NULL, NULL, NULL },
     };
     bool found = false;
+    const char *state = NULL;
+    const char *xdg_data_dirs = NULL;
+    char *data_dir = NULL;
+    char *desktop_file_dir = NULL;
 
     pa_assert(r);
-    fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s.desktop", r->process_name);
 
-    if (stat(fn, &st) == 0)
-        found = true;
-    else {
+    if ((xdg_data_dirs = getenv("XDG_DATA_DIRS"))) {
+      while(data_dir = pa_split(xdg_data_dirs, ":", &state)) {
+        desktop_file_dir = pa_sprintf_malloc("%s" PA_PATH_SEP "applications", data_dir);
+        fn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s.desktop", desktop_file_dir, r->process_name);
+        if (stat(fn, &st) == 0) {
+            found = true;
+            break;
+        } else {
 #ifdef DT_DIR
-        DIR *desktopfiles_dir;
-        struct dirent *dir;
-
-        /* Let's try a more aggressive search, but only one level */
-        if ((desktopfiles_dir = opendir(DESKTOPFILEDIR))) {
-            while ((dir = readdir(desktopfiles_dir))) {
-                if (dir->d_type != DT_DIR
-                    || pa_streq(dir->d_name, ".")
-                    || pa_streq(dir->d_name, ".."))
-                    continue;
-
-                pa_xfree(fn);
-                fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", dir->d_name, r->process_name);
-
-                if (stat(fn, &st) == 0) {
-                    found = true;
-                    break;
+            DIR *desktopfiles_dir;
+            struct dirent *dir;
+
+            /* Let's try a more aggressive search, but only one level */
+            if ((desktopfiles_dir = opendir(desktop_file_dir))) {
+                while ((dir = readdir(desktopfiles_dir))) {
+                    if (dir->d_type != DT_DIR
+                        || pa_streq(dir->d_name, ".")
+                        || pa_streq(dir->d_name, ".."))
+                        continue;
+
+                    pa_xfree(fn);
+                    fn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", desktop_file_dir, dir->d_name, r->process_name);
+
+                    if (stat(fn, &st) == 0) {
+                        found = true;
+                        break;
+                    }
                 }
+                closedir(desktopfiles_dir);
+                if (found)
+                    break;
             }
-            closedir(desktopfiles_dir);
-        }
 #endif
+        }
+        pa_xfree(desktop_file_dir);
+      }
+
+      if (data_dir)
+          pa_xfree(data_dir);
     }
+
     if (!found) {
         r->good = false;
         pa_xfree(fn);
-- 
2.13.3



More information about the pulseaudio-discuss mailing list