Add behavior to hide an empty taskbar in multi_desktop mode: fix TODO and fix panel resize

This commit is contained in:
Benoit Averty 2016-09-04 15:33:33 +02:00
parent 8976f35c5f
commit d765190e3d
2 changed files with 27 additions and 16 deletions

View file

@ -394,7 +394,11 @@ gboolean resize_panel(void *obj)
int total_size = 0; int total_size = 0;
int total_name_size = 0; int total_name_size = 0;
int total_items = 0; int total_items = 0;
int visible_taskbars = 0;
for (int i = 0; i < panel->num_desktops; i++) { for (int i = 0; i < panel->num_desktops; i++) {
if (!panel->taskbar[i].area.on_screen)
continue;
visible_taskbars++;
if (panel_horizontal) { if (panel_horizontal) {
total_size += panel->taskbar[i].area.width; total_size += panel->taskbar[i].area.width;
} else { } else {
@ -426,14 +430,16 @@ gboolean resize_panel(void *obj)
if (total_items) { if (total_items) {
int actual_name_size; int actual_name_size;
if (total_name_size <= total_size) { if (total_name_size <= total_size) {
actual_name_size = total_name_size / panel->num_desktops; actual_name_size = total_name_size / visible_taskbars;
} else { } else {
actual_name_size = total_size / panel->num_desktops; actual_name_size = total_size / visible_taskbars;
} }
total_size -= total_name_size; total_size -= total_name_size;
for (int i = 0; i < panel->num_desktops; i++) { for (int i = 0; i < panel->num_desktops; i++) {
Taskbar *taskbar = &panel->taskbar[i]; Taskbar *taskbar = &panel->taskbar[i];
if (!taskbar->area.on_screen)
continue;
int requested_size = (panel_horizontal ? left_right_border_width(&taskbar->area) int requested_size = (panel_horizontal ? left_right_border_width(&taskbar->area)
: top_bottom_border_width(&taskbar->area)) + : top_bottom_border_width(&taskbar->area)) +

View file

@ -430,24 +430,30 @@ gboolean resize_taskbar(void *obj)
return FALSE; return FALSE;
} }
gboolean taskbar_is_empty(Taskbar *taskbar)
{
GList *l = taskbar->area.children;
if (taskbarname_enabled)
l = l->next;
for (; l != NULL; l = l->next) {
if (((Task *)l->data)->area.on_screen) {
return TRUE;
}
}
return FALSE;
}
void update_one_taskbar_visibility(Taskbar *taskbar) void update_one_taskbar_visibility(Taskbar *taskbar)
{ {
//TODO handle hidden name
gboolean taskbar_non_empty = g_list_length(taskbar->area.children) > 1;
if (taskbar->desktop == server.desktop) { if (taskbar->desktop == server.desktop) {
// Taskbar for current desktop is always shown // Taskbar for current desktop is always shown
taskbar->area.on_screen = TRUE; show(&taskbar->area);
} } else if (taskbar_mode == MULTI_DESKTOP && taskbar_is_empty(taskbar)) {
else if (taskbar_mode == MULTI_DESKTOP && taskbar_non_empty) {
// MULTI_DESKTOP : show non-empty taskbars // MULTI_DESKTOP : show non-empty taskbars
taskbar->area.on_screen = TRUE; show(&taskbar->area);
} else {
hide(&taskbar->area);
} }
else {
taskbar->area.on_screen = FALSE;
}
panel_refresh = TRUE;
} }
void update_all_taskbars_visibility() void update_all_taskbars_visibility()
@ -458,7 +464,6 @@ void update_all_taskbars_visibility()
update_one_taskbar_visibility(&panel->taskbar[j]); update_one_taskbar_visibility(&panel->taskbar[j]);
} }
} }
panel_refresh = TRUE;
} }
void set_taskbar_state(Taskbar *taskbar, TaskbarState state) void set_taskbar_state(Taskbar *taskbar, TaskbarState state)