+ 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, *lfirst_tsk;
+ Task *tsk1;
+ Taskbar* tskbar = tsk->area.parent;
+
+ 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 = lfirst_tsk;
+ else l0 = l0->next;
+ return l0->data;
+ }
+ }
+
+ return 0;
+}
+
+Task *prev_task(Task *tsk)
+{
+ if (tsk == 0)
+ return 0;
+
+ GSList *l0, *lfirst_tsk;
+ Task *tsk1, *tsk2;
+ Taskbar* tskbar = tsk->area.parent;
+
+ tsk2 = 0;
+ 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 == lfirst_tsk) {
+ l0 = g_slist_last ( l0 );
+ tsk2 = l0->data;
+ }
+ return tsk2;
+ }
+ tsk2 = tsk1;
+ }
+
+ return 0;
+}
+
+
+void active_task()
+{
+ if (task_active) {
+ set_task_state(task_active, window_is_iconified(task_active->win) ? TASK_ICONIFIED : TASK_NORMAL);
+ task_active = 0;
+ }
+
+ Window w1 = window_get_active();
+ //printf("Change active task %ld\n", w1);
+
+ if (w1) {
+ 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);
+ }
+}
+
+
+void set_task_state(Task *tsk, int state)
+{
+ if (tsk == 0 || state < 0 || state >= TASK_STATE_COUNT)
+ return;
+
+ if (tsk->current_state != state) {
+ GPtrArray* task_group = task_get_tasks(tsk->win);
+ if (task_group) {
+ int i;
+ for (i=0; i<task_group->len; ++i) {
+ Task* tsk1 = g_ptr_array_index(task_group, i);
+ tsk1->current_state = state;
+ tsk1->area.bg = panel1[0].g_task.background[state];
+ tsk1->area.pix = tsk1->state_pix[state];
+ if (tsk1->state_pix[state] == 0)
+ tsk1->area.redraw = 1;
+ if (state == TASK_ACTIVE && g_slist_find(urgent_list, tsk1))
+ del_urgent(tsk1);
+ }
+ panel_refresh = 1;
+ }