diff --git a/src/config.c b/src/config.c index 5008223..abca070 100644 --- a/src/config.c +++ b/src/config.c @@ -603,7 +603,7 @@ void add_entry (char *key, char *value) launcher_max_icon_size = atoi(value); } else if (strcmp(key, "launcher_item_app") == 0) { - char *app = strdup(value); + char *app = expand_tilde(value); panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app); } else if (strcmp(key, "launcher_icon_theme") == 0) { diff --git a/src/tint2conf/properties.c b/src/tint2conf/properties.c index 60c3cb7..5aed407 100644 --- a/src/tint2conf/properties.c +++ b/src/tint2conf/properties.c @@ -1851,6 +1851,10 @@ void create_launcher(GtkWidget *parent) fprintf(stderr, "Loading .desktop files\n"); fflush(stderr); load_desktop_files("/usr/share/applications"); + gchar *path = g_build_filename(g_get_home_dir(), ".local/share/applications", NULL); + load_desktop_files(path); + g_free(path); + load_icons(launcher_apps); load_icons(all_apps); fprintf(stderr, "Desktop files loaded\n"); fflush(stderr); diff --git a/src/tint2conf/properties_rw.c b/src/tint2conf/properties_rw.c index 488853b..3cb8c9a 100644 --- a/src/tint2conf/properties_rw.c +++ b/src/tint2conf/properties_rw.c @@ -409,7 +409,9 @@ void config_write_launcher(FILE *fp) gtk_tree_model_get(GTK_TREE_MODEL(launcher_apps), &iter, appsColPath, &app_path, -1); - fprintf(fp, "launcher_item_app = %s\n", app_path); + char *contracted = contract_tilde(app_path); + fprintf(fp, "launcher_item_app = %s\n", contracted); + free(contracted); g_free(app_path); } @@ -1079,8 +1081,10 @@ void add_entry(char *key, char *value) gtk_spin_button_set_value(GTK_SPIN_BUTTON(launcher_icon_size), atoi(value)); } else if (strcmp(key, "launcher_item_app") == 0) { - load_desktop_file(value, TRUE); - load_desktop_file(value, FALSE); + char *path = expand_tilde(value); + load_desktop_file(path, TRUE); + load_desktop_file(path, FALSE); + free(path); } else if (strcmp(key, "launcher_icon_theme") == 0) { set_current_icon_theme(value); diff --git a/src/util/common.c b/src/util/common.c index 3675605..6e7ce19 100644 --- a/src/util/common.c +++ b/src/util/common.c @@ -26,7 +26,7 @@ #include #include #include - +#include #include "common.h" #include "../server.h" @@ -95,6 +95,43 @@ void tint_exec(const char *command) } } +char *expand_tilde(char *s) +{ + const gchar *home = g_get_home_dir(); + if (home && + (strcmp(s, "~") == 0 || + strstr(s, "~/") == s)) { + char *result = calloc(strlen(home) + strlen(s), 1); + strcat(result, home); + strcat(result, s + 1); + return result; + } else { + return strdup(s); + } +} + +char *contract_tilde(char *s) +{ + const gchar *home = g_get_home_dir(); + if (!home) + return strdup(s); + + char *home_slash = calloc(strlen(home) + 1, 1); + strcat(home_slash, home); + strcat(home_slash, "/"); + + if ((strcmp(s, home) == 0 || + strstr(s, home_slash) == s)) { + char *result = calloc(strlen(s) - strlen(home) + 1, 1); + strcat(result, "~"); + strcat(result, s + strlen(home)); + free(home_slash); + return result; + } else { + free(home_slash); + return strdup(s); + } +} int hex_char_to_int (char c) { @@ -297,7 +334,6 @@ void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright } } - void createHeuristicMask(DATA32* data, int w, int h) { // first we need to find the mask color, therefore we check all 4 edge pixel and take the color which diff --git a/src/util/common.h b/src/util/common.h index 0c60317..de16063 100644 --- a/src/util/common.h +++ b/src/util/common.h @@ -43,6 +43,13 @@ int parse_line (const char *line, char **key, char **value); // execute a command by calling fork 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 returned string must be freed by the caller. +char *expand_tilde(char *s); + +// The opposite of expand_tilde: replaces the path to the user's home directory with "~". +// The returned string must be freed by the caller. +char *contract_tilde(char *s); // conversion int hex_char_to_int (char c);