add comment
git-svn-id: http://tint2.googlecode.com/svn/trunk@545 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
906ee82dbf
commit
aabe6b11b9
14 changed files with 115 additions and 112 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
167
src/util/area.c
167
src/util/area.c
|
@ -34,48 +34,102 @@
|
|||
/************************************************************
|
||||
* !!! This design is experimental and not yet fully implemented !!!!!!!!!!!!!
|
||||
*
|
||||
* AREA :
|
||||
* 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.
|
||||
*
|
||||
* DATA ORGANISATION :
|
||||
* tint2 define one panel per monitor. And each panel have a tree of Area (nodes).
|
||||
* Areas in tint2 are similar to widgets in a GUI.
|
||||
* 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).
|
||||
*
|
||||
* 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 size_by_content (Area *a)
|
||||
{
|
||||
// don't resize hiden objects
|
||||
if (!a->on_screen) return;
|
||||
|
||||
// children node are resized before its parent
|
||||
GSList *l;
|
||||
for (l = a->list; l ; l = l->next)
|
||||
size_by_content(l->data);
|
||||
|
||||
// calculate area's size
|
||||
if (a->resize && a->size_mode == SIZE_BY_CONTENT) {
|
||||
a->resize = 0;
|
||||
|
||||
if (a->_resize) {
|
||||
if (a->_resize(a)) {
|
||||
// 'size' changed then 'resize = 1' on the parent
|
||||
((Area*)a->parent)->resize = 1;
|
||||
}
|
||||
a->redraw = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void size_by_layout (Area *a)
|
||||
{
|
||||
// don't resize hiden objects
|
||||
if (!a->on_screen) return;
|
||||
|
||||
// parent node is resized before its children
|
||||
// calculate area's size
|
||||
GSList *l;
|
||||
if (a->resize && a->size_mode == SIZE_BY_LAYOUT) {
|
||||
a->resize = 0;
|
||||
|
||||
if (a->_resize) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (l = a->list; l ; l = l->next)
|
||||
size_by_layout(l->data);
|
||||
}
|
||||
|
||||
|
||||
void refresh (Area *a)
|
||||
{
|
||||
// don't draw and resize hide objects
|
||||
|
@ -87,7 +141,8 @@ void refresh (Area *a)
|
|||
// force redraw of child
|
||||
GSList *l;
|
||||
for (l = a->list ; l ; l = l->next)
|
||||
set_redraw(l->data);
|
||||
((Area*)l->data)->redraw = 1;
|
||||
// set_redraw(l->data);
|
||||
|
||||
//printf("draw area posx %d, width %d\n", a->posx, a->width);
|
||||
draw(a);
|
||||
|
@ -104,56 +159,6 @@ void refresh (Area *a)
|
|||
}
|
||||
|
||||
|
||||
void size_by_content (Area *a)
|
||||
{
|
||||
// don't draw and resize hide objects
|
||||
if (!a->on_screen) return;
|
||||
|
||||
// children node are resized before its parent
|
||||
GSList *l;
|
||||
for (l = a->list; l ; l = l->next)
|
||||
size_by_content(l->data);
|
||||
|
||||
// calculate current 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);
|
||||
a->redraw = 1;
|
||||
((Area*)a->parent)->resize = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void size_by_layout (Area *a)
|
||||
{
|
||||
// don't draw and resize hide objects
|
||||
if (!a->on_screen) return;
|
||||
|
||||
// parent node is resized before its children
|
||||
// calculate current 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (l = a->list; l ; l = l->next)
|
||||
size_by_layout(l->data);
|
||||
}
|
||||
|
||||
|
||||
void set_redraw (Area *a)
|
||||
{
|
||||
a->redraw = 1;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue