]> Dogcows Code - chaz/tint2/blobdiff - src/taskbar/task.c
Fix for incorrect task cycling when windows visible on all desktops are present
[chaz/tint2] / src / taskbar / task.c
index e03f69c60943e40aad3511812cbce8c332840701..994ff3f3893c7dce39965513e5900af05098eae8 100644 (file)
@@ -405,22 +405,52 @@ void on_change_task (void *obj)
        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;
 
        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;
                }
@@ -434,17 +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;
        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;
                        }
This page took 0.022092 seconds and 4 git commands to generate.