Merge branch 'hide_empty_taskbars' into 'master'

Add behavior to hide an empty taskbar in multi_desktop mode

- [x] Hide empty taskbar
- [x] Handle case when workspace name is not showing
- [x] Make it configurable
- [x] Fix bugs
    - [x] Size issue when removing taskbars
    - [x] Overlapping taskbars (?)

See merge request !17
This commit is contained in:
o9000 2016-09-10 20:51:06 +00:00
commit 047c59b53f
5 changed files with 61 additions and 31 deletions

View file

@ -771,6 +771,8 @@ void add_entry(char *key, char *value)
hide_inactive_tasks = atoi(value);
} else if (strcmp(key, "taskbar_hide_different_monitor") == 0) {
hide_task_diff_monitor = atoi(value);
} else if (strcmp(key, "taskbar_hide_if_empty") == 0) {
hide_taskbar_if_empty = atoi(value);
} else if (strcmp(key, "taskbar_always_show_all_desktop_tasks") == 0) {
always_show_all_desktop_tasks = atoi(value);
} else if (strcmp(key, "taskbar_sort_order") == 0) {

View file

@ -269,12 +269,11 @@ void init_panel()
if (panel_autohide)
autohide_trigger_hide(p);
update_taskbar_visibility(p);
}
taskbar_refresh_tasklist();
reset_active_task();
update_all_taskbars_visibility();
}
void init_panel_size_and_position(Panel *panel)
@ -395,7 +394,11 @@ gboolean resize_panel(void *obj)
int total_size = 0;
int total_name_size = 0;
int total_items = 0;
int visible_taskbars = 0;
for (int i = 0; i < panel->num_desktops; i++) {
if (!panel->taskbar[i].area.on_screen)
continue;
visible_taskbars++;
if (panel_horizontal) {
total_size += panel->taskbar[i].area.width;
} else {
@ -427,14 +430,16 @@ gboolean resize_panel(void *obj)
if (total_items) {
int actual_name_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 {
actual_name_size = total_size / panel->num_desktops;
actual_name_size = total_size / visible_taskbars;
}
total_size -= total_name_size;
for (int i = 0; i < panel->num_desktops; i++) {
Taskbar *taskbar = &panel->taskbar[i];
if (!taskbar->area.on_screen)
continue;
int requested_size = (panel_horizontal ? left_right_border_width(&taskbar->area)
: top_bottom_border_width(&taskbar->area)) +

View file

@ -41,6 +41,7 @@ gboolean taskbar_enabled;
gboolean taskbar_distribute_size;
gboolean hide_inactive_tasks;
gboolean hide_task_diff_monitor;
gboolean hide_taskbar_if_empty;
gboolean always_show_all_desktop_tasks;
TaskbarSortMethod taskbar_sort_method;
Alignment taskbar_alignment;
@ -74,6 +75,7 @@ void default_taskbar()
taskbar_distribute_size = FALSE;
hide_inactive_tasks = FALSE;
hide_task_diff_monitor = FALSE;
hide_taskbar_if_empty = FALSE;
always_show_all_desktop_tasks = FALSE;
taskbar_sort_method = TASKBAR_NOSORT;
taskbar_alignment = ALIGN_LEFT;
@ -169,7 +171,7 @@ void init_taskbar_panel(void *p)
if (panel_horizontal) {
panel->g_taskbar.area.posy = top_border_width(&panel->area) + panel->area.paddingy;
panel->g_taskbar.area.height =
panel->area.height - top_bottom_border_width(&panel->area) - 2 * panel->area.paddingy;
panel->area.height - top_bottom_border_width(&panel->area) - 2 * panel->area.paddingy;
panel->g_taskbar.area_name.posy = panel->g_taskbar.area.posy;
panel->g_taskbar.area_name.height = panel->g_taskbar.area.height;
} else {
@ -430,18 +432,52 @@ gboolean resize_taskbar(void *obj)
return FALSE;
}
gboolean taskbar_is_not_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)
{
if (taskbar->desktop == server.desktop) {
// Taskbar for current desktop is always shown
show(&taskbar->area);
}
else if (taskbar_mode == MULTI_DESKTOP && (taskbar_is_not_empty(taskbar) || hide_taskbar_if_empty == FALSE)) {
// MULTI_DESKTOP : show non-empty taskbars
show(&taskbar->area);
} else {
hide(&taskbar->area);
}
}
void update_all_taskbars_visibility()
{
for (int i = 0; i < num_panels; i++) {
Panel *panel = &panels[i];
for (int j = 0; j < panel->num_desktops; j++) {
update_one_taskbar_visibility(&panel->taskbar[j]);
}
}
}
void set_taskbar_state(Taskbar *taskbar, TaskbarState state)
{
taskbar->area.bg = panels[0].g_taskbar.background[state];
if (taskbarname_enabled) {
taskbar->bar_name.area.bg = panels[0].g_taskbar.background_name[state];
}
if (taskbar_mode != MULTI_DESKTOP) {
if (state == TASKBAR_NORMAL)
taskbar->area.on_screen = FALSE;
else
taskbar->area.on_screen = TRUE;
}
update_one_taskbar_visibility(taskbar);
if (taskbar->area.on_screen) {
schedule_redraw(&taskbar->area);
if (taskbarname_enabled) {
@ -459,22 +495,6 @@ void set_taskbar_state(Taskbar *taskbar, TaskbarState state)
panel_refresh = TRUE;
}
void update_taskbar_visibility(void *p)
{
Panel *panel = (Panel *)p;
for (int j = 0; j < panel->num_desktops; j++) {
Taskbar *taskbar = &panel->taskbar[j];
if (taskbar_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) {
// SINGLE_DESKTOP and not current desktop
taskbar->area.on_screen = FALSE;
} else {
taskbar->area.on_screen = TRUE;
}
}
panel_refresh = TRUE;
}
#define NONTRIVIAL 2
gint compare_tasks_trivial(Task *a, Task *b, Taskbar *taskbar)
{

View file

@ -49,6 +49,7 @@ extern gboolean taskbar_enabled;
extern gboolean taskbar_distribute_size;
extern gboolean hide_inactive_tasks;
extern gboolean hide_task_diff_monitor;
extern gboolean hide_taskbar_if_empty;
extern gboolean always_show_all_desktop_tasks;
extern TaskbarSortMethod taskbar_sort_method;
extern Alignment taskbar_alignment;
@ -79,10 +80,11 @@ Task *get_task(Window win);
// However for windows shown on all desktops, there are multiple buttons, one for each taskbar.
GPtrArray *get_task_buttons(Window win);
// Change state of a taskbar (ACTIVE or NORMAL)
void set_taskbar_state(Taskbar *taskbar, TaskbarState state);
// Updates the visibility of each taskbar when the current desktop changes.
void update_taskbar_visibility(void *p);
// Updates the visibility of all taskbars
void update_all_taskbars_visibility();
// Sorts the taskbar(s) on which the window is present.
void sort_taskbar_for_win(Window win);

View file

@ -1010,7 +1010,7 @@ void event_property_notify(XEvent *e)
int old_desktop = server.desktop;
server_get_number_of_desktops();
server.desktop = get_current_desktop();
if (old_num_desktops != server.num_desktops) {
if (old_num_desktops != server.num_desktops) { // If number of desktop changed
if (server.num_desktops <= server.desktop) {
server.desktop = server.num_desktops - 1;
}
@ -1019,11 +1019,11 @@ void event_property_notify(XEvent *e)
for (int i = 0; i < num_panels; i++) {
init_taskbar_panel(&panels[i]);
set_panel_items_order(&panels[i]);
update_taskbar_visibility(&panels[i]);
panels[i].area.resize_needed = 1;
}
taskbar_refresh_tasklist();
reset_active_task();
update_all_taskbars_visibility();
panel_refresh = TRUE;
} else if (old_desktop != server.desktop) {
for (int i = 0; i < num_panels; i++) {
@ -1092,6 +1092,7 @@ void event_property_notify(XEvent *e)
if (debug)
fprintf(stderr, "%s %d: win = root, atom = _NET_CLIENT_LIST\n", __FUNCTION__, __LINE__);
taskbar_refresh_tasklist();
update_all_taskbars_visibility();
panel_refresh = TRUE;
}
// Change active