From 5376e09963769cfa883b12b750d9991fd5bcff21 Mon Sep 17 00:00:00 2001 From: o9000 Date: Sat, 28 Mar 2015 21:07:33 +0000 Subject: [PATCH] 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 --- src/taskbar/task.c | 8 ++++++-- src/taskbar/task.h | 2 ++ src/taskbar/taskbar.c | 35 ++++++++++++++++++++++++++++++++--- src/taskbar/taskbar.h | 1 + src/tint.c | 15 ++++++++------- src/util/window.c | 11 ++++++++--- src/util/window.h | 2 +- 7 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/taskbar/task.c b/src/taskbar/task.c index 9b154d7..ec129a6 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -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; diff --git a/src/taskbar/task.h b/src/taskbar/task.h index a157e14..c2938ae 100644 --- a/src/taskbar/task.h +++ b/src/taskbar/task.h @@ -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; diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 99a95c4..72d3f04 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -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); + } + } + } +} diff --git a/src/taskbar/taskbar.h b/src/taskbar/taskbar.h index 84bf240..7874199 100644 --- a/src/taskbar/taskbar.h +++ b/src/taskbar/taskbar.h @@ -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 diff --git a/src/tint.c b/src/tint.c index 5ebf9e2..1ca11a5 100644 --- a/src/tint.c +++ b/src/tint.c @@ -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) diff --git a/src/util/window.c b/src/util/window.c index f0cd867..543bf15 100644 --- a/src/util/window.c +++ b/src/util/window.c @@ -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) diff --git a/src/util/window.h b/src/util/window.h index 7883e59..de90e9b 100644 --- a/src/util/window.h +++ b/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);