From 63bbffa4af17926ba2d52728883988eae402b07a Mon Sep 17 00:00:00 2001 From: Thierry Lorthiois Date: Thu, 23 Sep 2010 18:09:30 +0000 Subject: [PATCH] cleanup code --- src/battery/battery.c | 2 ++ src/config.c | 3 ++- src/panel.c | 26 ++------------------------ src/panel.h | 1 - src/taskbar/task.c | 1 + src/taskbar/taskbar.c | 31 +++++++++++++++++++++++++------ src/taskbar/taskbar.h | 4 +++- src/tint.c | 9 ++++----- src/util/area.c | 1 - src/util/area.h | 3 ++- 10 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/battery/battery.c b/src/battery/battery.c index fd4d59b..9bb024e 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -237,6 +237,8 @@ void init_battery_panel(void *p) battery->area._draw_foreground = draw_battery; battery->area.size_mode = SIZE_BY_CONTENT; battery->area._resize = resize_battery; + battery->area.on_screen = 1; + battery->area.resize = 1; } diff --git a/src/config.c b/src/config.c index 37a30ef..04ec056 100644 --- a/src/config.c +++ b/src/config.c @@ -451,13 +451,14 @@ void add_entry (char *key, char *value) int id = atoi (value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.g_taskbar.bg = &g_array_index(backgrounds, Background, id); + if (panel_config.g_taskbar.bg_active == 0) + panel_config.g_taskbar.bg_active = panel_config.g_taskbar.bg; panel_config.g_taskbar.area.bg = panel_config.g_taskbar.bg; } else if (strcmp (key, "taskbar_active_background_id") == 0) { int id = atoi (value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.g_taskbar.bg_active = &g_array_index(backgrounds, Background, id); - panel_config.g_taskbar.use_active = 1; } /* Task */ diff --git a/src/panel.c b/src/panel.c index 797b96a..6a98a26 100644 --- a/src/panel.c +++ b/src/panel.c @@ -219,9 +219,10 @@ void init_panel() if (panel_autohide) add_timeout(panel_autohide_hide_timeout, 0, autohide_hide, p); + + visible_taskbar(p); } - visible_object(); task_refresh_tasklist(); active_task(); } @@ -301,29 +302,6 @@ void init_panel_size_and_position(Panel *panel) } -void visible_object() -{ - Panel *panel; - int i, j; - - for (i=0 ; i < nb_panel ; i++) { - panel = &panel1[i]; - - Taskbar *taskbar; - for (j=0 ; j < panel->nb_desktop ; j++) { - taskbar = &panel->taskbar[j]; - if (panel_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) { - // SINGLE_DESKTOP and not current desktop - taskbar->area.on_screen = 0; - } - else { - taskbar->area.on_screen = 1; - } - } - } - panel_refresh = 1; -} - void update_strut(Panel* p) { if (panel_strut_policy == STRUT_NONE) { diff --git a/src/panel.h b/src/panel.h index aedb1f2..8336666 100644 --- a/src/panel.h +++ b/src/panel.h @@ -138,7 +138,6 @@ void init_panel_size_and_position(Panel *panel); void set_panel_items_order(Panel *p); void set_panel_properties(Panel *p); -void visible_object(); // draw background panel void set_panel_background(Panel *p); diff --git a/src/taskbar/task.c b/src/taskbar/task.c index 5f92233..83e827f 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -342,6 +342,7 @@ void draw_task (void *obj, cairo_t *c) Color *config_text; int width=0, height; Panel *panel = (Panel*)tsk->area.panel; + //printf("draw_task %d %d\n", tsk->area.posx, tsk->area.posy); if (panel->g_task.text) { /* Layout */ diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index aa65991..6901fcc 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -198,7 +198,7 @@ void init_taskbar_panel(void *p) tskbar = &panel->taskbar[j]; memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area)); tskbar->desktop = j; - if (j == server.desktop && panel->g_taskbar.use_active) + if (j == server.desktop) tskbar->area.bg = panel->g_taskbar.bg_active; } } @@ -266,9 +266,7 @@ int resize_taskbar(void *obj) GSList *l; int task_count, border_width; - //printf("resize_taskbar : posx et width des taches\n"); - taskbar->area.redraw = 1; - +// taskbar->area.redraw = 1; border_width = taskbar->area.bg->border.width; if (panel_horizontal) { @@ -297,7 +295,7 @@ int resize_taskbar(void *obj) for (l = taskbar->area.list; l ; l = l->next) { tsk = l->data; if (!tsk->area.on_screen) continue; - set_task_redraw(tsk); // always redraw task, because the background could have changed (taskbar_active_id) + //set_task_redraw(tsk); // always redraw task, because the background could have changed (taskbar_active_id) tsk->area.width = pixel_width; // TODO : move later (when posx is known) // long value[] = { panel->posx+x, panel->posy, pixel_width, panel->area.height }; @@ -335,7 +333,7 @@ int resize_taskbar(void *obj) for (l = taskbar->area.list; l ; l = l->next) { tsk = l->data; if (!tsk->area.on_screen) continue; - set_task_redraw(tsk); // always redraw task, because the background could have changed (taskbar_active_id) + //set_task_redraw(tsk); // always redraw task, because the background could have changed (taskbar_active_id) tsk->area.height = pixel_height; // TODO : move later (when posy is known) // long value[] = { panel->posx, panel->posy+y, panel->area.width, pixel_height }; @@ -347,6 +345,27 @@ int resize_taskbar(void *obj) } } } + return 0; } + +void visible_taskbar(void *p) +{ + Panel *panel =(Panel*)p; + int j; + + Taskbar *taskbar; + for (j=0 ; j < panel->nb_desktop ; j++) { + taskbar = &panel->taskbar[j]; + if (panel_mode != MULTI_DESKTOP && taskbar->desktop != server.desktop) { + // SINGLE_DESKTOP and not current desktop + taskbar->area.on_screen = 0; + } + else { + taskbar->area.on_screen = 1; + } + } + panel_refresh = 1; +} + diff --git a/src/taskbar/taskbar.h b/src/taskbar/taskbar.h index f863684..8407819 100644 --- a/src/taskbar/taskbar.h +++ b/src/taskbar/taskbar.h @@ -34,7 +34,6 @@ typedef struct { Area area; Background* bg; Background* bg_active; - int use_active; } Global_taskbar; @@ -54,6 +53,9 @@ void task_refresh_tasklist (); int resize_taskbar(void *obj); +// show/hide taskbar according to current desktop +void visible_taskbar(void *p); + #endif diff --git a/src/tint.c b/src/tint.c index 80a7dd9..2f5edc6 100644 --- a/src/tint.c +++ b/src/tint.c @@ -494,9 +494,9 @@ void event_property_notify (XEvent *e) for (i=0 ; i < nb_panel ; i++) { init_taskbar_panel(&panel1[i]); set_panel_items_order(&panel1[i]); + visible_taskbar(&panel1[i]); panel1[i].area.resize = 1; } - visible_object(); task_refresh_tasklist(); active_task(); panel_refresh = 1; @@ -508,7 +508,7 @@ void event_property_notify (XEvent *e) server.desktop = server_get_current_desktop (); for (i=0 ; i < nb_panel ; i++) { Panel *panel = &panel1[i]; - if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.use_active) { + if (panel_mode == MULTI_DESKTOP && panel->g_taskbar.bg != panel->g_taskbar.bg_active) { // redraw both taskbar if (server.nb_desktop > old_desktop) { // can happen if last desktop is deleted and we've been on the last desktop @@ -542,9 +542,8 @@ void event_property_notify (XEvent *e) tskbar->area.resize = 1; } } - } - if (panel_mode != MULTI_DESKTOP) { - visible_object(); + if (panel_mode != MULTI_DESKTOP) + visible_taskbar(panel); } } // Window list diff --git a/src/util/area.c b/src/util/area.c index 34a4d13..adec3c9 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -220,7 +220,6 @@ int resize_by_layout(void *obj) Area *child, *a = (Area*)obj; int size, nb_by_content=0, nb_by_layout=0; - printf("resize_by_layout\n"); if (panel_horizontal) { // detect free size for SIZE_BY_LAYOUT's Area size = a->width - (2 * (a->paddingxlr + a->bg->border.width)); diff --git a/src/util/area.h b/src/util/area.h index 2f8d822..7270419 100644 --- a/src/util/area.h +++ b/src/util/area.h @@ -82,7 +82,8 @@ typedef struct { // each object can overwrite following function void (*_draw_foreground)(void *obj, cairo_t *c); - // calculate size. return '1' if size changed, '0' otherwise. + // update area's content and update size (width/heith). + // return '1' if size changed, '0' otherwise. int (*_resize)(void *obj); void (*_add_child)(void *obj); int (*_remove_child)(void *obj); -- 2.45.2