From 734af1c0253eefad4486cd8dbc907141032f48ff Mon Sep 17 00:00:00 2001 From: o9000 Date: Sun, 28 Feb 2016 15:50:32 +0100 Subject: [PATCH] tint2conf: Do not load desktop files marked as NoDisplay --- src/launcher/apps-common.c | 12 ++++++++---- src/launcher/apps-common.h | 1 + src/tint2conf/properties.c | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/launcher/apps-common.c b/src/launcher/apps-common.c index 793b602..fd2b654 100644 --- a/src/launcher/apps-common.c +++ b/src/launcher/apps-common.c @@ -54,8 +54,8 @@ void expand_exec(DesktopEntry *entry, const char *path) // %k -> path if (entry->exec) { char *exec2 = calloc(strlen(entry->exec) + (entry->name ? strlen(entry->name) : 1) + - (entry->icon ? strlen(entry->icon) : 1) + 100, - 1); + (entry->icon ? strlen(entry->icon) : 1) + 100, + 1); char *p, *q; // p will never point to an escaped char for (p = entry->exec, q = exec2; *p; p++, q++) { @@ -112,13 +112,14 @@ int read_desktop_file(const char *path, DesktopEntry *entry) entry->path = strdup(path); entry->name = entry->icon = entry->exec = NULL; + entry->hidden_from_menus = FALSE; if ((fp = fopen(path, "rt")) == NULL) { fprintf(stderr, "Could not open file %s\n", path); return 0; } - const gchar **languages = (const gchar **)g_get_language_names(); + const gchar **languages = (const gchar **)g_get_language_names(); // lang_index is the index of the language for the best Name key in the language vector // lang_index_default is a constant that encodes the Name key without a language int lang_index, lang_index_default; @@ -165,6 +166,8 @@ int read_desktop_file(const char *path, DesktopEntry *entry) entry->exec = strdup(value); } else if (!entry->icon && strcmp(key, "Icon") == 0) { entry->icon = strdup(value); + } else if (!entry->icon && strcmp(key, "NoDisplay") == 0) { + entry->hidden_from_menus = strcasecmp(value, "true") == 0; } } } @@ -205,7 +208,8 @@ const GSList *get_apps_locations() apps_locations = load_locations_from_env(apps_locations, "XDG_DATA_HOME", "applications", NULL); - apps_locations = g_slist_append(apps_locations, g_build_filename(g_get_home_dir(), ".local/share/applications", NULL)); + apps_locations = + g_slist_append(apps_locations, g_build_filename(g_get_home_dir(), ".local/share/applications", NULL)); apps_locations = load_locations_from_env(apps_locations, "XDG_DATA_DIRS", "applications", NULL); diff --git a/src/launcher/apps-common.h b/src/launcher/apps-common.h index 80afe69..de45898 100644 --- a/src/launcher/apps-common.h +++ b/src/launcher/apps-common.h @@ -14,6 +14,7 @@ typedef struct DesktopEntry { char *exec; char *icon; char *path; + gboolean hidden_from_menus; } DesktopEntry; // Parses a line of the form "key = value". Modifies the line. diff --git a/src/tint2conf/properties.c b/src/tint2conf/properties.c index 065d783..9286618 100644 --- a/src/tint2conf/properties.c +++ b/src/tint2conf/properties.c @@ -2367,6 +2367,10 @@ void load_desktop_entry(const char *file, GList **entries) DesktopEntry *entry = calloc(1, sizeof(DesktopEntry)); if (!read_desktop_file(file, entry)) printf("Could not load %s\n", file); + if (entry->hidden_from_menus) { + free(entry); + return; + } if (!entry->name) entry->name = strdup(file); if (!entry->icon)