From e113080a0e2c628bb1b6d3cd3d163557fee6bbe7 Mon Sep 17 00:00:00 2001 From: o9000 Date: Sun, 22 Mar 2015 16:07:04 +0000 Subject: [PATCH] Tentative to sort tasks on taskbar (disabled) - issue 478 git-svn-id: http://tint2.googlecode.com/svn/trunk@738 121b4492-b84c-0410-8b4c-0d4edfb3f3cc --- src/taskbar/task.c | 3 +++ src/taskbar/task.h | 3 +++ src/taskbar/taskbar.c | 47 +++++++++++++++++++++++++++++++++++++++++++ src/taskbar/taskbar.h | 3 +++ src/tint.c | 42 +++++++++++++++++++++----------------- src/util/window.c | 5 +++++ src/util/window.h | 1 + 7 files changed, 86 insertions(+), 18 deletions(-) diff --git a/src/taskbar/task.c b/src/taskbar/task.c index 449e372..9b154d7 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -63,6 +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); // allocate only one title and one icon // even with task_on_all_desktop and with task_on_all_panel @@ -115,6 +116,8 @@ 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); + if (panel_mode == MULTI_DESKTOP) { Panel *panel = new_tsk2->area.panel; panel->area.resize = 1; diff --git a/src/taskbar/task.h b/src/taskbar/task.h index 50eed31..a157e14 100644 --- a/src/taskbar/task.h +++ b/src/taskbar/task.h @@ -63,6 +63,9 @@ typedef struct { unsigned int icon_height; char *title; int urgent_tick; + // These may not be up-to-date + int win_x; + int win_y; } Task; diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index b99ee55..99a95c4 100644 --- a/src/taskbar/taskbar.c +++ b/src/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 @@ void default_taskbar() taskbar_distribute_size = 0; hide_inactive_tasks = 0; hide_task_diff_monitor = 0; + sort_tasks_method = TASKBAR_NOSORT; default_taskbarname(); } @@ -408,3 +410,48 @@ void visible_taskbar(void *p) 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; + } +} diff --git a/src/taskbar/taskbar.h b/src/taskbar/taskbar.h index 917d23f..84bf240 100644 --- a/src/taskbar/taskbar.h +++ b/src/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 @@ void set_taskbar_state(Taskbar *tskbar, int state); // show/hide taskbar according to current desktop void visible_taskbar(void *p); +void sort_tasks(Taskbar *taskbar); #endif diff --git a/src/tint.c b/src/tint.c index ae0692e..5ebf9e2 100644 --- a/src/tint.c +++ b/src/tint.c @@ -827,25 +827,31 @@ void event_configure_notify (Window win) } // 'win' move in another monitor - if (nb_panel == 1 && !hide_task_diff_monitor) - return; - - Task *tsk = task_get_task (win); - if (!tsk) - return; - - 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 (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; + } + } + } + + 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; } } diff --git a/src/util/window.c b/src/util/window.c index eb686d9..f0cd867 100644 --- a/src/util/window.c +++ b/src/util/window.c @@ -144,6 +144,11 @@ int window_get_monitor (Window win) 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) { diff --git a/src/util/window.h b/src/util/window.h index 0b4ded4..7883e59 100644 --- a/src/util/window.h +++ b/src/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);