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
This commit is contained in:
o9000 2015-03-28 21:07:33 +00:00 committed by mrovi9000@gmail.com
parent 1a41159142
commit 5376e09963
7 changed files with 58 additions and 16 deletions

View file

@ -63,7 +63,7 @@ Task *add_task (Window 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 @@ Task *add_task (Window win)
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 @@ Task *add_task (Window 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;

View file

@ -66,6 +66,8 @@ typedef struct {
// These may not be up-to-date
int win_x;
int win_y;
int win_w;
int win_h;
} Task;

View file

@ -412,6 +412,8 @@ void visible_taskbar(void *p)
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 @@ gint compare_tasks(Task *a, Task *b, Taskbar *taskbar)
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 @@ void sort_tasks(Taskbar *taskbar)
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);
}
}
}
}

View file

@ -76,6 +76,7 @@ void set_taskbar_state(Taskbar *tskbar, int state);
// 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

View file

@ -475,6 +475,9 @@ void event_button_motion_notify (XEvent *e)
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)
@ -496,6 +499,10 @@ void event_button_motion_notify (XEvent *e)
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;
task_dragged = 1;
@ -846,13 +853,7 @@ void event_configure_notify (Window win)
}
}
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)

View file

@ -144,10 +144,15 @@ int window_get_monitor (Window win)
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)

View file

@ -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);