Compare commits

...

3 Commits

5 changed files with 81 additions and 47 deletions

View File

@@ -269,12 +269,11 @@ void init_panel()
if (panel_autohide) if (panel_autohide)
autohide_trigger_hide(p); autohide_trigger_hide(p);
update_taskbar_visibility(p);
} }
taskbar_refresh_tasklist(); taskbar_refresh_tasklist();
reset_active_task(); reset_active_task();
update_all_taskbars_visibility();
} }
void init_panel_size_and_position(Panel *panel) void init_panel_size_and_position(Panel *panel)
@@ -395,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 {
@@ -427,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

@@ -268,21 +268,26 @@ void task_update_icon(Task *task)
Imlib_Image img = NULL; Imlib_Image img = NULL;
int i; if (!img) {
gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &i); int i;
if (data) { gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &i);
// get ARGB icon if (data) {
int w, h; // get ARGB icon
gulong *tmp_data; int w, h;
gulong *tmp_data;
tmp_data = get_best_icon(data, get_icon_count(data, i), i, &w, &h, panel->g_task.icon_size1); tmp_data = get_best_icon(data, get_icon_count(data, i), i, &w, &h, panel->g_task.icon_size1);
DATA32 icon_data[w * h]; DATA32 icon_data[w * h];
for (int j = 0; j < w * h; ++j) for (int j = 0; j < w * h; ++j)
icon_data[j] = tmp_data[j]; icon_data[j] = tmp_data[j];
img = imlib_create_image_using_copied_data(w, h, icon_data); img = imlib_create_image_using_copied_data(w, h, icon_data);
XFree(data); if (img)
} else { fprintf(stderr, "%s: Got %dx%d icon via _NET_WM_ICON for %s\n", __FUNCTION__, w, h, task->title ? task->title : "task");
// get Pixmap icon XFree(data);
}
}
if (!img) {
XWMHints *hints = XGetWMHints(server.display, task->win); XWMHints *hints = XGetWMHints(server.display, task->win);
if (hints) { if (hints) {
if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) { if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
@@ -292,17 +297,20 @@ void task_update_icon(Task *task)
uint border_width, bpp; uint border_width, bpp;
uint w, h; uint w, h;
// printf(" get pixmap\n");
XGetGeometry(server.display, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp); XGetGeometry(server.display, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp);
imlib_context_set_drawable(hints->icon_pixmap); imlib_context_set_drawable(hints->icon_pixmap);
img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0); img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0);
if (img)
fprintf(stderr, "%s: Got %dx%d pixmap icon via WM_HINTS for %s\n", __FUNCTION__, w, h, task->title ? task->title : "task");
} }
XFree(hints); XFree(hints);
} }
} }
if (img == NULL) { if (img == NULL) {
imlib_context_set_image(default_icon); imlib_context_set_image(default_icon);
img = imlib_clone_image(); img = imlib_clone_image();
fprintf(stderr, "%s: Using default icon for %s\n", __FUNCTION__, task->title ? task->title : "task");
} }
// transform icons // transform icons
@@ -348,7 +356,7 @@ void task_update_icon(Task *task)
GPtrArray *task_buttons = get_task_buttons(task->win); GPtrArray *task_buttons = get_task_buttons(task->win);
if (task_buttons) { if (task_buttons) {
for (i = 0; i < task_buttons->len; ++i) { for (int i = 0; i < task_buttons->len; ++i) {
Task *task2 = g_ptr_array_index(task_buttons, i); Task *task2 = g_ptr_array_index(task_buttons, i);
task2->icon_width = task->icon_width; task2->icon_width = task->icon_width;
task2->icon_height = task->icon_height; task2->icon_height = task->icon_height;

View File

@@ -169,7 +169,7 @@ void init_taskbar_panel(void *p)
if (panel_horizontal) { if (panel_horizontal) {
panel->g_taskbar.area.posy = top_border_width(&panel->area) + panel->area.paddingy; panel->g_taskbar.area.posy = top_border_width(&panel->area) + panel->area.paddingy;
panel->g_taskbar.area.height = 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.posy = panel->g_taskbar.area.posy;
panel->g_taskbar.area_name.height = panel->g_taskbar.area.height; panel->g_taskbar.area_name.height = panel->g_taskbar.area.height;
} else { } else {
@@ -430,18 +430,51 @@ 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)
{
if (taskbar->desktop == server.desktop) {
// Taskbar for current desktop is always shown
show(&taskbar->area);
} else if (taskbar_mode == MULTI_DESKTOP && taskbar_is_empty(taskbar)) {
// 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) void set_taskbar_state(Taskbar *taskbar, TaskbarState state)
{ {
taskbar->area.bg = panels[0].g_taskbar.background[state]; taskbar->area.bg = panels[0].g_taskbar.background[state];
if (taskbarname_enabled) { if (taskbarname_enabled) {
taskbar->bar_name.area.bg = panels[0].g_taskbar.background_name[state]; taskbar->bar_name.area.bg = panels[0].g_taskbar.background_name[state];
} }
if (taskbar_mode != MULTI_DESKTOP) {
if (state == TASKBAR_NORMAL) update_one_taskbar_visibility(taskbar);
taskbar->area.on_screen = FALSE;
else
taskbar->area.on_screen = TRUE;
}
if (taskbar->area.on_screen) { if (taskbar->area.on_screen) {
schedule_redraw(&taskbar->area); schedule_redraw(&taskbar->area);
if (taskbarname_enabled) { if (taskbarname_enabled) {
@@ -459,22 +492,6 @@ void set_taskbar_state(Taskbar *taskbar, TaskbarState state)
panel_refresh = TRUE; 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 #define NONTRIVIAL 2
gint compare_tasks_trivial(Task *a, Task *b, Taskbar *taskbar) gint compare_tasks_trivial(Task *a, Task *b, Taskbar *taskbar)
{ {

View File

@@ -79,10 +79,11 @@ Task *get_task(Window win);
// However for windows shown on all desktops, there are multiple buttons, one for each taskbar. // However for windows shown on all desktops, there are multiple buttons, one for each taskbar.
GPtrArray *get_task_buttons(Window win); GPtrArray *get_task_buttons(Window win);
// Change state of a taskbar (ACTIVE or NORMAL)
void set_taskbar_state(Taskbar *taskbar, TaskbarState state); void set_taskbar_state(Taskbar *taskbar, TaskbarState state);
// Updates the visibility of each taskbar when the current desktop changes. // Updates the visibility of all taskbars
void update_taskbar_visibility(void *p); void update_all_taskbars_visibility();
// Sorts the taskbar(s) on which the window is present. // Sorts the taskbar(s) on which the window is present.
void sort_taskbar_for_win(Window win); void sort_taskbar_for_win(Window win);

View File

@@ -1010,7 +1010,7 @@ void event_property_notify(XEvent *e)
int old_desktop = server.desktop; int old_desktop = server.desktop;
server_get_number_of_desktops(); server_get_number_of_desktops();
server.desktop = get_current_desktop(); 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) { if (server.num_desktops <= server.desktop) {
server.desktop = server.num_desktops - 1; server.desktop = server.num_desktops - 1;
} }
@@ -1019,11 +1019,11 @@ void event_property_notify(XEvent *e)
for (int i = 0; i < num_panels; i++) { for (int i = 0; i < num_panels; i++) {
init_taskbar_panel(&panels[i]); init_taskbar_panel(&panels[i]);
set_panel_items_order(&panels[i]); set_panel_items_order(&panels[i]);
update_taskbar_visibility(&panels[i]);
panels[i].area.resize_needed = 1; panels[i].area.resize_needed = 1;
} }
taskbar_refresh_tasklist(); taskbar_refresh_tasklist();
reset_active_task(); reset_active_task();
update_all_taskbars_visibility();
panel_refresh = TRUE; panel_refresh = TRUE;
} else if (old_desktop != server.desktop) { } else if (old_desktop != server.desktop) {
for (int i = 0; i < num_panels; i++) { for (int i = 0; i < num_panels; i++) {
@@ -1092,6 +1092,7 @@ void event_property_notify(XEvent *e)
if (debug) if (debug)
fprintf(stderr, "%s %d: win = root, atom = _NET_CLIENT_LIST\n", __FUNCTION__, __LINE__); fprintf(stderr, "%s %d: win = root, atom = _NET_CLIENT_LIST\n", __FUNCTION__, __LINE__);
taskbar_refresh_tasklist(); taskbar_refresh_tasklist();
update_all_taskbars_visibility();
panel_refresh = TRUE; panel_refresh = TRUE;
} }
// Change active // Change active
@@ -1203,6 +1204,8 @@ void event_property_notify(XEvent *e)
add_urgent(task); add_urgent(task);
} }
XFree(wmhints); XFree(wmhints);
task_update_icon(task);
panel_refresh = TRUE;
} }
if (!server.got_root_win) if (!server.got_root_win)