all repos — tint2 @ 1d15c41c1b56fb23375cefcdebca8b800ae1263e

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

Fix resizing logic (taskbar_distribute_size was broken, resizing triggered unnecessary redraws)
o9000 mrovi9000@gmail.com
commit

1d15c41c1b56fb23375cefcdebca8b800ae1263e

parent

0d861ebd97cf128ce575dabce5eb8241d12883e0

M src/battery/battery.csrc/battery/battery.c

@@ -243,22 +243,12 @@

for (int i = 0; i < num_panels; i++) { // Show/hide if needed if (!battery_found) { - if (panels[i].battery.area.on_screen) { - hide(&panels[i].battery.area); - panel_refresh = TRUE; - } + hide(&panels[i].battery.area); } else { - if (battery_state.percentage >= percentage_hide) { - if (panels[i].battery.area.on_screen) { - hide(&panels[i].battery.area); - panel_refresh = TRUE; - } - } else { - if (!panels[i].battery.area.on_screen) { - show(&panels[i].battery.area); - panel_refresh = TRUE; - } - } + if (battery_state.percentage >= percentage_hide) + hide(&panels[i].battery.area); + else + show(&panels[i].battery.area); } // Redraw if needed if (panels[i].battery.area.on_screen) {
M src/launcher/launcher.csrc/launcher/launcher.c

@@ -524,8 +524,7 @@ launcherIcon->icon_tooltip = g_strdup_printf("%s", entry.exec);

} } launcher_reload_icon_image(launcher, launcherIcon); - if (!launcherIcon->area.on_screen) - show(&launcherIcon->area); + show(&launcherIcon->area); } else { hide(&launcherIcon->area); }
M src/panel.csrc/panel.c

@@ -365,11 +365,11 @@ panel->posx = server.monitors[panel->monitor].x + panel->marginx;

} else { if (panel_position & RIGHT) { panel->posx = server.monitors[panel->monitor].x + server.monitors[panel->monitor].width - - panel->area.width - panel->marginx; + panel->area.width - panel->marginx; } else { if (panel_horizontal) panel->posx = server.monitors[panel->monitor].x + - ((server.monitors[panel->monitor].width - panel->area.width) / 2); + ((server.monitors[panel->monitor].width - panel->area.width) / 2); else panel->posx = server.monitors[panel->monitor].x + panel->marginx; }

@@ -379,10 +379,10 @@ panel->posy = server.monitors[panel->monitor].y + panel->marginy;

} else { if (panel_position & BOTTOM) { panel->posy = server.monitors[panel->monitor].y + server.monitors[panel->monitor].height - - panel->area.height - panel->marginy; + panel->area.height - panel->marginy; } else { panel->posy = - server.monitors[panel->monitor].y + ((server.monitors[panel->monitor].height - panel->area.height) / 2); + server.monitors[panel->monitor].y + ((server.monitors[panel->monitor].height - panel->area.height) / 2); } }

@@ -416,96 +416,101 @@ // propagate width/height on hidden taskbar

