]> Dogcows Code - chaz/tint2/blobdiff - src/taskbar/task.c
*fix* tooltip copys the displayed text
[chaz/tint2] / src / taskbar / task.c
index 25c383ea1e372c129785a0f7f9b6a67a4c73d3ed..a59f28f50b18cc42f660e5e2bfab2f719e29ad0a 100644 (file)
 #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)
@@ -80,6 +89,7 @@ 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;
@@ -133,6 +143,8 @@ void remove_task (Task *tsk)
                                                task_active = 0;
                                        if (tsk2 == task_drag)
                                                task_drag = 0;
+                                       if (is_urgent(tsk2))
+                                               del_urgent(tsk2);
 
                                        XFreePixmap (server.dsp, tsk2->area.pix.pmap);
                                        XFreePixmap (server.dsp, tsk2->area.pix_active.pmap);
@@ -351,3 +363,170 @@ void draw_task (void *obj, cairo_t *c, int 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;
+       }
+}
+
+
+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;
+}
This page took 0.024109 seconds and 4 git commands to generate.