panel_items : fixed segfault (panel without clock, change number desktop)

git-svn-id: http://tint2.googlecode.com/svn/trunk@550 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
thilor77 2010-09-18 18:06:29 +00:00
parent 500981b052
commit b98d2001cb
8 changed files with 216 additions and 183 deletions

View file

@ -157,7 +157,6 @@ void cleanup_launcher()
int resize_launcher(void *obj)
{
Launcher *launcher = obj;
Panel *panel = launcher->area.panel;
GSList *l;
int count, icon_size;
int icons_per_column=1, icons_per_row=1, marging=0;

View file

@ -126,7 +126,7 @@ void cleanup_panel()
void init_panel()
{
int i, j;
int i;
Panel *p;
if (panel_config.monitor > (server.nb_monitor-1)) {
@ -142,6 +142,7 @@ void init_panel()
#ifdef ENABLE_BATTERY
init_battery();
#endif
init_taskbar();
// number of panels (one monitor or 'all' monitors)
if (panel_config.monitor >= 0)
@ -172,38 +173,8 @@ void init_panel()
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 };
@ -234,7 +205,6 @@ void init_panel()
}
panel_refresh = 1;
init_taskbar();
visible_object();
task_refresh_tasklist();
active_task();
@ -483,6 +453,45 @@ void update_strut(Panel* p)
}
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");

View file

@ -137,6 +137,7 @@ void init_panel();
void init_panel_size_and_position(Panel *panel);
int resize_panel(void *obj);
void set_panel_items(Panel *p);
void set_panel_properties(Panel *p);
void visible_object();

View file

@ -90,10 +90,6 @@ void init_systray()
systray.alpha = 100;
systray.brightness = systray.saturation = 0;
}
systray.area.resize = 1;
systray.area.redraw = 1;
systray.area.on_screen = 1;
refresh_systray = 0;
}
@ -111,6 +107,18 @@ void init_systray_panel(void *p)
}
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;
}
@ -195,8 +203,6 @@ int resize_systray(void *obj)
//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);
@ -204,9 +210,6 @@ int resize_systray(void *obj)
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
@ -215,7 +218,6 @@ int resize_systray(void *obj)
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;
}
@ -433,6 +435,9 @@ gboolean add_icon(Window id)
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)
@ -488,6 +493,17 @@ void remove_icon(TrayWindow *traywin)
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;

View file

@ -46,19 +46,56 @@ guint win_hash(gconstpointer key) { return (guint)*((Window*)key); }
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()
void default_taskbar()
{
win_to_task_table = 0;
urgent_timeout = 0;
urgent_list = 0;
}
void cleanup_taskbar()
{
Panel *panel;
Taskbar *tskbar;
int i, j;
if (win_to_task_table) g_hash_table_foreach(win_to_task_table, taskbar_remove_task, 0);
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
for (j=0 ; j < panel->nb_desktop ; j++) {
tskbar = &panel->taskbar[j];
free_area (&tskbar->area);
// remove taskbar from the panel
panel->area.list = g_slist_remove(panel->area.list, tskbar);
}
if (panel->taskbar) {
free(panel->taskbar);
panel->taskbar = 0;
}
}
if (win_to_task_table) {
g_hash_table_destroy(win_to_task_table);
win_to_task_table = 0;
}
}
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;
}
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
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);
@ -127,13 +164,12 @@ void init_taskbar()
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;
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;
}
}
@ -154,6 +190,8 @@ void init_taskbar()
//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));
@ -162,47 +200,13 @@ void init_taskbar()
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()
{
win_to_task_table = 0;
urgent_timeout = 0;
urgent_list = 0;
}
void cleanup_taskbar()
{
Panel *panel;
Taskbar *tskbar;
int i, j;
if (win_to_task_table) g_hash_table_foreach(win_to_task_table, taskbar_remove_task, 0);
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
for (j=0 ; j < panel->nb_desktop ; j++) {
tskbar = &panel->taskbar[j];
free_area (&tskbar->area);
// remove taskbar from the panel
panel->area.list = g_slist_remove(panel->area.list, tskbar);
}
if (panel->taskbar) {
free(panel->taskbar);
panel->taskbar = 0;
}
}
if (win_to_task_table) {
g_hash_table_destroy(win_to_task_table);
win_to_task_table = 0;
}
}
Task *task_get_task (Window win)
{

View file

@ -44,7 +44,9 @@ void default_taskbar();
void cleanup_taskbar();
void init_taskbar();
void init_taskbar_panel(void *p);
void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data);
Task *task_get_task (Window win);
GPtrArray* task_get_tasks(Window win);
void task_refresh_tasklist ();

View file

@ -490,10 +490,11 @@ void event_property_notify (XEvent *e)
server.nb_desktop = server_get_number_of_desktop ();
cleanup_taskbar();
init_taskbar();
visible_object();
for (i=0 ; i < nb_panel ; i++) {
set_panel_items(&panel1[i]);
panel1[i].area.resize = 1;
}
visible_object();
task_refresh_tasklist();
active_task();
panel_refresh = 1;
@ -883,7 +884,7 @@ start:
signal_pending = SIGUSR1;
break;
}
if (e.xany.window == g_tooltip.window || !systray.area.on_screen)
if (e.xany.window == g_tooltip.window || !systray_enabled)
break;
for (it = systray.list_icons; it; it = g_slist_next(it)) {
if (((TrayWindow*)it->data)->tray_id == e.xany.window) {
@ -903,7 +904,7 @@ start:
// Start real_transparency
signal_pending = SIGUSR1;
}
if (systray.area.on_screen && e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
if (systray_enabled && e.xclient.message_type == server.atom._NET_SYSTEM_TRAY_OPCODE && e.xclient.format == 32 && e.xclient.window == net_sel_win) {
net_message(&e.xclient);
}
else if (e.xclient.message_type == server.atom.XdndPosition) {

View file

@ -63,7 +63,8 @@ typedef struct {
// list of child : Area object
GSList *list;
// object visible on screen
// object visible on screen.
// An object (like systray) could be enabled but hidden (because no tray icon).
int on_screen;
// way to calculate the size (SIZE_BY_CONTENT or SIZE_BY_LAYOUT)
int size_mode;