void init_panel()
{
- int i, j;
+ int i;
Panel *p;
if (panel_config.monitor > (server.nb_monitor-1)) {
#ifdef ENABLE_BATTERY
init_battery();
#endif
+ init_taskbar();
// number of panels (one monitor or 'all' monitors)
if (panel_config.monitor >= 0)
p->g_taskbar.area.panel = p;
p->g_task.area.panel = p;
init_panel_size_and_position(p);
- // add childs occording to panel_items_order
- int k;
- for (k=0 ; k < strlen(panel_items_order) ; k++) {
- if (panel_items_order[k] == 'L') {
- init_launcher_panel(p);
- p->area.list = g_slist_append(p->area.list, &p->launcher);
- }
- if (panel_items_order[k] == 'T') {
- p->nb_desktop = server.nb_desktop;
- p->taskbar = calloc(p->nb_desktop, sizeof(Taskbar));
- for (j=0 ; j < p->nb_desktop ; j++) {
- p->area.list = g_slist_append(p->area.list, &p->taskbar[j]);
- }
- //printf("init taskbar\n");
- }
-#ifdef ENABLE_BATTERY
- if (panel_items_order[k] == 'B') {
- init_battery_panel(p);
- p->area.list = g_slist_append(p->area.list, &p->battery);
- }
-#endif
- if (panel_items_order[k] == 'S') {
- // TODO : check systray is only on 1 panel
- init_systray_panel(p);
- p->area.list = g_slist_append(p->area.list, &systray);
- refresh_systray = 1;
- }
- if (panel_items_order[k] == 'C') {
- init_clock_panel(p);
- p->area.list = g_slist_append(p->area.list, &p->clock);
- }
- }
+ // add childs according to panel_items
+ set_panel_items(p);
// catch some events
XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 };
}
panel_refresh = 1;
- init_taskbar();
visible_object();
task_refresh_tasklist();
active_task();
}
+void set_panel_items(Panel *p)
+{
+ int k, j;
+
+ if (p->area.list) {
+ g_slist_free(p->area.list);
+ p->area.list = 0;
+ }
+
+ for (k=0 ; k < strlen(panel_items_order) ; k++) {
+ if (panel_items_order[k] == 'L') {
+ init_launcher_panel(p);
+ p->area.list = g_slist_append(p->area.list, &p->launcher);
+ }
+ if (panel_items_order[k] == 'T') {
+ init_taskbar_panel(p);
+ for (j=0 ; j < p->nb_desktop ; j++)
+ p->area.list = g_slist_append(p->area.list, &p->taskbar[j]);
+ }
+#ifdef ENABLE_BATTERY
+ if (panel_items_order[k] == 'B') {
+ init_battery_panel(p);
+ p->area.list = g_slist_append(p->area.list, &p->battery);
+ }
+#endif
+ if (panel_items_order[k] == 'S') {
+ // TODO : check systray is only on 1 panel
+ init_systray_panel(p);
+ refresh_systray = 1;
+ p->area.list = g_slist_append(p->area.list, &systray);
+ }
+ if (panel_items_order[k] == 'C') {
+ init_clock_panel(p);
+ p->area.list = g_slist_append(p->area.list, &p->clock);
+ }
+ }
+}
+
+
void set_panel_properties(Panel *p)
{
XStoreName (server.dsp, p->main_win, "tint2");
systray.alpha = 100;
systray.brightness = systray.saturation = 0;
}
- systray.area.resize = 1;
- systray.area.redraw = 1;
- systray.area.on_screen = 1;
- refresh_systray = 0;
}
}
systray.area.parent = p;
systray.area.panel = p;
+
+ GSList *l;
+ int count = 0;
+ for (l = systray.list_icons; l ; l = l->next) {
+ if (!((TrayWindow*)l->data)->hide)
+ count++;
+ }
+ if (count == 0)
+ systray.area.on_screen = 0;
+ else
+ systray.area.on_screen = 1;
+ refresh_systray = 0;
}
//printf("count %d\n", count);
if (panel_horizontal) {
- if (!count) systray.area.width = 0;
- else {
- int height = sysbar->area.height - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
- // here icons_per_column always higher than 0
- icons_per_column = (height+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
- marging = height - (icons_per_column-1)*(icon_size+sysbar->area.paddingx) - icon_size;
- icons_per_row = count / icons_per_column + (count%icons_per_column != 0);
- systray.area.width = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_row) + ((icons_per_row-1) * systray.area.paddingx);
- }
+ int height = sysbar->area.height - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
+ // here icons_per_column always higher than 0
+ icons_per_column = (height+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
+ marging = height - (icons_per_column-1)*(icon_size+sysbar->area.paddingx) - icon_size;
+ icons_per_row = count / icons_per_column + (count%icons_per_column != 0);
+ systray.area.width = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_row) + ((icons_per_row-1) * systray.area.paddingx);
}
else {
- if (!count) systray.area.height = 0;
- else {
- int width = sysbar->area.width - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
- // here icons_per_row always higher than 0
- icons_per_row = (width+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
- marging = width - (icons_per_row-1)*(icon_size+sysbar->area.paddingx) - icon_size;
- icons_per_column = count / icons_per_row+ (count%icons_per_row != 0);
- systray.area.height = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_column) + ((icons_per_column-1) * systray.area.paddingx);
- }
+ int width = sysbar->area.width - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
+ // here icons_per_row always higher than 0
+ icons_per_row = (width+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
+ marging = width - (icons_per_row-1)*(icon_size+sysbar->area.paddingx) - icon_size;
+ icons_per_column = count / icons_per_row+ (count%icons_per_row != 0);
+ systray.area.height = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_column) + ((icons_per_column-1) * systray.area.paddingx);
}
return 1;
}
traywin->depth = attr.depth;
traywin->damage = 0;
+ if (systray.area.on_screen == 0)
+ systray.area.on_screen = 1;
+
if (systray.sort == 3)
systray.list_icons = g_slist_prepend(systray.list_icons, traywin);
else if (systray.sort == 2)
stop_timeout(traywin->render_timeout);
g_free(traywin);
+ // check empty systray
+ int count = 0;
+ GSList *l;
+ for (l = systray.list_icons; l ; l = l->next) {
+ if (!((TrayWindow*)l->data)->hide)
+ count++;
+ }
+ if (count == 0) {
+ systray.area.on_screen = 0;
+ systray.area.width = 0;
+ }
// changed in systray force resize on panel
Panel *panel = systray.area.panel;
panel->area.resize = 1;
gboolean win_compare(gconstpointer a, gconstpointer b) { return (*((Window*)a) == *((Window*)b)); }
void free_ptr_array(gpointer data) { g_ptr_array_free(data, 1); }
-void init_taskbar()
-{
- Panel *panel;
- int i, j;
-
- if (win_to_task_table == 0)
- win_to_task_table = g_hash_table_new_full(win_hash, win_compare, free, free_ptr_array);
-
- task_active = 0;
- task_drag = 0;
-
- for (i=0 ; i < nb_panel ; i++) {
- panel = &panel1[i];
-
- if (panel->g_taskbar.bg == 0) {
- panel->g_taskbar.bg = &g_array_index(backgrounds, Background, 0);
- panel->g_taskbar.area.bg = panel->g_taskbar.bg;
- }
- if (panel->g_taskbar.bg_active == 0)
- panel->g_taskbar.bg_active = panel->g_taskbar.bg;
- if (panel->g_task.area.bg == 0)
- panel->g_task.area.bg = &g_array_index(backgrounds, Background, 0);
-
- // taskbar
- panel->g_taskbar.area.size_mode = SIZE_BY_LAYOUT;
- panel->g_taskbar.area._resize = resize_taskbar;
- panel->g_taskbar.area.redraw = 1;
- panel->g_taskbar.area.on_screen = 1;
- if (panel_horizontal) {
- panel->g_taskbar.area.posy = panel->area.bg->border.width + panel->area.paddingy;
- panel->g_taskbar.area.height = panel->area.height - (2 * panel->g_taskbar.area.posy);
- }
- else {
- panel->g_taskbar.area.posx = panel->area.bg->border.width + panel->area.paddingy;
- panel->g_taskbar.area.width = panel->area.width - (2 * panel->g_taskbar.area.posx);
- }
-
- // task
- panel->g_task.area.size_mode = SIZE_BY_LAYOUT;
- panel->g_task.area._draw_foreground = draw_task;
- panel->g_task.area.redraw = 1;
- panel->g_task.area.on_screen = 1;
- if ((panel->g_task.config_asb_mask & (1<<TASK_NORMAL)) == 0) {
- panel->g_task.alpha[TASK_NORMAL] = 100;
- panel->g_task.saturation[TASK_NORMAL] = 0;
- panel->g_task.brightness[TASK_NORMAL] = 0;
- }
- if ((panel->g_task.config_asb_mask & (1<<TASK_ACTIVE)) == 0) {
- panel->g_task.alpha[TASK_ACTIVE] = panel->g_task.alpha[TASK_NORMAL];
- panel->g_task.saturation[TASK_ACTIVE] = panel->g_task.saturation[TASK_NORMAL];
- panel->g_task.brightness[TASK_ACTIVE] = panel->g_task.brightness[TASK_NORMAL];
- }
- if ((panel->g_task.config_asb_mask & (1<<TASK_ICONIFIED)) == 0) {
- panel->g_task.alpha[TASK_ICONIFIED] = panel->g_task.alpha[TASK_NORMAL];
- panel->g_task.saturation[TASK_ICONIFIED] = panel->g_task.saturation[TASK_NORMAL];
- panel->g_task.brightness[TASK_ICONIFIED] = panel->g_task.brightness[TASK_NORMAL];
- }
- if ((panel->g_task.config_asb_mask & (1<<TASK_URGENT)) == 0) {
- panel->g_task.alpha[TASK_URGENT] = panel->g_task.alpha[TASK_ACTIVE];
- panel->g_task.saturation[TASK_URGENT] = panel->g_task.saturation[TASK_ACTIVE];
- panel->g_task.brightness[TASK_URGENT] = panel->g_task.brightness[TASK_ACTIVE];
- }
- if ((panel->g_task.config_font_mask & (1<<TASK_NORMAL)) == 0) panel->g_task.font[TASK_NORMAL] = (Color){{0, 0, 0}, 0};
- if ((panel->g_task.config_font_mask & (1<<TASK_ACTIVE)) == 0) panel->g_task.font[TASK_ACTIVE] = panel->g_task.font[TASK_NORMAL];
- if ((panel->g_task.config_font_mask & (1<<TASK_ICONIFIED)) == 0) panel->g_task.font[TASK_ICONIFIED] = panel->g_task.font[TASK_NORMAL];
- if ((panel->g_task.config_font_mask & (1<<TASK_URGENT)) == 0) panel->g_task.font[TASK_URGENT] = panel->g_task.font[TASK_ACTIVE];
- if ((panel->g_task.config_font_mask & (1<<TASK_NORMAL)) == 0) panel->g_task.background[TASK_NORMAL] = &g_array_index(backgrounds, Background, 0);
- if ((panel->g_task.config_background_mask & (1<<TASK_ACTIVE)) == 0) panel->g_task.background[TASK_ACTIVE] = panel->g_task.background[TASK_NORMAL];
- if ((panel->g_task.config_background_mask & (1<<TASK_ICONIFIED)) == 0) panel->g_task.background[TASK_ICONIFIED] = panel->g_task.background[TASK_NORMAL];
- if ((panel->g_task.config_background_mask & (1<<TASK_URGENT)) == 0) panel->g_task.background[TASK_URGENT] = panel->g_task.background[TASK_ACTIVE];
-
- if (panel_horizontal) {
- panel->g_task.area.posy = panel->g_taskbar.area.posy + panel->g_taskbar.bg->border.width + panel->g_taskbar.area.paddingy;
- panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy);
- }
- else {
- panel->g_task.area.posx = panel->g_taskbar.area.posx + panel->g_taskbar.bg->border.width + panel->g_taskbar.area.paddingy;
- panel->g_task.area.width = panel->area.width - (2 * panel->g_task.area.posx);
- panel->g_task.area.height = panel->g_task.maximum_height;
- }
-
- int k;
- for (k=0; k<TASK_STATE_COUNT; ++k) {
- if (panel->g_task.background[k]->border.rounded > panel->g_task.area.height/2) {
- printf("task%sbackground_id has a too large rounded value. Please fix your tint2rc\n", k==0 ? "_" : k==1 ? "_active_" : k==2 ? "_iconified_" : "_urgent_");
- g_array_append_val(backgrounds, *panel->g_task.background[k]);
- panel->g_task.background[k] = &g_array_index(backgrounds, Background, backgrounds->len-1);
- panel->g_task.background[k]->border.rounded = panel->g_task.area.height/2;
- }
- }
-
- // compute vertical position : text and icon
- int height_ink, height;
- get_text_size(panel->g_task.font_desc, &height_ink, &height, panel->area.height, "TAjpg", 5);
-
- if (!panel->g_task.maximum_width && panel_horizontal)
- panel->g_task.maximum_width = server.monitor[panel->monitor].width;
-
- panel->g_task.text_posx = panel->g_task.background[0]->border.width + panel->g_task.area.paddingxlr;
- panel->g_task.text_height = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
- if (panel->g_task.icon) {
- panel->g_task.icon_size1 = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
- panel->g_task.text_posx += panel->g_task.icon_size1;
- panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2;
- }
- //printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
-
- Taskbar *tskbar;
- for (j=0 ; j < panel->nb_desktop ; j++) {
- tskbar = &panel->taskbar[j];
- memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area));
- tskbar->desktop = j;
- if (j == server.desktop && panel->g_taskbar.use_active)
- tskbar->area.bg = panel->g_taskbar.bg_active;
- }
- }
-}
-
-void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data)
-{
- remove_task(task_get_task(*(Window*)key));
-}
void default_taskbar()
{
}
+void init_taskbar()
+{
+ if (win_to_task_table == 0)
+ win_to_task_table = g_hash_table_new_full(win_hash, win_compare, free, free_ptr_array);
+
+ task_active = 0;
+ task_drag = 0;
+}
+
+
+void init_taskbar_panel(void *p)
+{
+ Panel *panel =(Panel*)p;
+ int j;
+
+ if (panel->g_taskbar.bg == 0) {
+ panel->g_taskbar.bg = &g_array_index(backgrounds, Background, 0);
+ panel->g_taskbar.area.bg = panel->g_taskbar.bg;
+ }
+ if (panel->g_taskbar.bg_active == 0)
+ panel->g_taskbar.bg_active = panel->g_taskbar.bg;
+ if (panel->g_task.area.bg == 0)
+ panel->g_task.area.bg = &g_array_index(backgrounds, Background, 0);
+
+ // taskbar
+ panel->g_taskbar.area.size_mode = SIZE_BY_LAYOUT;
+ panel->g_taskbar.area._resize = resize_taskbar;
+ panel->g_taskbar.area.redraw = 1;
+ panel->g_taskbar.area.on_screen = 1;
+ if (panel_horizontal) {
+ panel->g_taskbar.area.posy = panel->area.bg->border.width + panel->area.paddingy;
+ panel->g_taskbar.area.height = panel->area.height - (2 * panel->g_taskbar.area.posy);
+ }
+ else {
+ panel->g_taskbar.area.posx = panel->area.bg->border.width + panel->area.paddingy;
+ panel->g_taskbar.area.width = panel->area.width - (2 * panel->g_taskbar.area.posx);
+ }
+
+ // task
+ panel->g_task.area.size_mode = SIZE_BY_LAYOUT;
+ panel->g_task.area._draw_foreground = draw_task;
+ panel->g_task.area.redraw = 1;
+ panel->g_task.area.on_screen = 1;
+ if ((panel->g_task.config_asb_mask & (1<<TASK_NORMAL)) == 0) {
+ panel->g_task.alpha[TASK_NORMAL] = 100;
+ panel->g_task.saturation[TASK_NORMAL] = 0;
+ panel->g_task.brightness[TASK_NORMAL] = 0;
+ }
+ if ((panel->g_task.config_asb_mask & (1<<TASK_ACTIVE)) == 0) {
+ panel->g_task.alpha[TASK_ACTIVE] = panel->g_task.alpha[TASK_NORMAL];
+ panel->g_task.saturation[TASK_ACTIVE] = panel->g_task.saturation[TASK_NORMAL];
+ panel->g_task.brightness[TASK_ACTIVE] = panel->g_task.brightness[TASK_NORMAL];
+ }
+ if ((panel->g_task.config_asb_mask & (1<<TASK_ICONIFIED)) == 0) {
+ panel->g_task.alpha[TASK_ICONIFIED] = panel->g_task.alpha[TASK_NORMAL];
+ panel->g_task.saturation[TASK_ICONIFIED] = panel->g_task.saturation[TASK_NORMAL];
+ panel->g_task.brightness[TASK_ICONIFIED] = panel->g_task.brightness[TASK_NORMAL];
+ }
+ if ((panel->g_task.config_asb_mask & (1<<TASK_URGENT)) == 0) {
+ panel->g_task.alpha[TASK_URGENT] = panel->g_task.alpha[TASK_ACTIVE];
+ panel->g_task.saturation[TASK_URGENT] = panel->g_task.saturation[TASK_ACTIVE];
+ panel->g_task.brightness[TASK_URGENT] = panel->g_task.brightness[TASK_ACTIVE];
+ }
+ if ((panel->g_task.config_font_mask & (1<<TASK_NORMAL)) == 0) panel->g_task.font[TASK_NORMAL] = (Color){{0, 0, 0}, 0};
+ if ((panel->g_task.config_font_mask & (1<<TASK_ACTIVE)) == 0) panel->g_task.font[TASK_ACTIVE] = panel->g_task.font[TASK_NORMAL];
+ if ((panel->g_task.config_font_mask & (1<<TASK_ICONIFIED)) == 0) panel->g_task.font[TASK_ICONIFIED] = panel->g_task.font[TASK_NORMAL];
+ if ((panel->g_task.config_font_mask & (1<<TASK_URGENT)) == 0) panel->g_task.font[TASK_URGENT] = panel->g_task.font[TASK_ACTIVE];
+ if ((panel->g_task.config_font_mask & (1<<TASK_NORMAL)) == 0) panel->g_task.background[TASK_NORMAL] = &g_array_index(backgrounds, Background, 0);
+ if ((panel->g_task.config_background_mask & (1<<TASK_ACTIVE)) == 0) panel->g_task.background[TASK_ACTIVE] = panel->g_task.background[TASK_NORMAL];
+ if ((panel->g_task.config_background_mask & (1<<TASK_ICONIFIED)) == 0) panel->g_task.background[TASK_ICONIFIED] = panel->g_task.background[TASK_NORMAL];
+ if ((panel->g_task.config_background_mask & (1<<TASK_URGENT)) == 0) panel->g_task.background[TASK_URGENT] = panel->g_task.background[TASK_ACTIVE];
+
+ if (panel_horizontal) {
+ panel->g_task.area.posy = panel->g_taskbar.area.posy + panel->g_taskbar.bg->border.width + panel->g_taskbar.area.paddingy;
+ panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy);
+ }
+ else {
+ panel->g_task.area.posx = panel->g_taskbar.area.posx + panel->g_taskbar.bg->border.width + panel->g_taskbar.area.paddingy;
+ panel->g_task.area.width = panel->area.width - (2 * panel->g_task.area.posx);
+ panel->g_task.area.height = panel->g_task.maximum_height;
+ }
+
+ for (j=0; j<TASK_STATE_COUNT; ++j) {
+ if (panel->g_task.background[j]->border.rounded > panel->g_task.area.height/2) {
+ printf("task%sbackground_id has a too large rounded value. Please fix your tint2rc\n", j==0 ? "_" : j==1 ? "_active_" : j==2 ? "_iconified_" : "_urgent_");
+ g_array_append_val(backgrounds, *panel->g_task.background[j]);
+ panel->g_task.background[j] = &g_array_index(backgrounds, Background, backgrounds->len-1);
+ panel->g_task.background[j]->border.rounded = panel->g_task.area.height/2;
+ }
+ }
+
+ // compute vertical position : text and icon
+ int height_ink, height;
+ get_text_size(panel->g_task.font_desc, &height_ink, &height, panel->area.height, "TAjpg", 5);
+
+ if (!panel->g_task.maximum_width && panel_horizontal)
+ panel->g_task.maximum_width = server.monitor[panel->monitor].width;
+
+ panel->g_task.text_posx = panel->g_task.background[0]->border.width + panel->g_task.area.paddingxlr;
+ panel->g_task.text_height = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
+ if (panel->g_task.icon) {
+ panel->g_task.icon_size1 = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
+ panel->g_task.text_posx += panel->g_task.icon_size1;
+ panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2;
+ }
+ //printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
+
+ Taskbar *tskbar;
+ panel->nb_desktop = server.nb_desktop;
+ panel->taskbar = calloc(server.nb_desktop, sizeof(Taskbar));
+ for (j=0 ; j < panel->nb_desktop ; j++) {
+ tskbar = &panel->taskbar[j];
+ memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area));
+ tskbar->desktop = j;
+ if (j == server.desktop && panel->g_taskbar.use_active)
+ tskbar->area.bg = panel->g_taskbar.bg_active;
+ }
+}
+
+
+void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data)
+{
+ remove_task(task_get_task(*(Window*)key));
+}
+
+
Task *task_get_task (Window win)
{
GPtrArray* task_group = task_get_tasks(win);