]> Dogcows Code - chaz/tint2/blobdiff - src/launcher/launcher.c
fixed theme detection in local .icons directory
[chaz/tint2] / src / launcher / launcher.c
index 158e06c1ddac0a590253ed1b0b8709482b9c778a..6ac7f51cb4d5d2e57138b0141c6c80d335b12361 100644 (file)
@@ -70,18 +70,13 @@ void init_launcher_panel(void *p)
        launcher->area._resize = resize_launcher;
        launcher->area.resize = 1;
        launcher->area.redraw = 1;
-       launcher->area.on_screen = 1;
 
-       if (panel_horizontal) {
-               // panel horizonal => fixed height and posy
-               launcher->area.posy = panel->area.bg->border.width + panel->area.paddingy;
-               launcher->area.height = panel->area.height - (2 * launcher->area.posy);
-       }
-       else {
-               // panel vertical => fixed width, height, posy and posx
-               launcher->area.posx = panel->area.bg->border.width + panel->area.paddingxlr;
-               launcher->area.width = panel->area.width - (2 * panel->area.bg->border.width) - (2 * panel->area.paddingy);
-       }
+       // check consistency
+       if (launcher->list_apps == NULL)
+               return;
+
+       launcher->area.on_screen = 1;
+       panel_refresh = 1;
 
        fprintf(stderr, "Loading themes...\n");
        launcher_load_themes(launcher);
@@ -149,10 +144,10 @@ void cleanup_launcher()
        launcher_enabled = 0;
 }
 
-void resize_launcher(void *obj)
+
+int resize_launcher(void *obj)
 {
        Launcher *launcher = obj;
-       Panel *panel = launcher->area.panel;
        GSList *l;
        int count, icon_size;
        int icons_per_column=1, icons_per_row=1, marging=0;
@@ -222,9 +217,6 @@ void resize_launcher(void *obj)
                        icons_per_row = count / icons_per_column + (count%icons_per_column != 0);
                        launcher->area.width = (2 * launcher->area.bg->border.width) + (2 * launcher->area.paddingxlr) + (icon_size * icons_per_row) + ((icons_per_row-1) * launcher->area.paddingx);
                }
-
-               launcher->area.posx = panel->area.bg->border.width + panel->area.paddingxlr;
-               launcher->area.posy = panel->area.bg->border.width;
        }
        else {
                if (!count) launcher->area.height = 0;
@@ -236,9 +228,6 @@ void resize_launcher(void *obj)
                        icons_per_column = count / icons_per_row+ (count%icons_per_row != 0);
                        launcher->area.height = (2 * launcher->area.bg->border.width) + (2 * launcher->area.paddingxlr) + (icon_size * icons_per_column) + ((icons_per_column-1) * launcher->area.paddingx);
                }
-
-               launcher->area.posx = panel->area.bg->border.width;
-               launcher->area.posy = panel->area.height - panel->area.bg->border.width - panel->area.paddingxlr - launcher->area.height;
        }
 
        int i, posx, posy;
@@ -274,9 +263,7 @@ void resize_launcher(void *obj)
                        }
                }
        }
-       
-       // resize force the redraw
-       launcher->area.redraw = 1;
+       return 1;
 }
 
 
@@ -372,7 +359,7 @@ void expand_exec(DesktopEntry *entry, const char *path)
        // %c -> Name
        // %k -> path
        if (entry->exec) {
-               char *exec2 = malloc(strlen(entry->exec) + strlen(entry->name) + strlen(entry->icon) + 100);
+               char *exec2 = malloc(strlen(entry->exec) + (entry->name ? strlen(entry->name) : 1) + (entry->icon ? strlen(entry->icon) : 1) + 100);
                char *p, *q;
                // p will never point to an escaped char
                for (p = entry->exec, q = exec2; *p; p++, q++) {
@@ -486,29 +473,33 @@ IconTheme *load_theme(char *name)
        if (name == NULL)
                return NULL;
 
-       fprintf(stderr, "Loading icon theme %s\n", name);
-
-       file_name = malloc(100 + strlen(name));
-       sprintf(file_name, "~/.icons/%s/index.theme", name);
+       file_name = g_build_filename(g_get_home_dir(), ".icons", name, "index.theme", NULL);
        if (!g_file_test(file_name, G_FILE_TEST_EXISTS)) {
-               sprintf(file_name, "/usr/share/icons/%s/index.theme", name);
+               g_free (file_name);
+               file_name = g_build_filename("/usr", "share", "icons", name, "index.theme", NULL);
                if (!g_file_test(file_name, G_FILE_TEST_EXISTS)) {
-                       sprintf(file_name, "/usr/share/pixmaps/%s/index.theme", name);
+                       g_free (file_name);
+                       file_name = g_build_filename("/usr", "share", "pixmaps", name, "index.theme", NULL);
                        if (!g_file_test(file_name, G_FILE_TEST_EXISTS)) {
-                               free(file_name);
+                               g_free (file_name);
                                file_name = NULL;
                        }
                }
        }
+
        if (!file_name) {
-               fprintf(stderr, "Could not load theme %s\n", name);
+               fprintf(stderr, "Could not found theme '%s'\n", name);
                return NULL;
        }
 
-       if ((f = fopen(file_name, "rt")) == NULL)
+       if ((f = fopen(file_name, "rt")) == NULL) {
+               fprintf(stderr, "Could not open theme '%s'\n", file_name);
                return NULL;
+       }
+       else
+               fprintf(stderr, "Loading icon theme '%s'\n", file_name);
 
-       free(file_name);
+       g_free (file_name);
 
        theme = calloc(1, sizeof(IconTheme));
        theme->name = strdup(name);
@@ -711,6 +702,7 @@ void launcher_load_themes(Launcher *launcher)
                        launcher->icon_themes = g_slist_append(launcher->icon_themes, theme);
 
                        GSList* item = theme->list_inherits;
+                       int pos = 0;
                        while (item != NULL)
                        {
                                char *parent = item->data;
@@ -724,7 +716,8 @@ void launcher_load_themes(Launcher *launcher)
                                        queued_item = g_slist_next(queued_item);
                                }
                                if (!duplicate) {
-                                       queue = g_slist_append(queue, strdup(parent));
+                                       queue = g_slist_insert(queue, strdup(parent), pos);
+                                       pos++;
                                        queued = g_slist_append(queued, strdup(parent));
                                }
                                item = g_slist_next(item);
@@ -804,6 +797,7 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
        for (theme = launcher->icon_themes; theme; theme = g_slist_next(theme)) {
                GSList *dir;
                for (dir = ((IconTheme*)theme->data)->list_directories; dir; dir = g_slist_next(dir)) {
+                       //printf("directory  %s, size %d\n", ((IconThemeDir*)dir->data)->name, ((IconThemeDir*)dir->data)->size);
                        if (directory_matches_size((IconThemeDir*)dir->data, size)) {
                                GSList *base;
                                for (base = basenames; base; base = g_slist_next(base)) {
This page took 0.024491 seconds and 4 git commands to generate.