all repos — tint2 @ 047c59b53f80a8066ba42c95614d0edbe663d85c

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

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
o9000 mrovi9000@gmail.com
commit

047c59b53f80a8066ba42c95614d0edbe663d85c

parent

008eebe4b1238c827e76b8c77aee1231f61a748f

5 files changed, 61 insertions(+), 31 deletions(-)

jump to
M src/config.csrc/config.c

@@ -771,6 +771,8 @@ } else if (strcmp(key, "taskbar_hide_inactive_tasks") == 0) {

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) {
M src/panel.csrc/panel.c

@@ -269,12 +269,11 @@ }

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 @@ // 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 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 @@ // 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->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)) +
M src/taskbar/taskbar.csrc/taskbar/taskbar.c

@@ -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 @@ taskbar_enabled = FALSE;

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 @@ panel->g_taskbar.area.on_screen = TRUE;

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 @@ }

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) {

@@ -454,22 +490,6 @@ if (taskbarname_enabled)

l = l->next; for (; l; l = l->next) schedule_redraw((Area *)l->data); - } - } - 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;
M src/taskbar/taskbar.hsrc/taskbar/taskbar.h

@@ -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 @@ // Returns the task buttons for this window, usually having only one element.

// 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);
M src/tint.csrc/tint.c

@@ -1010,7 +1010,7 @@ int old_num_desktops = server.num_desktops;

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 @@ init_taskbar();

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 @@ else if (at == server.atom._NET_CLIENT_LIST) {

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