]> Dogcows Code - chaz/tint2/blobdiff - src/launcher/launcher.c
Launcher: add icon lookup in ~/.local and /usr/local
[chaz/tint2] / src / launcher / launcher.c
index 4e7a6f956a6870e676a70dca699657e61967ec30..6915d05b00cd7d445177e827a50c79e9a236b824 100644 (file)
 
 int launcher_enabled;
 int launcher_max_icon_size;
+int launcher_tooltip_enabled;
+int launcher_alpha;
+int launcher_saturation;
+int launcher_brightness;
 char *icon_theme_name; 
 XSettingsClient *xsettings_client;
 
@@ -52,6 +56,10 @@ void default_launcher()
 {
        launcher_enabled = 0;
        launcher_max_icon_size = 0;
+       launcher_tooltip_enabled = 0;
+       launcher_alpha = 100;
+       launcher_saturation = 0;
+       launcher_brightness = 0;
        icon_theme_name = 0;
        xsettings_client = NULL;
 }
@@ -96,6 +104,7 @@ void init_launcher_panel(void *p)
 void cleanup_launcher()
 {
        int i;
+       GSList *l;
 
        if (xsettings_client)
                xsettings_client_destroy(xsettings_client);
@@ -103,15 +112,14 @@ void cleanup_launcher()
                Panel *panel = &panel1[i];
                Launcher *launcher = &panel->launcher;          
                cleanup_launcher_theme(launcher);
-               
-               GSList *l;
-               for (l = launcher->list_apps; l ; l = l->next) {
-                       free(l->data);
-               }
-               g_slist_free(launcher->list_apps);
-               launcher->list_apps = NULL;
        }
-       g_free(icon_theme_name);
+       for (l = panel_config.launcher.list_apps; l ; l = l->next) {
+               free(l->data);
+       }
+       g_slist_free(panel_config.launcher.list_apps);
+       panel_config.launcher.list_apps = NULL;
+       free(icon_theme_name);
+       icon_theme_name = 0;
        launcher_enabled = 0;
 }
 
@@ -301,6 +309,11 @@ Imlib_Image scale_icon(Imlib_Image original, int icon_size)
        if (original) {
                imlib_context_set_image (original);
                icon_scaled = imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), icon_size, icon_size);
+               imlib_context_set_image (icon_scaled);
+               imlib_image_set_has_alpha(1);
+               DATA32* data = imlib_image_get_data();
+               adjust_asb(data, icon_size, icon_size, launcher_alpha, (float)launcher_saturation/100, (float)launcher_brightness/100);
+               imlib_image_put_back_data(data);
        } else {
                icon_scaled = imlib_create_image(icon_size, icon_size);
                imlib_context_set_image (icon_scaled);
@@ -424,17 +437,21 @@ int launcher_read_desktop_file(const char *path, DesktopEntry *entry)
                return 0;
        }
 
+       int inside_desktop_entry = 0;
        while (getline(&line, &line_size, fp) >= 0) {
                int len = strlen(line);
                if (len == 0)
                        continue;
                line[len - 1] = '\0';
-               if (parse_dektop_line(line, &key, &value)) {
-                       if (strcmp(key, "Name") == 0) {
+               if (line[0] == '[') {
+                       inside_desktop_entry = (strcmp(line, "[Desktop Entry]") == 0);
+               }
+               if (inside_desktop_entry && parse_dektop_line(line, &key, &value)) {
+                       if (!entry->name && strcmp(key, "Name") == 0) {
                                entry->name = strdup(value);
-                       } else if (strcmp(key, "Exec") == 0) {
+                       } else if (!entry->exec && strcmp(key, "Exec") == 0) {
                                entry->exec = strdup(value);
-                       } else if (strcmp(key, "Icon") == 0) {
+                       } else if (!entry->icon && strcmp(key, "Icon") == 0) {
                                entry->icon = strdup(value);
                        }
                }
@@ -679,7 +696,10 @@ void launcher_load_icons(Launcher *launcher)
                        launcherIcon->area.bg = &g_array_index(backgrounds, Background, 0);
                        launcherIcon->area.on_screen = 1;
                        launcherIcon->area._on_change_layout = launcher_icon_on_change_layout;
-                       launcherIcon->area._get_tooltip_text = launcher_icon_get_tooltip_text;
+                       if (launcher_tooltip_enabled) 
+                               launcherIcon->area._get_tooltip_text = launcher_icon_get_tooltip_text;
+                       else
+                               launcherIcon->area._get_tooltip_text = NULL;
                        launcherIcon->is_app_desktop = 1;
                        launcherIcon->cmd = strdup(entry.exec);
                        launcherIcon->icon_name = entry.icon ? strdup(entry.icon) : strdup(ICON_FALLBACK);
@@ -701,10 +721,10 @@ void launcher_load_themes(Launcher *launcher)
        // avoid inheritance loops
        if (!icon_theme_name) {
                fprintf(stderr, "Missing launcher theme, default to 'hicolor'.\n");
-               icon_theme_name = "hicolor";
-       }
-       else
+               icon_theme_name = strdup("hicolor");
+       } else {
                fprintf(stderr, "Loading %s. Icon theme :", icon_theme_name);
+       }
 
        GSList *queue = g_slist_append(NULL, strdup(icon_theme_name));
        GSList *queued = g_slist_append(NULL, strdup(icon_theme_name));
@@ -803,6 +823,7 @@ int directory_size_distance(IconThemeDir *dir, int size)
        }
 }
 
