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

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

View File

@@ -430,18 +430,51 @@ gboolean resize_taskbar(void *obj)
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)
{
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 +492,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

@@ -79,10 +79,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
@@ -1203,6 +1204,8 @@ void event_property_notify(XEvent *e)
add_urgent(task);
}
XFree(wmhints);
task_update_icon(task);
panel_refresh = TRUE;
}
if (!server.got_root_win)