all repos — tint2 @ e113080a0e2c628bb1b6d3cd3d163557fee6bbe7

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Tentative to sort tasks on taskbar (disabled) - issue 478

git-svn-id: http://tint2.googlecode.com/svn/trunk@738 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
o9000 o9000
commit

e113080a0e2c628bb1b6d3cd3d163557fee6bbe7

parent

5faf063f967d6367886b671b7b5e2df8d2d05e56

M src/taskbar/task.csrc/taskbar/task.c

@@ -63,6 +63,7 @@ new_tsk.win = win;

new_tsk.desktop = window_get_desktop (win); new_tsk.area.panel = &panel1[monitor]; new_tsk.current_state = window_is_iconified(win) ? TASK_ICONIFIED : TASK_NORMAL; + window_get_position(win, &new_tsk.win_x, &new_tsk.win_y); // allocate only one title and one icon // even with task_on_all_desktop and with task_on_all_panel

@@ -114,6 +115,8 @@ Window* key = malloc(sizeof(Window));

*key = new_tsk.win; g_hash_table_insert(win_to_task_table, key, task_group); set_task_state(new_tsk2, new_tsk.current_state); + + sort_tasks(tskbar); if (panel_mode == MULTI_DESKTOP) { Panel *panel = new_tsk2->area.panel;
M src/taskbar/task.hsrc/taskbar/task.h

@@ -63,6 +63,9 @@ unsigned int icon_width;

unsigned int icon_height; char *title; int urgent_tick; + // These may not be up-to-date + int win_x; + int win_y; } Task;
M src/taskbar/taskbar.csrc/taskbar/taskbar.c

@@ -45,6 +45,7 @@ int taskbar_enabled;

int taskbar_distribute_size; int hide_inactive_tasks; int hide_task_diff_monitor; +int sort_tasks_method; guint win_hash(gconstpointer key) { return (guint)*((Window*)key); } gboolean win_compare(gconstpointer a, gconstpointer b) { return (*((Window*)a) == *((Window*)b)); }

@@ -60,6 +61,7 @@ taskbar_enabled = 0;

taskbar_distribute_size = 0; hide_inactive_tasks = 0; hide_task_diff_monitor = 0; + sort_tasks_method = TASKBAR_NOSORT; default_taskbarname(); }

@@ -408,3 +410,48 @@ }

panel_refresh = 1; } +gint compare_tasks(Task *a, Task *b, Taskbar *taskbar) +{ + if (a == b) + return 0; + if (taskbarname_enabled) { + if (a == taskbar->area.list->data) + return -1; + if (b == taskbar->area.list->data) + return 1; + } + if (a->win_x != b->win_x) { + return a->win_x - b->win_x; + } + return a->win_y - b->win_y; +} + +int taskbar_needs_sort(Taskbar *taskbar) +{ + if (sort_tasks_method == TASKBAR_NOSORT) + return 0; + + if (sort_tasks_method == TASKBAR_SORT_POSITION) { + GSList *i, *j; + for (i = taskbar->area.list, j = i ? i->next : NULL; i && j; i = i->next, j = j->next) { + if (compare_tasks(i->data, j->data, taskbar) > 0) { + return 1; + } + } + } + + return 0; +} + +void sort_tasks(Taskbar *taskbar) +{ + if (!taskbar) + return; + if (!taskbar_needs_sort(taskbar)) + return; + if (sort_tasks_method == TASKBAR_SORT_POSITION) { + taskbar->area.list = g_slist_sort_with_data(taskbar->area.list, (GCompareDataFunc)compare_tasks, taskbar); + taskbar->area.resize = 1; + panel_refresh = 1; + } +}
M src/taskbar/taskbar.hsrc/taskbar/taskbar.h

@@ -19,6 +19,8 @@ extern int taskbar_enabled;

extern int taskbar_distribute_size; extern int hide_inactive_tasks; extern int hide_task_diff_monitor; +enum { TASKBAR_NOSORT, TASKBAR_SORT_POSITION }; +extern int sort_tasks_method; typedef struct { // always start with area

@@ -74,6 +76,7 @@

// show/hide taskbar according to current desktop void visible_taskbar(void *p); +void sort_tasks(Taskbar *taskbar); #endif
M src/tint.csrc/tint.c

@@ -827,25 +827,31 @@ }

} // 'win' move in another monitor - if (nb_panel == 1 && !hide_task_diff_monitor) - return; - - Task *tsk = task_get_task (win); - if (!tsk) - return; + if (nb_panel > 1 || hide_task_diff_monitor) { + Task *tsk = task_get_task (win); + if (tsk) { + Panel *p = tsk->area.panel; + int monitor = window_get_monitor(win); + if ((hide_task_diff_monitor && p->monitor != monitor && tsk->area.on_screen) || + (hide_task_diff_monitor && p->monitor == monitor && !tsk->area.on_screen) || + (p->monitor != monitor && nb_panel > 1)) { + remove_task (tsk); + tsk = add_task (win); + if (win == window_get_active ()) { + set_task_state(tsk, TASK_ACTIVE); + task_active = tsk; + } + panel_refresh = 1; + } + } + } - Panel *p = tsk->area.panel; - int monitor = window_get_monitor(win); - if ((hide_task_diff_monitor && p->monitor != monitor && tsk->area.on_screen) || - (hide_task_diff_monitor && p->monitor == monitor && !tsk->area.on_screen) || - (p->monitor != monitor && nb_panel > 1)) { - remove_task (tsk); - tsk = add_task (win); - if (win == window_get_active ()) { - set_task_state(tsk, TASK_ACTIVE); - task_active = tsk; + if (sort_tasks_method == TASKBAR_SORT_POSITION) { + Task *tsk = task_get_task (win); + if (tsk) { + window_get_position(win, &tsk->win_x, &tsk->win_y); + sort_tasks(tsk->area.parent); } - panel_refresh = 1; } }
M src/util/window.csrc/util/window.c

@@ -144,6 +144,11 @@ if (i == server.nb_monitor) return 0;

else return i; } +void window_get_position (Window win, int *x, int *y) +{ + Window src; + XTranslateCoordinates(server.dsp, win, server.root_win, 0, 0, x, y, &src); +} int window_is_iconified (Window win) {
M src/util/window.hsrc/util/window.h

@@ -18,6 +18,7 @@ void set_desktop (int desktop);

void set_close (Window win); int server_get_current_desktop (); GSList *server_get_name_of_desktop (); +void window_get_position (Window win, int *x, int *y); int window_is_iconified (Window win); int window_is_urgent (Window win); int window_is_hidden (Window win);