#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include <unistd.h>
#include "window.h"
#include "task.h"
#include "server.h"
#include "panel.h"
#include "tooltip.h"
+#include "timer.h"
+static int urgent_timer = 0;
+
+const char* task_get_tooltip(void* obj)
+{
+ Task* t = obj;
+ return t->title;
+}
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;
new_tsk2->icon = new_tsk.icon;
new_tsk2->icon_active = new_tsk.icon_active;
new_tsk2->icon_width = new_tsk.icon_width;
int length = w * h;
for (i = 0; i < length; ++i)
icon_data[i] = tmp_data[i];
- img = imlib_create_image_using_data (w, h, icon_data);
+ img = imlib_create_image_using_copied_data (w, h, icon_data);
#else
img = imlib_create_image_using_data (w, h, (DATA32*)tmp_data);
#endif
}
+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;
+ }
+}
+
+
+void blink_urgent()
+{
+ GSList* urgent_task = urgent_list;
+ while (urgent_task) {
+ Task_urgent* t = urgent_task->data;
+ if ( t->tick < max_tick_urgent) {
+ t->tsk->area.is_active = !t->tsk->area.is_active;
+ t->tsk->area.redraw = 1;
+ t->tick++;
+ }
+ urgent_task = urgent_task->next;
+ }
+ panel_refresh = 1;
+}
+
+
+void add_urgent(Task *tsk)
+{
+ // first check if task is already in the list and reset the counter
+ GSList* urgent_task = urgent_list;
+ while (urgent_task) {
+ Task_urgent* t = urgent_task->data;
+ if (t->tsk == tsk) {
+ t->tick = 0;
+ return;
+ }
+ urgent_task = urgent_task->next;
+ }
+
+ // not yet in the list, so we have to add it
+ Task_urgent* t = malloc(sizeof(Task_urgent));
+ if (!t)
+ return;
+ t->tsk = tsk;
+ t->tick = 0;
+ urgent_list = g_slist_prepend(urgent_list, t);
+
+ if (urgent_timer == 0)
+ urgent_timer = install_timer(0, 1000000, 1, 0, blink_urgent);
+ else
+ reset_timer(urgent_timer, 0, 1000000, 1, 0);
+}
+
+
+void del_urgent(Task *tsk)
+{
+ GSList* urgent_task = urgent_list;
+ while (urgent_task) {
+ Task_urgent* t = urgent_task->data;
+ if (t->tsk == tsk) {
+ urgent_list = g_slist_remove(urgent_list, t);
+ free(t);
+ if (!urgent_list)
+ reset_timer(urgent_timer, 0, 0, 0, 0);
+ return;
+ }
+ urgent_task = urgent_task->next;
+ }
+}
+
+int is_urgent(Task *tsk)
+{
+ GSList* urgent_task = urgent_list;
+ while (urgent_task) {
+ Task_urgent* t = urgent_task->data;
+ if (t->tsk == tsk)
+ return 1;
+ urgent_task = urgent_task->next;
+ }
+ return 0;
+}