diff options
Diffstat (limited to 'libmdock/matcher.c')
-rw-r--r-- | libmdock/matcher.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/libmdock/matcher.c b/libmdock/matcher.c index 25e2b2f..5c1bd8b 100644 --- a/libmdock/matcher.c +++ b/libmdock/matcher.c @@ -18,6 +18,7 @@ */ #include <ftw.h> +#include <stdlib.h> #include <string.h> #include <glib/gstdio.h> #include <gio/gio.h> @@ -107,6 +108,18 @@ static void add_desktop_item_by_wmclass(const gchar *wmclass, GDesktopAppInfo *i elist->list = g_slist_append(elist->list, item); } +static gchar *resolve_path(const gchar *path) +{ + char *buf = realpath(path, NULL); + if (buf) { + gchar *str = g_strdup(buf); + free(buf); + return str; + } else { + return NULL; + } +} + static void add_desktop_info(GDesktopAppInfo *info) { const char *quoted_executable = g_app_info_get_executable(G_APP_INFO(info)); @@ -117,11 +130,19 @@ static void add_desktop_info(GDesktopAppInfo *info) if (executable && executable[0]) { if (g_path_is_absolute(executable)) { - add_desktop_item_by_exec(executable, info, 4000); + gchar *resolved_exec = resolve_path(executable); + add_desktop_item_by_exec(resolved_exec, info, 4000); + g_free(resolved_exec); } else { gchar *execpath = g_find_program_in_path(executable); if (execpath) { - add_desktop_item_by_exec(execpath, info, 0); + gchar *resolved_exec = resolve_path(execpath); + if (resolved_exec) { + add_desktop_item_by_exec(resolved_exec, info, 0); + } else { + g_warning("Could not realpath executable: '%s'", execpath); + } + g_free(resolved_exec); } else { g_warning("Could not find executable in path: '%s'", executable); } @@ -199,6 +220,7 @@ static GSList * matches_by_executable(const gchar *exec) if (elist) { return g_slist_copy(elist->list); } else { + g_debug("Executable %s not matched", exec); return NULL; } } @@ -214,7 +236,7 @@ static GSList * matches_by_wmclass(const gchar *wmclass) } } -const gchar * match_application_to_desktop_file(AppId *appid) +const gchar * match_appid_to_desktopid(AppId *appid) { if (!init_matcher()) return NULL; @@ -229,6 +251,12 @@ const gchar * match_application_to_desktop_file(AppId *appid) if (list) { list = g_slist_sort(list, desktop_item_compare); + + for (GSList *l = list; l; l = l->next) { + DesktopItem *item = l->data; + g_debug(" match %d %s", item->priority, item->desktop_file); + } + DesktopItem *best = list->data; g_slist_free(list); return best->desktop_file; |