]> Dogcows Code - chaz/tint2/commitdiff
add comment
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Thu, 16 Sep 2010 23:24:25 +0000 (23:24 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Thu, 16 Sep 2010 23:24:25 +0000 (23:24 +0000)
14 files changed:
src/battery/battery.c
src/battery/battery.h
src/clock/clock.c
src/clock/clock.h
src/launcher/launcher.c
src/launcher/launcher.h
src/panel.c
src/panel.h
src/systray/systraybar.c
src/systray/systraybar.h
src/taskbar/taskbar.c
src/taskbar/taskbar.h
src/util/area.c
src/util/area.h

index be6472184c58755cc95c34175e3718dd11745a19..3ad28996af88b0321656b5a4241e5f4f93dfca94 100644 (file)
@@ -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;
 }
 
index fa46aeef67b4bed4da1d54102ec3f720cf0a7646..c081e0f003299fe798ab0c12fd1698a002488e1c 100644 (file)
@@ -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
index af6778efa50a28c649d305b793288be764cd35d0..bd741c2bcd270c19904276d2237384a30b6cc638 100644 (file)
@@ -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;
 }
 
 
index fa8c7969af8df7145618ec38a23a5de3ab88d5c2..4c31605ba166d68bff7aaabe21ea80dc04e95520 100644 (file)
@@ -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);
 
index c90c545a023b73290827dfbcd003bc397293f832..3a7c4ca11734cd38890b36c62b4aa0bcf42ce28d 100644 (file)
@@ -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;
 }
 
 
index 3023546e90fb3f23bb7d833e2ef3702f63cebe9d..d44ade1a0eba7f0f5580dbc33a5b3f5f61047e88 100644 (file)
@@ -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);
index 61b4b2025a01a36be364a4abf90b257d79653b7c..e51a69573db36998f77970fe4008975b3c4be346 100644 (file)
@@ -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;
index 8bad2e718948f4697af763499866061add107aa5..e4174d98ac1f7bc6a0b39bddf782e13feb3e4519 100644 (file)
@@ -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();
index 9d460549cc50b8e6fe8b352d5cf41d6abd847ae5..a8e0fbc042f48c16b03ab1c50a409c0540c10ffc 100644 (file)
@@ -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;
 }
 
 
index 7b5e9fcac5caf66a03809cd216a61b449f77358e..5921ee513c11022b7cbd2a9573dcf7a9dff4bd65 100644 (file)
@@ -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
index 7f000eefbff541a1f49d0e5ea77a6e58c4f3fb46..c53712a27748834f97082401abecb1e2198f9535 100644 (file)
@@ -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;
 }
index 3474825d02b959a6a828527fb1d0d745ddf6658d..583cd36e9167fee5999db82bde5ec49a06e9c394 100644 (file)
@@ -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
index 0460d57c72ca571803846983b885fa88c31dfae9..7455561b34e90e5f0862ac476ce794953531ab97 100644 (file)
 /************************************************************
  * !!! 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;
index af7e4e728e6569573aecb5fea0955928999c08ac..77f957e2988ac914abe4aac35710a85d92eef761 100644 (file)
@@ -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);
This page took 0.038247 seconds and 4 git commands to generate.