]> Dogcows Code - chaz/tint2/blobdiff - src/launcher/launcher.c
Added alpha, saturation, brightness control for launcher icons (Issue 365).
[chaz/tint2] / src / launcher / launcher.c
index 4e7a6f956a6870e676a70dca699657e61967ec30..fd85fed0e531fe7e94cfae90b2effa9f94979bdc 100644 (file)
@@ -34,6 +34,9 @@
 
 int launcher_enabled;
 int launcher_max_icon_size;
+int launcher_alpha;
+int launcher_saturation;
+int launcher_brightness;
 char *icon_theme_name; 
 XSettingsClient *xsettings_client;
 
@@ -52,6 +55,9 @@ void default_launcher()
 {
        launcher_enabled = 0;
        launcher_max_icon_size = 0;
+       launcher_alpha = 100;
+       launcher_saturation = 0;
+       launcher_brightness = 0;
        icon_theme_name = 0;
        xsettings_client = NULL;
 }
@@ -301,6 +307,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 +435,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);
                        }
                }
@@ -701,10 +716,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));
This page took 0.026482 seconds and 4 git commands to generate.