[pulseaudio-commits] src/modules
Tanu Kaskinen
tanuk at kemper.freedesktop.org
Thu Nov 30 19:14:43 UTC 2017
src/modules/module-augment-properties.c | 78 +++++++++++++++++++++-----------
1 file changed, 53 insertions(+), 25 deletions(-)
New commits:
commit 10010f81e8c84c185f8d610a6190c3b943a289f9
Author: Iceyer <iceyers at gmail.com>
Date: Sat Nov 18 15:33:51 2017 +0800
augment-properties: support XDG_DATA_DIRS when find desktop files
diff --git a/src/modules/module-augment-properties.c b/src/modules/module-augment-properties.c
index 541f0e79..f0584328 100644
--- a/src/modules/module-augment-properties.c
+++ b/src/modules/module-augment-properties.c
@@ -131,32 +131,21 @@ static int catch_all(pa_config_parser_state *state) {
return 0;
}
-static void update_rule(struct rule *r) {
- char *fn;
- struct stat st;
- static pa_config_item table[] = {
- { "Name", pa_config_parse_string, NULL, "Desktop Entry" },
- { "Icon", pa_config_parse_string, NULL, "Desktop Entry" },
- { "Type", check_type, NULL, "Desktop Entry" },
- { "X-PulseAudio-Properties", parse_properties, NULL, "Desktop Entry" },
- { "Categories", parse_categories, NULL, "Desktop Entry" },
- { NULL, catch_all, NULL, NULL },
- { NULL, NULL, NULL, NULL },
- };
- bool found = false;
+static char * find_desktop_file_in_dir(struct rule *r, const char *desktop_file_dir, struct stat *st) {
+ char *fn = NULL;
- pa_assert(r);
- fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s.desktop", r->process_name);
+ pa_assert(st);
- if (stat(fn, &st) == 0)
- found = true;
- else {
+ fn = pa_sprintf_malloc("%s" PA_PATH_SEP "%s.desktop", desktop_file_dir, r->process_name);
+ if (stat(fn, st) == 0) {
+ return fn;
+ } 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))) {
+ if ((desktopfiles_dir = opendir(desktop_file_dir))) {
while ((dir = readdir(desktopfiles_dir))) {
if (dir->d_type != DT_DIR
|| pa_streq(dir->d_name, ".")
@@ -164,20 +153,59 @@ static void update_rule(struct rule *r) {
continue;
pa_xfree(fn);
- fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", dir->d_name, r->process_name);
+ 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;
+ if (stat(fn, st) == 0) {
+ closedir(desktopfiles_dir);
+ return fn;
}
}
closedir(desktopfiles_dir);
}
#endif
}
- if (!found) {
+ return NULL;
+}
+
+static void update_rule(struct rule *r) {
+ char *fn = NULL;
+ struct stat st;
+ static pa_config_item table[] = {
+ { "Name", pa_config_parse_string, NULL, "Desktop Entry" },
+ { "Icon", pa_config_parse_string, NULL, "Desktop Entry" },
+ { "Type", check_type, NULL, "Desktop Entry" },
+ { "X-PulseAudio-Properties", parse_properties, NULL, "Desktop Entry" },
+ { "Categories", parse_categories, NULL, "Desktop Entry" },
+ { NULL, catch_all, NULL, NULL },
+ { NULL, NULL, NULL, NULL },
+ };
+ const char *state = NULL;
+ const char *xdg_data_dirs = NULL;
+ char *data_dir = NULL;
+ char *desktop_file_dir = NULL;
+
+ pa_assert(r);
+
+ 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);
+
+ pa_xfree(fn);
+ fn = find_desktop_file_in_dir(r, desktop_file_dir, &st);
+
+ pa_xfree(desktop_file_dir);
+ pa_xfree(data_dir);
+
+ if (fn) {
+ break;
+ }
+ }
+ } else {
+ fn = find_desktop_file_in_dir(r, DESKTOPFILEDIR, &st);
+ }
+
+ if (!fn) {
r->good = false;
- pa_xfree(fn);
return;
}
More information about the pulseaudio-commits
mailing list