]> Dogcows Code - chaz/tint2/blobdiff - src/taskbar/task.c
*add* multiple tasks can be urgent now
[chaz/tint2] / src / taskbar / task.c
index c8db413eaa9e95fc1cceb755e9377ccc0b73dce9..07db3723068ad0ee6f9d25ea4335fc0f3da8e61c 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
+#include <unistd.h>
 
 #include "window.h"
 #include "task.h"
@@ -363,3 +364,101 @@ void draw_task (void *obj, cairo_t *c, int active)
 }
 
 
+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 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);
+       time_precision = 1;
+}
+
+
+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)
+                               init_precision();
+                       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;
+}
This page took 0.02581 seconds and 4 git commands to generate.