Tentative to sort tasks on taskbar (disabled) - issue 478
git-svn-id: http://tint2.googlecode.com/svn/trunk@738 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
5faf063f96
commit
e113080a0e
7 changed files with 86 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
42
src/tint.c
42
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue