all repos — tint2 @ edbf9f4437ecf2f05ed4b5582914bbba1e507039

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

tint2conf: Sort applications correctly when additional desktop files from non-standard locations are found in the config
o9000 mrovi9000@gmail.com
commit

edbf9f4437ecf2f05ed4b5582914bbba1e507039

parent

e8eae2702925f2359ceafcf53787aab711430c32

3 files changed, 71 insertions(+), 28 deletions(-)

jump to
M src/tint2conf/properties.csrc/tint2conf/properties.c

@@ -2268,31 +2268,75 @@ }

void load_desktop_file(const char *file, gboolean selected) { - DesktopEntry entry; - if (read_desktop_file(file, &entry)) { - GdkPixbuf *pixbuf = load_icon(entry.icon); + char *file_contracted = contract_tilde(file); + + GtkListStore *store = selected ? launcher_apps : all_apps; + gboolean duplicate = FALSE; + for (int index = 0; ; index++) { + GtkTreePath *path = gtk_tree_path_new_from_indices(index, -1); GtkTreeIter iter; - gtk_list_store_append(selected ? launcher_apps : all_apps, &iter); - gtk_list_store_set(selected ? launcher_apps :all_apps, &iter, - appsColIcon, pixbuf, - appsColText, g_strdup(entry.name), - appsColPath, g_strdup(file), - appsColIconName, g_strdup(entry.icon), - -1); - if (pixbuf) - g_object_unref(pixbuf); - } else { - printf("Could not load %s\n", file); - GtkTreeIter iter; - gtk_list_store_append(selected ? launcher_apps : all_apps, &iter); - gtk_list_store_set(selected ? launcher_apps :all_apps, &iter, - appsColIcon, NULL, - appsColText, g_strdup(file), - appsColPath, g_strdup(file), - appsColIconName, g_strdup(""), - -1); + gboolean found = gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path); + gtk_tree_path_free(path); + if (!found) + break; + + gchar *app_path; + gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, appsColPath, &app_path, -1); + char *contracted = contract_tilde(app_path); + if (strcmp(contracted, file_contracted) == 0) { + duplicate = TRUE; + break; + } + free(contracted); + g_free(app_path); } - free_desktop_entry(&entry); + + if (!duplicate) { + DesktopEntry entry; + if (read_desktop_file(file, &entry)) { + int index; + gboolean stop = FALSE; + for (index = 0; !stop; index++) { + GtkTreePath *path = gtk_tree_path_new_from_indices(index, -1); + GtkTreeIter iter; + gboolean found = gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path); + gtk_tree_path_free(path); + if (!found) + break; + + gchar *app_name; + gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, appsColText, &app_name, -1); + if (strnatcasecmp(app_name, entry.name) >= 0) + stop = TRUE; + g_free(app_name); + } + + GdkPixbuf *pixbuf = load_icon(entry.icon); + GtkTreeIter iter; + gtk_list_store_insert(store, &iter, index); + gtk_list_store_set(store, &iter, + appsColIcon, pixbuf, + appsColText, g_strdup(entry.name), + appsColPath, g_strdup(file), + appsColIconName, g_strdup(entry.icon), + -1); + if (pixbuf) + g_object_unref(pixbuf); + } else { + printf("Could not load %s\n", file); + GtkTreeIter iter; + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, + appsColIcon, NULL, + appsColText, g_strdup(file), + appsColPath, g_strdup(file), + appsColIconName, g_strdup(""), + -1); + } + free_desktop_entry(&entry); + } + + free(file_contracted); } void populate_from_entries(GList *entries, gboolean selected)

@@ -2444,7 +2488,6 @@ #else

char real_path[65536]; #endif if (realpath(file, real_path)) { - fprintf(stderr, "SYMLINK %s -> %s in %s\n", file, real_path, path); if (strstr(real_path, path) == real_path) duplicate = TRUE; }
M src/util/common.csrc/util/common.c

@@ -112,7 +112,7 @@ }

} } -char *expand_tilde(char *s) +char *expand_tilde(const char *s) { const gchar *home = g_get_home_dir(); if (home && (strcmp(s, "~") == 0 || strstr(s, "~/") == s)) {

@@ -125,7 +125,7 @@ return strdup(s);

} } -char *contract_tilde(char *s) +char *contract_tilde(const char *s) { const gchar *home = g_get_home_dir(); if (!home)
M src/util/common.hsrc/util/common.h

@@ -53,11 +53,11 @@ void tint_exec(const char *command);

// Returns a copy of s in which "~" is expanded to the path to the user's home directory. // The caller takes ownership of the string. -char *expand_tilde(char *s); +char *expand_tilde(const char *s); // The opposite of expand_tilde: replaces the path to the user's home directory with "~". // The caller takes ownership of the string. -char *contract_tilde(char *s); +char *contract_tilde(const char *s); // Color int hex_char_to_int(char c);