]> Dogcows Code - chaz/tint2/commitdiff
add default icon on task (/usr/share/tint2/default_icon.png needed)
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Sat, 19 Sep 2009 05:30:43 +0000 (05:30 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Sat, 19 Sep 2009 05:30:43 +0000 (05:30 +0000)
default_icon.png [new file with mode: 0644]
src/panel.c
src/panel.h
src/taskbar/task.c

diff --git a/default_icon.png b/default_icon.png
new file mode 100644 (file)
index 0000000..70d1f07
Binary files /dev/null and b/default_icon.png differ
index 5aca8e46c215fe7b42141eda9bb60075598f3c78..a753dfec1646f033342734788d2b6f1885be4739 100644 (file)
@@ -58,6 +58,7 @@ int  max_tick_urgent;
 Panel *panel1 = 0;
 int  nb_panel;
 
+Imlib_Image default_icon;
 
 
 void init_panel()
@@ -65,6 +66,17 @@ void init_panel()
        int i;
        Panel *p;
 
+       // load default icon
+       char *path;
+       const gchar * const *data_dirs;
+       data_dirs = g_get_system_data_dirs ();
+       for (i = 0; data_dirs[i] != NULL; i++)  {
+               path = g_build_filename(data_dirs[i], "tint2", "default_icon.png", NULL);
+               if (g_file_test (path, G_FILE_TEST_EXISTS))
+                       default_icon = imlib_load_image(path);
+               g_free(path);
+       }
+
        for (i=0 ; i < nb_panel ; i++) {
                p = &panel1[i];
 
@@ -175,6 +187,11 @@ void cleanup_panel()
        cleanup_systray();
        cleanup_taskbar();
 
+       if (default_icon) {
+               imlib_context_set_image(default_icon);
+               imlib_free_image();
+       }
+
        // font allocated once
        if (panel1[0].g_task.font_desc) {
                pango_font_description_free(panel1[0].g_task.font_desc);
index b1ca46c33d1fcd22d47a2d22992e769873ad5fb7..dff0a03bc43b30098190737bf2da002371407936 100644 (file)
@@ -54,6 +54,8 @@ extern Task *task_urgent;
 extern int  tick_urgent;
 extern int  max_tick_urgent;
 
+extern Imlib_Image default_icon;
+
 
 typedef struct {
    // always start with area
index b8ca6780710ae05c02427b2b0220df51665ba019..64c86a82999770e0b77b846246651ab822de08bf 100644 (file)
@@ -172,6 +172,8 @@ void get_icon (Task *tsk)
 {
        Panel *panel = tsk->area.panel;
        if (!panel->g_task.icon) return;
+       unsigned int w, h, num;
+       long *data;
 
        if (tsk->icon_data) {
                free (tsk->icon_data);
@@ -180,12 +182,9 @@ void get_icon (Task *tsk)
        }
        tsk->area.redraw = 1;
 
-       long *data;
-       int num;
        data = server_get_property (tsk->win, server.atom._NET_WM_ICON, XA_CARDINAL, &num);
        if (data) {
                // get ARGB icon
-               int w, h;
                long *tmp_data;
                tmp_data = get_best_icon (data, get_icon_count (data, num), num, &w, &h, panel->g_task.icon_size1);
 
@@ -196,8 +195,7 @@ void get_icon (Task *tsk)
 
                if (tsk->icon_data) {
 #ifdef __x86_64__
-                       int length = tsk->icon_width * tsk->icon_height;
-                       int i;
+                       int i, length = w * h;
                        for (i = 0; i < length; ++i)
                                tsk->icon_data[i] =  tmp_data[i];
 #else
@@ -209,32 +207,33 @@ void get_icon (Task *tsk)
        else {
                // get Pixmap icon
                XWMHints *hints = XGetWMHints(server.dsp, tsk->win);
-               if (!hints) return;
-               if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
-                       // get width, height and depth for the pixmap
-                       Window root;
-                       int  icon_x, icon_y;
-                       uint border_width, bpp;
-                       uint icon_width, icon_height;
-
-                       XGetGeometry(server.dsp, hints->icon_pixmap, &root, &icon_x, &icon_y, &icon_width, &icon_height, &border_width, &bpp);
-
-                       //printf("  get_pixmap\n");
-                       Imlib_Image  img;
-                       imlib_context_set_drawable(hints->icon_pixmap);
-                       img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, icon_width, icon_height, 0);
-                       imlib_context_set_image(img);
-                       unsigned int *data = imlib_image_get_data();
-                       if (!data) {
-                               return;
+               Imlib_Image  img;
+               if (hints) {
+                       if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
+                               // get width, height and depth for the pixmap
+                               Window root;
+                               int  icon_x, icon_y;
+                               uint border_width, bpp;
+
+                               // printf("  get pixmap\n");
+                               XGetGeometry(server.dsp, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp);
+                               imlib_context_set_drawable(hints->icon_pixmap);
+                               img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0);
+                               imlib_context_set_image(img);
                        }
-                       tsk->icon_width = imlib_image_get_width();
-                       tsk->icon_height = imlib_image_get_height();
-                       tsk->icon_data = malloc (tsk->icon_width * tsk->icon_height * sizeof (DATA32));
-                       if (tsk->icon_data)
-                               memcpy (tsk->icon_data, data, tsk->icon_width * tsk->icon_height * sizeof (DATA32));
-                       imlib_free_image();
+                       else
+                               imlib_context_set_image(default_icon);
                }
+               else
+                       imlib_context_set_image(default_icon);
+               data = imlib_image_get_data();
+               tsk->icon_width = imlib_image_get_width();
+               tsk->icon_height = imlib_image_get_height();
+               tsk->icon_data = malloc (tsk->icon_width * tsk->icon_height * sizeof (DATA32));
+               if (tsk->icon_data)
+                       memcpy (tsk->icon_data, data, tsk->icon_width * tsk->icon_height * sizeof (DATA32));
+               if (imlib_context_get_image() == img)
+                       imlib_free_image();
                XFree(hints);
        }
 
This page took 0.029201 seconds and 4 git commands to generate.