+#define DEBUG_ICON_SEARCH 0
 // Returns the full path to an icon file (or NULL) given the icon name
 char *icon_path(Launcher *launcher, const char *icon_name, int size)
 {
@@ -820,6 +841,10 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
        GSList *basenames = NULL;
        char *home_icons = g_build_filename(g_get_home_dir(), ".icons", NULL);
        basenames = g_slist_append(basenames, home_icons);
+       char *home_local_icons = g_build_filename(g_get_home_dir(), ".local/share/icons", NULL);
+       basenames = g_slist_append(basenames, home_local_icons);
+       basenames = g_slist_append(basenames, "/usr/local/share/icons");
+       basenames = g_slist_append(basenames, "/usr/local/share/pixmaps");
        basenames = g_slist_append(basenames, "/usr/share/icons");
        basenames = g_slist_append(basenames, "/usr/share/pixmaps");
 
@@ -864,6 +889,7 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
                                                        g_slist_free(basenames);
                                                        g_slist_free(extensions);
                                                        g_free(home_icons);
+                                                       g_free(home_local_icons);
                                                        return file_name;
                                                } else {
                                                        free(file_name);
@@ -907,8 +933,11 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
                                        strlen(dir_name) + strlen(icon_name) + strlen(extension) + 100);
                                        // filename = directory/$(themename)/subdirectory/iconname.extension
                                        sprintf(file_name, "%s/%s/%s/%s%s", base_name, theme_name, dir_name, icon_name, extension);
+                                       if (DEBUG_ICON_SEARCH)
+                                               printf("checking %s\n", file_name);
                                        if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
-                                               //printf("found: %s\n", file_name);
+                                               if (DEBUG_ICON_SEARCH)
+                                                       printf("found: %s\n", file_name);
                                                // Closest match
                                                if (directory_size_distance((IconThemeDir*)dir->data, size) < minimal_size && (!best_file_theme ? 1 : theme == best_file_theme)) {
                                                        if (best_file_name) {
@@ -918,7 +947,8 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
                                                        best_file_name = strdup(file_name);
                                                        minimal_size = directory_size_distance((IconThemeDir*)dir->data, size);
                                                        best_file_theme = theme;
-                                                       //printf("best_file_name = %s; minimal_size = %d\n", best_file_name, minimal_size);
+                                                       if (DEBUG_ICON_SEARCH)
+                                                               printf("best_file_name = %s; minimal_size = %d\n", best_file_name, minimal_size);
                                                }
                                                // Next larger match
                                                if (((IconThemeDir*)dir->data)->size >= size &&
@@ -931,7 +961,8 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
                                                        next_larger = strdup(file_name);
                                                        next_larger_size = ((IconThemeDir*)dir->data)->size;
                                                        next_larger_theme = theme;
-                                                       //printf("next_larger = %s; next_larger_size = %d\n", next_larger, next_larger_size);
+                                                       if (DEBUG_ICON_SEARCH)
+                                                               printf("next_larger = %s; next_larger_size = %d\n", next_larger, next_larger_size);
                                                }
                                        }
                                        free(file_name);
@@ -944,12 +975,14 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
                g_slist_free(extensions);
                free(best_file_name);
                g_free(home_icons);
+               g_free(home_local_icons);
                return next_larger;
        }
        if (best_file_name) {
                g_slist_free(basenames);
                g_slist_free(extensions);
                g_free(home_icons);
+               g_free(home_local_icons);
                return best_file_name;
        }
 
@@ -965,11 +998,13 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
                                        strlen(extension) + 100);
                                // filename = directory/iconname.extension
                                sprintf(file_name, "%s/%s%s", base_name, icon_name, extension);
-                               //printf("checking %s\n", file_name);
+                               if (DEBUG_ICON_SEARCH)
+                                       printf("checking %s\n", file_name);
                                if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
                                        g_slist_free(basenames);
                                        g_slist_free(extensions);
                                        g_free(home_icons);
+                                       g_free(home_local_icons);
                                        return file_name;
                                } else {
                                        free(file_name);
@@ -984,6 +1019,7 @@ char *icon_path(Launcher *launcher, const char *icon_name, int size)
        g_slist_free(basenames);
        g_slist_free(extensions);
        g_free(home_icons);
+       g_free(home_local_icons);
        return NULL;
 }
 
This page took 0.029305 seconds and 4 git commands to generate.