int width = panel->taskbar[server.desktop].area.width; int height = panel->taskbar[server.desktop].area.height; for (int i = 0; i < panel->num_desktops; i++) { + panel->taskbar[i].area.resize_needed = + panel->taskbar[i].area.width != width || panel->taskbar[i].area.height != height; panel->taskbar[i].area.width = width; panel->taskbar[i].area.height = height; - panel->taskbar[i].area.resize_needed = 1; } - } - if (taskbar_mode == MULTI_DESKTOP && taskbar_enabled && taskbar_distribute_size) { - // Distribute the available space between taskbars + } else if (taskbar_mode == MULTI_DESKTOP && taskbar_enabled && taskbar_distribute_size) { + for (int i = 0; i < panel->num_desktops; i++) { + Taskbar *taskbar = &panel->taskbar[i]; + taskbar->area.old_width = taskbar->area.width; + taskbar->area.old_height = taskbar->area.height; + } - // Compute the total available size, and the total size requested by the taskbars + // The total available size 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) + Taskbar *taskbar = &panel->taskbar[i]; + if (!taskbar->area.on_screen) continue; - visible_taskbars++; - if (panel_horizontal) { - total_size += panel->taskbar[i].area.width; - } else { - total_size += panel->taskbar[i].area.height; - } + total_size += panel_horizontal ? taskbar->area.width : taskbar->area.height; + } + // Reserve size for padding, taskbarname and spacings + for (int i = 0; i < panel->num_desktops; i++) { Taskbar *taskbar = &panel->taskbar[i]; - GList *l; - for (l = taskbar->area.children; l; l = l->next) { + if (!taskbar->area.on_screen) + continue; + if (!taskbar->area.children) + continue; + if (panel_horizontal) + taskbar->area.width = 2 * taskbar->area.paddingxlr; + else + taskbar->area.height = 2 * taskbar->area.paddingxlr; + if (taskbarname_enabled && taskbar->area.children) { + Area *name = (Area *)taskbar->area.children->data; + if (name->on_screen) { + if (panel_horizontal) + taskbar->area.width += name->width; + else + taskbar->area.height += name->height; + } + } + gboolean first_child = TRUE; + for (GList *l = taskbar->area.children; l; l = l->next) { Area *child = (Area *)l->data; if (!child->on_screen) continue; - total_items++; - } - if (taskbarname_enabled) { - if (taskbar->area.children) { - total_items--; - Area *name = (Area *)taskbar->area.children->data; - if (panel_horizontal) { - total_name_size += name->width; - } else { - total_name_size += name->height; - } + if (!first_child) { + if (panel_horizontal) + taskbar->area.width += taskbar->area.paddingx; + else + taskbar->area.height += taskbar->area.paddingy; } + first_child = FALSE; } + total_size -= panel_horizontal ? taskbar->area.width : taskbar->area.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 / visible_taskbars; - } else { - actual_name_size = total_size / visible_taskbars; + + // Compute the total number of tasks + int num_tasks = 0; + for (int i = 0; i < panel->num_desktops; i++) { + Taskbar *taskbar = &panel->taskbar[i]; + if (!taskbar->area.on_screen) + continue; + for (GList *l = taskbar->area.children; l; l = l->next) { + Area *child = (Area *)l->data; + if (!child->on_screen) + continue; + if (taskbarname_enabled && l == taskbar->area.children) + continue; + num_tasks++; } - total_size -= total_name_size; + } - for (int i = 0; i < panel->num_desktops; i++) { - Taskbar *taskbar = &panel->taskbar[i]; - if (!taskbar->area.on_screen) + // Distribute the remaining size between tasks + int task_size = total_size / MAX(num_tasks, 1); + for (int i = 0; i < panel->num_desktops; i++) { + Taskbar *taskbar = &panel->taskbar[i]; + if (!taskbar->area.on_screen) + continue; + for (GList *l = taskbar->area.children; l; l = l->next) { + Area *child = (Area *)l->data; + if (!child->on_screen) + continue; + if (taskbarname_enabled && l == taskbar->area.children) continue; - - int requested_size = (panel_horizontal ? left_right_border_width(&taskbar->area) - : top_bottom_border_width(&taskbar->area)) + - 2 * taskbar->area.paddingxlr; - int items = 0; - GList *l = taskbar->area.children; - if (taskbarname_enabled) - l = l->next; - for (; l; l = l->next) { - Area *child = (Area *)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_needed = 1; + if (panel_horizontal) + taskbar->area.width += task_size; + else + taskbar->area.height += task_size; } + } + for (int i = 0; i < panel->num_desktops; i++) { + Taskbar *taskbar = &panel->taskbar[i]; + taskbar->area.resize_needed = + taskbar->area.old_width != taskbar->area.width || taskbar->area.old_height != taskbar->area.height; } } for (GList *l = panel->freespace_list; l; l = g_list_next(l))

@@ -691,35 +696,35 @@

if (!panel->is_hidden) { if (panel_horizontal) { XMoveResizeWindow(server.display, - panel->main_win, - panel->posx, - panel->posy, - panel->area.width, - panel->area.height); + panel->main_win, + panel->posx, + panel->posy, + panel->area.width, + panel->area.height); } else { XMoveResizeWindow(server.display, - panel->main_win, - panel->posx, - panel->posy, - panel->area.width, - panel->area.height); + panel->main_win, + panel->posx, + panel->posy, + panel->area.width, + panel->area.height); } } else { int diff = (panel_horizontal ? panel->area.height : panel->area.width) - panel_autohide_height; if (panel_horizontal) { XMoveResizeWindow(server.display, - panel->main_win, - panel->posx, - panel->posy + diff, - panel->hidden_width, - panel->hidden_height); + panel->main_win, + panel->posx, + panel->posy + diff, + panel->hidden_width, + panel->hidden_height); } else { XMoveResizeWindow(server.display, - panel->main_win, - panel->posx + diff, - panel->posy, - panel->hidden_width, - panel->hidden_height); + panel->main_win, + panel->posx + diff, + panel->posy, + panel->hidden_width, + panel->hidden_height); } } }
M src/systray/systraybar.csrc/systray/systraybar.c

