X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Ftaskbar%2Ftask.c;h=994ff3f3893c7dce39965513e5900af05098eae8;hb=827f5d6fc955e7071351716d7d0d41b66ed65a76;hp=12476bc80250029451aa4354b93f89b6e38db39a;hpb=7c6cbefdf2443e1e9fa8372585d23fff40db1768;p=chaz%2Ftint2 diff --git a/src/taskbar/task.c b/src/taskbar/task.c index 12476bc..994ff3f 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -3,7 +3,7 @@ * Tint2 : task * * Copyright (C) 2007 PÃ¥l Staurland (staura@gmail.com) -* Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) +* Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -96,7 +96,8 @@ Task *add_task (Window win) new_tsk2->area.on_screen = 0; } new_tsk2->title = new_tsk.title; - new_tsk2->area._get_tooltip_text = task_get_tooltip; + if (panel1[monitor].g_task.tooltip_enabled) + new_tsk2->area._get_tooltip_text = task_get_tooltip; for (k=0; kicon[k] = new_tsk.icon[k]; new_tsk2->state_pix[k] = 0; @@ -159,12 +160,12 @@ void remove_task (Task *tsk) } -void get_title(Task *tsk) +int get_title(Task *tsk) { Panel *panel = tsk->area.panel; char *title, *name; - if (!panel->g_task.text && !g_tooltip.enabled) return; + if (!panel->g_task.text && !panel->g_task.tooltip_enabled) return 0; name = server_get_property (tsk->win, server.atom._NET_WM_VISIBLE_NAME, server.atom.UTF8_STRING, 0); if (!name || !strlen(name)) { @@ -184,9 +185,16 @@ void get_title(Task *tsk) else title[0] = 0; strcat(title, name); if (name) XFree (name); - - if (tsk->title) - free(tsk->title); + + if (tsk->title) { + // check unecessary title change + if (strcmp(tsk->title, title) == 0) { + free(title); + return 0; + } + else + free(tsk->title); + } tsk->title = title; GPtrArray* task_group = task_get_tasks(tsk->win); @@ -198,7 +206,7 @@ void get_title(Task *tsk) set_task_redraw(tsk2); } } - set_task_redraw(tsk); + return 1; } @@ -209,7 +217,7 @@ void get_icon (Task *tsk) int i; Imlib_Image img = NULL; XWMHints *hints = 0; - long *data = 0; + gulong *data = 0; int k; for (k=0; kg_task.icon_size1); - #ifdef __x86_64__ DATA32 icon_data[w * h]; int length = w * h; @@ -304,7 +311,6 @@ void get_icon (Task *tsk) set_task_redraw(tsk2); } } - set_task_redraw(tsk); } @@ -343,18 +349,20 @@ void draw_task (void *obj, cairo_t *c) Color *config_text; int width=0, height; Panel *panel = (Panel*)tsk->area.panel; + //printf("draw_task %d %d\n", tsk->area.posx, tsk->area.posy); 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); + 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_MIDDLE); - //pango_layout_set_wrap(layout, PANGO_WRAP_CHAR); + pango_layout_set_width(layout, ((Taskbar*)tsk->area.parent)->text_width * PANGO_SCALE); + pango_layout_set_height(layout, panel->g_task.text_height * PANGO_SCALE); + pango_layout_set_wrap(layout, PANGO_WRAP_CHAR); + pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); /* Center text */ if (panel->g_task.centered) pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); @@ -363,42 +371,86 @@ void draw_task (void *obj, cairo_t *c) pango_layout_get_pixel_size (layout, &width, &height); config_text = &panel->g_task.font[tsk->current_state]; - 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); + double text_posy = (panel->g_task.area.height - height) / 2.0; + cairo_move_to (c, panel->g_task.text_posx, 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); + cairo_move_to (c, panel->g_task.text_posx + 1, 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); } } +void on_change_task (void *obj) +{ + Task *tsk = obj; + Panel *panel = (Panel*)tsk->area.panel; + + long value[] = { panel->posx+tsk->area.posx, panel->posy+tsk->area.posy, tsk->area.width, tsk->area.height }; + XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4); + + // reset Pixmap when position/size changed + set_task_redraw(tsk); +} + +// Given a pointer to the active task (active_task) and a pointer +// to the task that is currently under the mouse (current_task), +// return a pointer to the active task that is on the same desktop +// as current_task. Normally this is simply active_task, except when +// it is set to appear on all desktops. In that case we search for +// another Task on current_task's taskbar, with the same window as +// active_task. +Task *find_active_task(Task *current_task, Task *active_task) +{ + if (active_task == 0) + return current_task; + if (active_task->desktop != ALLDESKTOP) + return active_task; + if (current_task == 0) + return active_task; + + GSList *l0; + Task *tsk; + Taskbar* tskbar = current_task->area.parent; + + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + for (; l0 ; l0 = l0->next) { + tsk = l0->data; + if (tsk->win == active_task->win) + return tsk; + } + return active_task; +} + Task *next_task(Task *tsk) { if (tsk == 0) return 0; - GSList *l0; + GSList *l0, *lfirst_tsk; Task *tsk1; Taskbar* tskbar = tsk->area.parent; - for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + lfirst_tsk = l0; + for (; l0 ; l0 = l0->next) { tsk1 = l0->data; if (tsk1 == tsk) { - if (l0->next == 0) l0 = tskbar->area.list; + if (l0->next == 0) l0 = lfirst_tsk; else l0 = l0->next; return l0->data; } @@ -412,15 +464,18 @@ Task *prev_task(Task *tsk) if (tsk == 0) return 0; - GSList *l0; + GSList *l0, *lfirst_tsk; Task *tsk1, *tsk2; Taskbar* tskbar = tsk->area.parent; tsk2 = 0; - for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + lfirst_tsk = l0; + for (; l0 ; l0 = l0->next) { tsk1 = l0->data; if (tsk1 == tsk) { - if (l0 == tskbar->area.list) { + if (l0 == lfirst_tsk) { l0 = g_slist_last ( l0 ); tsk2 = l0->data; } @@ -444,9 +499,11 @@ void active_task() //printf("Change active task %ld\n", w1); if (w1) { - Window w2; - if (XGetTransientForHint(server.dsp, w1, &w2) != 0) - if (w2 && !task_get_tasks(w1)) w1 = w2; + if (!task_get_tasks(w1)) { + Window w2; + while (XGetTransientForHint(server.dsp, w1, &w2)) + w1 = w2; + } set_task_state((task_active = task_get_task(w1)), TASK_ACTIVE); } }