From: Thierry Lorthiois Date: Thu, 16 Sep 2010 23:24:25 +0000 (+0000) Subject: add comment X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=e7c43073246afe07cddf67d40d545f2bebcf62a1;p=chaz%2Ftint2 add comment --- diff --git a/src/battery/battery.c b/src/battery/battery.c index be64721..3ad2899 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -449,11 +449,11 @@ void draw_battery (void *obj, cairo_t *c) } -void resize_battery(void *obj) +int resize_battery(void *obj) { Battery *battery = obj; PangoLayout *layout; - int percentage_width, time_width, new_width; + int percentage_width, time_width, new_width, ret = 0; percentage_width = time_width = 0; battery->area.redraw = 1; @@ -465,7 +465,7 @@ void resize_battery(void *obj) snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); } // vertical panel doen't adjust width - if (!panel_horizontal) return; + if (!panel_horizontal) return ret; cairo_surface_t *cs; cairo_t *c; @@ -500,18 +500,17 @@ void resize_battery(void *obj) if (panel->clock.area.on_screen) battery->area.posx -= (panel->clock.area.width + panel->area.paddingx); - if(new_width > old_width || new_width < (old_width-6)) { + if (new_width > old_width || new_width < (old_width-6)) { // refresh and resize other objects on panel // we try to limit the number of refresh // printf("battery_width %d, new_width %d\n", battery->area.width, new_width); - panel->area.resize = 1; - systray.area.resize = 1; - panel_refresh = 1; + ret = 1; } g_object_unref (layout); cairo_destroy (c); cairo_surface_destroy (cs); XFreePixmap (server.dsp, pmap); + return ret; } diff --git a/src/battery/battery.h b/src/battery/battery.h index fa46aee..c081e0f 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -71,6 +71,6 @@ void init_battery_panel(void *panel); void draw_battery(void *obj, cairo_t *c); -void resize_battery(void *obj); +int resize_battery(void *obj); #endif diff --git a/src/clock/clock.c b/src/clock/clock.c index af6778e..bd741c2 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -225,11 +225,11 @@ void draw_clock (void *obj, cairo_t *c) } -void resize_clock (void *obj) +int resize_clock (void *obj) { Clock *clock = obj; PangoLayout *layout; - int time_width, date_width, new_width; + int time_width, date_width, new_width, ret = 0; clock->area.redraw = 1; time_width = date_width = 0; @@ -238,7 +238,7 @@ void resize_clock (void *obj) strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone)); // vertical panel doen't adjust width - if (!panel_horizontal) return; + if (!panel_horizontal) return ret; //printf(" resize_clock\n"); cairo_surface_t *cs; @@ -274,11 +274,7 @@ void resize_clock (void *obj) clock->area.width = new_width + 1; // resize other objects on panel - panel->area.resize = 1; -#ifdef ENABLE_BATTERY - panel->battery.area.resize = 1; -#endif - systray.area.resize = 1; + ret = 1; panel_refresh = 1; } clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.bg->border.width; @@ -288,6 +284,7 @@ void resize_clock (void *obj) cairo_destroy (c); cairo_surface_destroy (cs); XFreePixmap (server.dsp, pmap); + return ret; } diff --git a/src/clock/clock.h b/src/clock/clock.h index fa8c796..4c31605 100644 --- a/src/clock/clock.h +++ b/src/clock/clock.h @@ -49,7 +49,7 @@ void init_clock_panel(void *panel); void draw_clock (void *obj, cairo_t *c); -void resize_clock (void *obj); +int resize_clock (void *obj); void clock_action(int button); diff --git a/src/launcher/launcher.c b/src/launcher/launcher.c index c90c545..3a7c4ca 100644 --- a/src/launcher/launcher.c +++ b/src/launcher/launcher.c @@ -149,7 +149,7 @@ void cleanup_launcher() launcher_enabled = 0; } -void resize_launcher(void *obj) +int resize_launcher(void *obj) { Launcher *launcher = obj; Panel *panel = launcher->area.panel; @@ -274,9 +274,7 @@ void resize_launcher(void *obj) } } } - - // resize force the redraw - launcher->area.redraw = 1; + return 1; } diff --git a/src/launcher/launcher.h b/src/launcher/launcher.h index 3023546..d44ade1 100644 --- a/src/launcher/launcher.h +++ b/src/launcher/launcher.h @@ -66,7 +66,7 @@ void init_launcher(); void init_launcher_panel(void *panel); void cleanup_launcher(); -void resize_launcher(void *obj); +int resize_launcher(void *obj); void draw_launcher (void *obj, cairo_t *c); void launcher_action(LauncherIcon *icon); diff --git a/src/panel.c b/src/panel.c index 61b4b20..e51a695 100644 --- a/src/panel.c +++ b/src/panel.c @@ -301,7 +301,7 @@ void init_panel_size_and_position(Panel *panel) } -void resize_panel(void *obj) +int resize_panel(void *obj) { Panel *panel = (Panel*)obj; //printf("resize_panel : taskbar\n"); @@ -385,6 +385,7 @@ void resize_panel(void *obj) posy += panel->taskbar[i].area.height + panel->area.paddingx; } } + return 0; } @@ -580,12 +581,14 @@ void set_panel_background(Panel *p) } // redraw panel's object + //p->area.redraw = 1; GSList *l0; Area *a; for (l0 = p->area.list; l0 ; l0 = l0->next) { a = l0->data; set_redraw(a); } + // reset task 'state_pix' int i; Taskbar *tskbar; diff --git a/src/panel.h b/src/panel.h index 8bad2e7..e4174d9 100644 --- a/src/panel.h +++ b/src/panel.h @@ -134,7 +134,7 @@ void cleanup_panel(); void init_panel(); void init_panel_size_and_position(Panel *panel); -void resize_panel(void *obj); +int resize_panel(void *obj); void set_panel_properties(Panel *p); void visible_object(); diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 9d46054..a8e0fbc 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -126,7 +126,7 @@ void draw_systray(void *obj, cairo_t *c) } -void resize_systray(void *obj) +int resize_systray(void *obj) { Systraybar *sysbar = obj; Panel *panel = sysbar->area.panel; @@ -228,8 +228,7 @@ void resize_systray(void *obj) XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size); XResizeWindow(server.dsp, traywin->tray_id, icon_size, icon_size); } - // resize force the redraw - systray.area.redraw = 1; + return 1; } diff --git a/src/systray/systraybar.h b/src/systray/systraybar.h index 7b5e9fc..5921ee5 100644 --- a/src/systray/systraybar.h +++ b/src/systray/systraybar.h @@ -63,7 +63,7 @@ void init_systray(); void init_systray_panel(void *p); void draw_systray(void *obj, cairo_t *c); -void resize_systray(void *obj); +int resize_systray(void *obj); // systray protocol diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 7f000ee..c53712a 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -261,7 +261,7 @@ void task_refresh_tasklist () } -void resize_taskbar(void *obj) +int resize_taskbar(void *obj) { Taskbar *taskbar = (Taskbar*)obj; Panel *panel = (Panel*)taskbar->area.panel; @@ -356,4 +356,5 @@ void resize_taskbar(void *obj) y += tsk->area.height + panel->g_taskbar.area.paddingx; } } + return 0; } diff --git a/src/taskbar/taskbar.h b/src/taskbar/taskbar.h index 3474825..583cd36 100644 --- a/src/taskbar/taskbar.h +++ b/src/taskbar/taskbar.h @@ -49,7 +49,7 @@ Task *task_get_task (Window win); GPtrArray* task_get_tasks(Window win); void task_refresh_tasklist (); -void resize_taskbar(void *obj); +int resize_taskbar(void *obj); #endif diff --git a/src/util/area.c b/src/util/area.c index 0460d57..7455561 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -34,79 +34,53 @@ /************************************************************ * !!! This design is experimental and not yet fully implemented !!!!!!!!!!!!! * - * AREA : + * DATA ORGANISATION : * Areas in tint2 are similar to widgets in a GUI. - * Graphical objects (panel, taskbar, task, systray, clock, ...) in tint2 'inherit' an Area class. - * Area is an abstract class of objects. It's at the begining of each object (&object == &area). - * Area manage the background and border drawing, size and padding. + * All graphical objects (panel, taskbar, task, systray, clock, ...) 'inherit' an abstract class 'Area'. + * This class 'Area' manage the background, border, size, position and padding. + * Area is at the begining of each object (&object == &area). * - * DATA ORGANISATION : - * tint2 define one panel per monitor. And each panel have a tree of Area (nodes). + * tint2 define one panel per monitor. And each panel have a tree of Area. * The root of the tree is Panel.Area. And task, clock, systray, taskbar,... are nodes. * + * The tree give the localisation of each object : + * - tree's root is in the background while tree's leafe are foreground objects + * - position of a node/Area depend on the layout : parent's position (posx, posy), size of previous brothers and parent's padding + * - size of a node/Area depend on the content (SIZE_BY_CONTENT objects) or on the layout (SIZE_BY_LAYOUT objects) + * + * DRAWING AND LAYERING ENGINE : + * Redrawing an object (like the clock) could come from an 'external event' (date change) + * or from a 'layering event' (position change). + * The following 'drawing engine' take care of all 'layering event'. + * 1) browse tree SIZE_BY_CONTENT + * - resize SIZE_BY_CONTENT node : children are resized before parent + * - if 'size' changed then 'resize = 1' on the parent + * 2) browse tree SIZE_BY_LAYOUT and POSITION + * - resize SIZE_BY_LAYOUT node : parent is resized before children + * - if 'size' changed then 'resize = 1' on childs with SIZE_BY_LAYOUT + * - calculate position (posx,posy) : parent is calculated before children + * - if 'position' changed then 'redraw = 1' + * 3) browse tree REDRAW + * - redraw needed objects : parent is drawn before children + * + * CONFIGURE PANEL'S LAYOUT : * 'panel_items' parameter (in config) define the list and the order of nodes in tree's panel. * 'panel_items = SC' define a panel with just Systray and Clock. - * So the root Panel.Area will have 2 childs (Systray and Clock). + * So the tree 'Panel.Area' will have 2 childs (Systray and Clock). * - * The tree allow to browse panel's objects from background to foreground and from left to right. - * The position of each node/Area depend on parent's position and brothers on the left. - * - * DRAWING EVENT : - * In the end, redrawing an object (like the clock) could come from an external event (date change) - * or from a layering event (size or position change). - * - * DRAWING LOOP : - * 1) browse tree and resize SIZE_BY_CONTENT node - * - children node are resized before its parent - * - if 'size' changed then 'redraw = 1' and 'resize = 1' on the parent - * 2) browse tree and resize SIZE_BY_LAYOUT node - * - parent node is resized before its children - * - if 'size' changed then 'redraw = 1' and 'resize = 1' on childs with SIZE_BY_LAYOUT - * 3) calculate posx of objects - * - parent's position is calculated before children's position - * - if 'position' changed then 'redraw = 1' - * 4) redraw needed objects - * - parent node is drawn before its children - * - * perhaps 2) and 3) can be merged... + * 1) ok + * 2) ?? + * 3) ?? * répartition entre niveau global et niveau local ?? * size_by_content peut-il modifier redraw=1 en cas de changement ? ou est ce géré par chaque composant ? * size_by_layout peut-il modifier redraw ? - * + * ************************************************************/ -void refresh (Area *a) -{ - // don't draw and resize hide objects - if (!a->on_screen) return; - - // don't draw transparent objects (without foreground and without background) - if (a->redraw) { - a->redraw = 0; - // force redraw of child - GSList *l; - for (l = a->list ; l ; l = l->next) - set_redraw(l->data); - - //printf("draw area posx %d, width %d\n", a->posx, a->width); - draw(a); - } - - // draw current Area - if (a->pix == 0) printf("empty area posx %d, width %d\n", a->posx, a->width); - XCopyArea (server.dsp, a->pix, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy); - - // and then refresh child object - GSList *l; - for (l = a->list; l ; l = l->next) - refresh(l->data); -} - - void size_by_content (Area *a) { - // don't draw and resize hide objects + // don't resize hiden objects if (!a->on_screen) return; // children node are resized before its parent @@ -114,15 +88,16 @@ void size_by_content (Area *a) for (l = a->list; l ; l = l->next) size_by_content(l->data); - // calculate current area's size + // calculate area's size if (a->resize && a->size_mode == SIZE_BY_CONTENT) { a->resize = 0; - // if 'size' changed then 'resize = 1' on the parent if (a->_resize) { - a->_resize(a); + if (a->_resize(a)) { + // 'size' changed then 'resize = 1' on the parent + ((Area*)a->parent)->resize = 1; + } a->redraw = 1; - ((Area*)a->parent)->resize = 1; } } } @@ -130,21 +105,22 @@ void size_by_content (Area *a) void size_by_layout (Area *a) { - // don't draw and resize hide objects + // don't resize hiden objects if (!a->on_screen) return; // parent node is resized before its children - // calculate current area's size + // calculate area's size GSList *l; if (a->resize && a->size_mode == SIZE_BY_LAYOUT) { a->resize = 0; - // if 'size' changed then 'resize = 1' on childs with SIZE_BY_LAYOUT if (a->_resize) { - a->_resize(a); - for (l = a->list; l ; l = l->next) { - if (((Area*)l->data)->size_mode == SIZE_BY_LAYOUT) - ((Area*)l->data)->resize = 1; + if (a->_resize(a)) { + // if 'size' changed then 'resize = 1' on childs with SIZE_BY_LAYOUT + for (l = a->list; l ; l = l->next) { + if (((Area*)l->data)->size_mode == SIZE_BY_LAYOUT) + ((Area*)l->data)->resize = 1; + } } } } @@ -154,6 +130,35 @@ void size_by_layout (Area *a) } +void refresh (Area *a) +{ + // don't draw and resize hide objects + if (!a->on_screen) return; + + // don't draw transparent objects (without foreground and without background) + if (a->redraw) { + a->redraw = 0; + // force redraw of child + GSList *l; + for (l = a->list ; l ; l = l->next) + ((Area*)l->data)->redraw = 1; +// set_redraw(l->data); + + //printf("draw area posx %d, width %d\n", a->posx, a->width); + draw(a); + } + + // draw current Area + if (a->pix == 0) printf("empty area posx %d, width %d\n", a->posx, a->width); + XCopyArea (server.dsp, a->pix, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy); + + // and then refresh child object + GSList *l; + for (l = a->list; l ; l = l->next) + refresh(l->data); +} + + void set_redraw (Area *a) { a->redraw = 1; diff --git a/src/util/area.h b/src/util/area.h index af7e4e7..77f957e 100644 --- a/src/util/area.h +++ b/src/util/area.h @@ -81,7 +81,8 @@ typedef struct { // each object can overwrite following function void (*_draw_foreground)(void *obj, cairo_t *c); - void (*_resize)(void *obj); + // calculate size. return '1' if size changed, '0' otherwise. + int (*_resize)(void *obj); void (*_add_child)(void *obj); int (*_remove_child)(void *obj); const char* (*_get_tooltip_text)(void *obj);