- if (tsk->icon_data == 0) get_icon (tsk);
- if (tsk->icon_data == 0) return;
-
- Pixmap *pmap;
-
- if (active) pmap = &tsk->area_active.pmap;
- else pmap = &tsk->area.pmap;
-
- /* Find pos */
- int pos_x;
- if (g_task.centered) {
- if (g_task.text)
- pos_x = (tsk->area.width - text_width - g_task.icon_size1) / 2;
- else
- pos_x = (tsk->area.width - g_task.icon_size1) / 2;
- }
- else pos_x = g_task.area.paddingx + g_task.area.border.width;
-
- /* Render */
- Imlib_Image icon;
- Imlib_Color_Modifier cmod;
- DATA8 red[256], green[256], blue[256], alpha[256];
-
- // TODO: cpu improvement : compute only when icon changed
- DATA32 *data;
- /* do we have 64bit? => long = 8bit */
- if (sizeof(long) != 4) {
- int length = tsk->icon_width * tsk->icon_height;
- data = malloc(sizeof(DATA32) * length);
- int i;
- for (i = 0; i < length; ++i)
- data[i] = tsk->icon_data[i];
- }
- else data = (DATA32 *) tsk->icon_data;
-
- icon = imlib_create_image_using_data (tsk->icon_width, tsk->icon_height, data);
- imlib_context_set_image (icon);
- imlib_context_set_drawable (*pmap);
-
- cmod = imlib_create_color_modifier ();
- imlib_context_set_color_modifier (cmod);
- imlib_image_set_has_alpha (1);
- imlib_get_color_modifier_tables (red, green, blue, alpha);
-
- int i, opacity;
- if (active) opacity = 255*g_task.font_active.alpha;
- else opacity = 255*g_task.font.alpha;
- for(i = 127; i < 256; i++) alpha[i] = opacity;
-
- imlib_set_color_modifier_tables (red, green, blue, alpha);
-
- //imlib_render_image_on_drawable (pos_x, pos_y);
- imlib_render_image_on_drawable_at_size (pos_x, g_task.icon_posy, g_task.icon_size1, g_task.icon_size1);
-
- imlib_free_color_modifier ();
- imlib_free_image ();
- if (sizeof(long) != 4) free(data);
+ if (tsk->icon == NULL || tsk->icon_active == NULL) return;
+
+ // Find pos
+ int pos_x;
+ Panel *panel = (Panel*)tsk->area.panel;
+ if (panel->g_task.centered) {
+ if (panel->g_task.text)
+ pos_x = (tsk->area.width - text_width - panel->g_task.icon_size1) / 2;
+ else
+ pos_x = (tsk->area.width - panel->g_task.icon_size1) / 2;
+ }
+ else pos_x = panel->g_task.area.paddingxlr + panel->g_task.area.pix.border.width;
+
+ // Render
+ Pixmap *pmap;
+ if (active == 0) {
+ imlib_context_set_image (tsk->icon);
+ pmap = &tsk->area.pix.pmap;
+ }
+ else {
+ imlib_context_set_image (tsk->icon_active);
+ pmap = &tsk->area.pix_active.pmap;
+ }
+ imlib_context_set_drawable (*pmap);
+ imlib_render_image_on_drawable (pos_x, panel->g_task.icon_posy);
+}
+
+
+void draw_task (void *obj, cairo_t *c, int active)
+{
+ Task *tsk = obj;
+ PangoLayout *layout;
+ config_color *config_text;
+ int width=0, height;
+ Panel *panel = (Panel*)tsk->area.panel;
+
+ if (panel->g_task.text) {
+ /* Layout */
+ layout = pango_cairo_create_layout (c);
+ pango_layout_set_font_description (layout, panel->g_task.font_desc);
+ pango_layout_set_text (layout, tsk->title, -1);
+
+ /* Drawing width and Cut text */
+ // pango use U+22EF or U+2026
+ pango_layout_set_width (layout, ((Taskbar*)tsk->area.parent)->text_width * PANGO_SCALE);
+ pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
+
+ /* Center text */
+ if (panel->g_task.centered) pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+ else pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
+
+ pango_layout_get_pixel_size (layout, &width, &height);
+
+ if (active) config_text = &panel->g_task.font_active;
+ else config_text = &panel->g_task.font;
+
+ cairo_set_source_rgba (c, config_text->color[0], config_text->color[1], config_text->color[2], config_text->alpha);
+
+ pango_cairo_update_layout (c, layout);
+ cairo_move_to (c, panel->g_task.text_posx, panel->g_task.text_posy);
+ pango_cairo_show_layout (c, layout);
+
+ if (panel->g_task.font_shadow) {
+ cairo_set_source_rgba (c, 0.0, 0.0, 0.0, 0.5);
+ pango_cairo_update_layout (c, layout);
+ cairo_move_to (c, panel->g_task.text_posx + 1, panel->g_task.text_posy + 1);
+ pango_cairo_show_layout (c, layout);
+ }
+ g_object_unref (layout);
+ }
+
+ if (panel->g_task.icon) {
+ // icon use same opacity as text
+ draw_task_icon (tsk, width, active);
+ }
+}
+
+
+Task *next_task(Task *tsk)
+{
+ GSList *l0;
+ int i, j;
+ Task *tsk1;
+
+ for (i=0 ; i < nb_panel ; i++) {
+ for (j=0 ; j < panel1[i].nb_desktop ; j++) {
+ for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
+ tsk1 = l0->data;
+ if (tsk1 == tsk) {
+ if (l0->next == NULL) l0 = panel1[i].taskbar[j].area.list;
+ else l0 = l0->next;
+ return l0->data;
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+
+Task *prev_task(Task *tsk)
+{
+ GSList *l0;
+ int i, j;
+ Task *tsk1, *tsk2;
+
+ for (i=0 ; i < nb_panel ; i++) {
+ for (j=0 ; j < panel1[i].nb_desktop ; j++) {
+ tsk2 = NULL;
+ for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
+ tsk1 = l0->data;
+ if (tsk1 == tsk) {
+ if (l0 == panel1[i].taskbar[j].area.list) {
+ l0 = g_slist_last ( l0 );
+ tsk2 = l0->data;
+ }
+ return tsk2;
+ }
+ tsk2 = tsk1;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+
+void active_task()
+{
+ GSList *l0;
+ int i, j;
+ Task *tsk1, *tsk2;
+
+ if (task_active) {
+ for (i=0 ; i < nb_panel ; i++) {
+ for (j=0 ; j < panel1[i].nb_desktop ; j++) {
+ for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
+ tsk1 = l0->data;
+ tsk1->area.is_active = 0;
+ }
+ }
+ }
+ task_active = 0;
+ }
+
+ Window w1 = window_get_active ();
+ //printf("Change active task %ld\n", w1);
+
+ tsk2 = task_get_task(w1);
+ if (!tsk2) {
+ Window w2;
+ if (XGetTransientForHint(server.dsp, w1, &w2) != 0)
+ if (w2) tsk2 = task_get_task(w2);
+ }
+ if ( is_urgent(tsk2) ) {
+ del_urgent(tsk2);
+ }
+ // put active state on all task (multi_desktop)
+ if (tsk2) {
+ for (i=0 ; i < nb_panel ; i++) {
+ for (j=0 ; j < panel1[i].nb_desktop ; j++) {
+ for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
+ tsk1 = l0->data;
+ if (tsk1->win == tsk2->win) {
+ tsk1->area.is_active = 1;
+ }
+ }
+ }
+ }
+ task_active = tsk2;
+ }