Sort tasks on taskbar (disabled, work in progress) - issue 478 git-svn-id: http://tint2.googlecode.com/svn/trunk@740 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
o9000 o9000
7 files changed,
58 insertions(+),
16 deletions(-)
M
src/taskbar/task.c
→
src/taskbar/task.c
@@ -63,7 +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); + window_get_coordinates(win, &new_tsk.win_x, &new_tsk.win_y, &new_tsk.win_w, &new_tsk.win_h); // allocate only one title and one icon // even with task_on_all_desktop and with task_on_all_panel@@ -92,6 +92,10 @@ memcpy(&new_tsk2->area, &panel1[monitor].g_task.area, sizeof(Area));
new_tsk2->area.parent = tskbar; new_tsk2->win = new_tsk.win; new_tsk2->desktop = new_tsk.desktop; + new_tsk2->win_x = new_tsk.win_x; + new_tsk2->win_y = new_tsk.win_y; + new_tsk2->win_w = new_tsk.win_w; + new_tsk2->win_h = new_tsk.win_h; new_tsk2->current_state = -1; // to update the current state later in set_task_state... if (new_tsk2->desktop == ALLDESKTOP && server.desktop != j) { // hide ALLDESKTOP task on non-current desktop@@ -116,7 +120,7 @@ *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); + sort_taskbar_for_win(win); if (panel_mode == MULTI_DESKTOP) { Panel *panel = new_tsk2->area.panel;
M
src/taskbar/task.h
→
src/taskbar/task.h
@@ -66,6 +66,8 @@ int urgent_tick;
// These may not be up-to-date int win_x; int win_y; + int win_w; + int win_h; } Task;
M
src/taskbar/taskbar.c
→
src/taskbar/taskbar.c
@@ -412,6 +412,8 @@ }
gint compare_tasks(Task *a, Task *b, Taskbar *taskbar) { + int a_horiz_c, a_vert_c, b_horiz_c, b_vert_c; + if (a == b) return 0; if (taskbarname_enabled) {@@ -420,10 +422,14 @@ return -1;
if (b == taskbar->area.list->data) return 1; } - if (a->win_x != b->win_x) { - return a->win_x - b->win_x; + a_horiz_c = a->win_x + a->win_w / 2; + b_horiz_c = b->win_x + b->win_w / 2; + a_vert_c = a->win_y + a->win_h / 2; + b_vert_c = b->win_y + b->win_h / 2; + if (a_horiz_c != b_horiz_c) { + return a_horiz_c - b_horiz_c; } - return a->win_y - b->win_y; + return a_vert_c - b_vert_c; } int taskbar_needs_sort(Taskbar *taskbar)@@ -455,3 +461,26 @@ taskbar->area.resize = 1;
panel_refresh = 1; } } + + +void sort_taskbar_for_win(Window win) +{ + if (sort_tasks_method == TASKBAR_SORT_POSITION) { + GPtrArray* task_group = task_get_tasks(win); + if (task_group) { + int i; + Task* tsk0 = g_ptr_array_index(task_group, 0); + if (tsk0) { + window_get_coordinates(win, &tsk0->win_x, &tsk0->win_y, &tsk0->win_w, &tsk0->win_h); + } + for (i = 0; i < task_group->len; ++i) { + Task* tsk = g_ptr_array_index(task_group, i); + tsk->win_x = tsk0->win_x; + tsk->win_y = tsk0->win_y; + tsk->win_w = tsk0->win_w; + tsk->win_h = tsk0->win_h; + sort_tasks(tsk->area.parent); + } + } + } +}
M
src/taskbar/taskbar.h
→
src/taskbar/taskbar.h
@@ -76,6 +76,7 @@
// show/hide taskbar according to current desktop void visible_taskbar(void *p); +void sort_taskbar_for_win(Window win); void sort_tasks(Taskbar *taskbar); #endif
M
src/tint.c
→
src/tint.c
@@ -475,6 +475,9 @@ panel_refresh = 1;
task_dragged = 1; } } + if (sort_tasks_method == TASKBAR_SORT_POSITION) { + sort_tasks(event_taskbar); + } } else { // The event is on another taskbar than the task being dragged if(task_drag->desktop == ALLDESKTOP || panel_mode != MULTI_DESKTOP)@@ -495,6 +498,10 @@ task_drag->area.parent = event_taskbar;
task_drag->desktop = event_taskbar->desktop; windows_set_desktop(task_drag->win, event_taskbar->desktop); + + if (sort_tasks_method == TASKBAR_SORT_POSITION) { + sort_tasks(event_taskbar); + } event_taskbar->area.resize = 1; drag_taskbar->area.resize = 1;@@ -846,13 +853,7 @@ }
} } - 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); - } - } + sort_taskbar_for_win(win); } char *GetAtomName(Display* disp, Atom a)
M
src/util/window.c
→
src/util/window.c
@@ -144,10 +144,15 @@ if (i == server.nb_monitor) return 0;
else return i; } -void window_get_position (Window win, int *x, int *y) +void window_get_coordinates (Window win, int *x, int *y, int *w, int *h) { - Window src; - XTranslateCoordinates(server.dsp, win, server.root_win, 0, 0, x, y, &src); + int dummy_int; + unsigned ww, wh, bw, bh; + Window src; + XTranslateCoordinates(server.dsp, win, server.root_win, 0, 0, x, y, &src); + XGetGeometry(server.dsp, win, &src, &dummy_int, &dummy_int, &ww, &wh, &bw, &bh); + *w = ww + bw; + *h = wh + bh; } int window_is_iconified (Window win)
M
src/util/window.h
→
src/util/window.h
@@ -18,7 +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); +void window_get_coordinates (Window win, int *x, int *y, int *w, int *h); int window_is_iconified (Window win); int window_is_urgent (Window win); int window_is_hidden (Window win);