Taskbar: add option to redistribute size in multi-desktop mode (useful especially when the taskbar is getting full on one desktop)

git-svn-id: http://tint2.googlecode.com/svn/trunk@673 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
o9000 2015-01-30 09:53:16 +00:00 committed by mrovi9000@gmail.com
parent 88e0e4fed8
commit 4e76c2bb5d
8 changed files with 112 additions and 4 deletions

View file

@ -413,6 +413,9 @@ void add_entry (char *key, char *value)
if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
else panel_mode = SINGLE_DESKTOP;
}
else if (strcmp (key, "taskbar_distribute_size") == 0) {
taskbar_distribute_size = atoi(value);
}
else if (strcmp (key, "taskbar_padding") == 0) {
extract_values(value, &value1, &value2, &value3);
panel_config.g_taskbar.area.paddingxlr = panel_config.g_taskbar.area.paddingx = atoi (value1);

View file

@ -322,6 +322,87 @@ int resize_panel(void *obj)
panel->taskbar[i].area.resize = 1;
}
}
if (panel_mode == MULTI_DESKTOP && taskbar_enabled && taskbar_distribute_size) {
// Distribute the available space between taskbars
Panel *panel = (Panel*)obj;
// Compute the total available size, and the total size requested by the taskbars
int total_size = 0;
int total_name_size = 0;
int total_items = 0;
int i;
for (i = 0; i < panel->nb_desktop; i++) {
if (panel_horizontal) {
total_size += panel->taskbar[i].area.width;
} else {
total_size += panel->taskbar[i].area.height;
}
Taskbar *taskbar = &panel->taskbar[i];
GSList *l;
for (l = taskbar->area.list; l; l = l->next) {
Area *child = l->data;
if (!child->on_screen)
continue;
total_items++;
}
if (taskbarname_enabled) {
if (taskbar->area.list) {
total_items--;
Area *name = taskbar->area.list->data;
if (panel_horizontal) {
total_name_size += name->width;
} else {
total_name_size += name->height;
}
}
}
}
// Distribute the space proportionally to the requested size (that is, to the
// number of tasks in each taskbar)
if (total_items) {
int actual_name_size;
if (total_name_size <= total_size) {
actual_name_size = total_name_size / panel->nb_desktop;
} else {
actual_name_size = total_size / panel->nb_desktop;
}
total_size -= total_name_size;
for (i = 0; i < panel->nb_desktop; i++) {
Taskbar *taskbar = &panel->taskbar[i];
int requested_size = (2 * taskbar->area.bg->border.width) + (2 * taskbar->area.paddingxlr);
int items = 0;
GSList *l = taskbar->area.list;
if (taskbarname_enabled)
l = l->next;
for (; l; l = l->next) {
Area *child = l->data;
if (!child->on_screen)
continue;
items++;
if (panel_horizontal) {
requested_size += child->width + taskbar->area.paddingy;
} else {
requested_size += child->height + taskbar->area.paddingx;
}
}
if (panel_horizontal) {
requested_size -= taskbar->area.paddingy;
} else {
requested_size -= taskbar->area.paddingx;
}
if (panel_horizontal) {
taskbar->area.width = actual_name_size + items / (float)total_items * total_size;
} else {
taskbar->area.height = actual_name_size + items / (float)total_items * total_size;
}
taskbar->area.resize = 1;
}
}
}
return 0;
}

View file

@ -150,6 +150,6 @@ void get_root_pixmap();
// detect monitors and desktops
void get_monitors();
void get_desktops();
int server_get_number_of_desktop();
#endif

View file

@ -118,6 +118,11 @@ Task *add_task (Window win)
if (window_is_urgent(win))
add_urgent(new_tsk2);
if (panel_mode == MULTI_DESKTOP) {
Panel *panel = new_tsk2->area.panel;
panel->area.resize = 1;
}
return new_tsk2;
}
@ -126,6 +131,11 @@ void remove_task (Task *tsk)
{
if (!tsk) return;
if (panel_mode == MULTI_DESKTOP) {
Panel *panel = tsk->area.panel;
panel->area.resize = 1;
}
Window win = tsk->win;
// free title and icon just for the first task

View file

@ -42,6 +42,7 @@ GHashTable* win_to_task_table;
Task *task_active;
Task *task_drag;
int taskbar_enabled;
int taskbar_distribute_size;
guint win_hash(gconstpointer key) { return (guint)*((Window*)key); }
gboolean win_compare(gconstpointer a, gconstpointer b) { return (*((Window*)a) == *((Window*)b)); }
@ -54,6 +55,7 @@ void default_taskbar()
urgent_timeout = 0;
urgent_list = 0;
taskbar_enabled = 0;
taskbar_distribute_size = 0;
default_taskbarname();
}
@ -321,8 +323,11 @@ int resize_taskbar(void *obj)
text_width = panel->g_task.maximum_width;
GSList *l = taskbar->area.list;
if (taskbarname_enabled) l = l->next;
if (l != NULL) {
text_width = ((Task *)l->data)->area.width;
for (; l != NULL; l = l->next) {
if (((Task *)l->data)->area.on_screen) {
text_width = ((Task *)l->data)->area.width;
break;
}
}
taskbar->text_width = text_width - panel->g_task.text_posx - panel->g_task.area.bg->border.width - panel->g_task.area.paddingx;
}

View file

@ -16,7 +16,7 @@ extern GHashTable* win_to_task_table;
extern Task *task_active;
extern Task *task_drag;
extern int taskbar_enabled;
extern int taskbar_distribute_size;
typedef struct {
// always start with area

View file

@ -461,6 +461,7 @@ void event_button_motion_notify (XEvent *e)
drag_taskbar->area.resize = 1;
task_dragged = 1;
panel_refresh = 1;
panel->area.resize = 1;
}
}
@ -634,6 +635,8 @@ void event_property_notify (XEvent *e)
tsk->area.on_screen = 0;
tskbar->area.resize = 1;
panel_refresh = 1;
if (panel_mode == MULTI_DESKTOP)
panel->area.resize = 1;
}
}
}
@ -645,6 +648,8 @@ void event_property_notify (XEvent *e)
if (tsk->desktop == ALLDESKTOP) {
tsk->area.on_screen = 1;
tskbar->area.resize = 1;
if (panel_mode == MULTI_DESKTOP)
panel->area.resize = 1;
}
}
}

View file

@ -82,11 +82,15 @@ void init_rendering(void *obj, int pos)
if (panel_horizontal) {
child->posy = pos + a->bg->border.width + a->paddingy;
child->height = a->height - (2 * (a->bg->border.width + a->paddingy));
if (child->_on_change_layout)
child->_on_change_layout(child);
init_rendering(child, child->posy);
}
else {
child->posx = pos + a->bg->border.width + a->paddingy;
child->width = a->width - (2 * (a->bg->border.width + a->paddingy));
if (child->_on_change_layout)
child->_on_change_layout(child);
init_rendering(child, child->posx);
}
}