@@ -701,8 +701,7 @@ traywin->name = name;

traywin->chrono = chrono; chrono++; - if (!systray.area.on_screen) - show(&systray.area); + show(&systray.area); if (systray.sort == SYSTRAY_SORT_RIGHT2LEFT) systray.list_icons = g_slist_prepend(systray.list_icons, traywin);
M src/taskbar/task.csrc/taskbar/task.c

@@ -152,6 +152,9 @@ if (window_is_urgent(win)) {

add_urgent((Task *)g_ptr_array_index(task_buttons, 0)); } + if (hide_taskbar_if_empty) + update_all_taskbars_visibility(); + return (Task *)g_ptr_array_index(task_buttons, 0); }

@@ -206,6 +209,8 @@ remove_area((Area *)task2);

free(task2); } g_hash_table_remove(win_to_task, &win); + if (hide_taskbar_if_empty) + update_all_taskbars_visibility(); } gboolean task_update_title(Task *task)
M src/taskbar/taskbar.csrc/taskbar/taskbar.c

@@ -426,7 +426,7 @@ {

Taskbar *taskbar = (Taskbar *)obj; Panel *panel = (Panel *)taskbar->area.panel; - if (taskbar_mode == MULTI_DESKTOP && !taskbar_distribute_size && !hide_taskbar_if_empty) { + if (taskbar_mode == MULTI_DESKTOP && !taskbar_distribute_size) { int result = 0; for (int i = 0; i < panel->num_desktops; i++) { Taskbar *t = &panel->taskbar[i];
M src/util/area.csrc/util/area.c

@@ -392,6 +392,8 @@ void hide(Area *a)

{ Area *parent = (Area *)a->parent; + if (!a->on_screen) + return; a->on_screen = FALSE; if (parent) parent->resize_needed = TRUE;

@@ -405,10 +407,13 @@ void show(Area *a)

{ Area *parent = (Area *)a->parent; + if (a->on_screen) + return; a->on_screen = TRUE; if (parent) parent->resize_needed = TRUE; a->resize_needed = TRUE; + panel_refresh = TRUE; } void update_dependent_gradients(Area *a)
M src/util/area.hsrc/util/area.h

@@ -172,6 +172,7 @@ // Position relative to the panel window

int posx, posy; // Size, including borders int width, height; + int old_width, old_height; Background *bg; // Each element is a pointer to a GradientClass (list can be empty), no ownership GList *gradients;