+2009-02-13
+- improved object oriented layout
+- tint2 looks good for me. if you see bugs, report it.
+
2009-02-12
- fixed issue 14 : no icons
clock->area._resize = resize_clock;
if (!time1_format) return;
+ // add clock to the panel
+ panel->area.list = g_slist_append(panel->area.list, clock);
+
if (strchr(time1_format, 'S') == NULL) time_precision = 60;
else time_precision = 1;
void resize_clock (void *obj)
{
- Area *parent = ((Area*)obj)->parent;
Clock *clock = obj;
PangoLayout *layout;
int time_width, date_width, new_width;
time_width = date_width = 0;
+ clock->area.redraw = 1;
+
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
if (time2_format)
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec));
new_width += (2*clock->area.paddingxlr) + (2*clock->area.pix.border.width);
if (new_width > clock->area.width || new_width < (clock->area.width-3)) {
- // resize clock
+ int i;
+ Panel *panel = ((Area*)obj)->panel;
+
//printf("clock_width %d, new_width %d\n", clock->area.width, new_width);
+ // resize clock
clock->area.width = new_width;
- clock->area.posx = parent->width - clock->area.width - parent->paddingxlr - parent->pix.border.width;
- set_resize(parent);
+ clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.pix.border.width;
+
+ // resize other objects on panel
+ for (i=0 ; i < nb_panel ; i++) {
+ panel1[i].area.resize = 1;
+ }
+ panel_refresh = 1;
}
g_object_unref (layout);
}
init_panel();
+ // force the resize
+ for (i=0 ; i < nb_panel ; i++) {
+ panel1[i].area.resize = 1;
+ resize_clock(&panel1[i].clock);
+ }
+
init_taskbar();
visible_object();
cleanup_config();
- // force the resize (using visible_object() order)
- for (i=0 ; i < nb_panel ; i++) {
- //init_systray(&panel1[i].trayer, &panel1[i].area);
- set_resize(&panel1[i]);
- }
task_refresh_tasklist();
}
for (i=0 ; i < nb_panel ; i++) {
p = &panel1[i];
- p->area.parent = 0;
+ p->area.parent = p;
p->area.panel = p;
+ p->area.visible = 1;
+ p->area._resize = resize_panel;
p->g_taskbar.parent = p;
p->g_taskbar.panel = p;
p->g_task.area.panel = p;
else
p->area.height = p->initial_height;
+
// full width mode
if (!p->area.width)
p->area.width = server.monitor[p->monitor].width;
cleanup_taskbar();
+ // font allocated once
+ if (panel1[0].g_task.font_desc) {
+ pango_font_description_free(panel1[0].g_task.font_desc);
+ panel1[0].g_task.font_desc = 0;
+ }
+
int i;
Panel *p;
for (i=0 ; i < nb_panel ; i++) {
p = &panel1[i];
- // no free_area(&p->area) because it's the list of visible objects
- if (p->area.list) {
- g_slist_free(p->area.list);
- p->area.list = 0;
+ // freed list of visible objects
+ if (p->list_visible) {
+ g_slist_free(p->list_visible);
+ p->list_visible = 0;
}
+ free_area(&p->area);
free_area(&p->g_task.area);
free_area(&p->g_taskbar);
- free_area(&p->clock.area);
- if (p->area.pix.pmap) XFreePixmap(server.dsp, p->area.pix.pmap);
- if (p->area.pix_active.pmap) XFreePixmap(server.dsp, p->area.pix_active.pmap);
- if (p->root_pmap) XFreePixmap(server.dsp, p->root_pmap);
- if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
- }
- // font allocated once
- if (panel1[0].g_task.font_desc) pango_font_description_free(panel1[0].g_task.font_desc);
+ if (p->temp_pmap) {
+ XFreePixmap(server.dsp, p->temp_pmap);
+ p->temp_pmap = 0;
+ }
+ if (p->main_win) {
+ XDestroyWindow(server.dsp, p->main_win);
+ p->main_win = 0;
+ }
+ }
if (panel1) free(panel1);
panel1 = 0;
}
-void visual_refresh (Panel *p)
+void resize_panel(void *obj)
{
- if (p->root_pmap) XFreePixmap(server.dsp, p->root_pmap);
- p->root_pmap = XCreatePixmap(server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
+ Panel *panel = (Panel*)obj;
+ int taskbar_width, modulo_width, taskbar_on_screen;
+
+//printf("resize_panel : : posx et width des barres de taches\n");
+
+ if (panel_mode == MULTI_DESKTOP) taskbar_on_screen = panel->nb_desktop;
+ else taskbar_on_screen = 1;
+
+ taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width);
+ if (time1_format)
+ taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
+ //taskbar_width -= (panel->trayer.area.width + panel->area.paddingx);
+
+ taskbar_width = (taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx)) / taskbar_on_screen;
+
+ if (taskbar_on_screen > 1)
+ modulo_width = (taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx)) % taskbar_on_screen;
+ else
+ modulo_width = 0;
+
+ // change posx and width for all taskbar
+ int i, modulo=0, posx=0;
+ for (i=0 ; i < panel->nb_desktop ; i++) {
+ if ((i % taskbar_on_screen) == 0) {
+ posx = panel->area.pix.border.width + panel->area.paddingxlr;
+ modulo = modulo_width;
+ }
+ else posx += taskbar_width + panel->area.paddingx;
+
+ panel->taskbar[i].area.posx = posx;
+ panel->taskbar[i].area.width = taskbar_width;
+ panel->taskbar[i].area.resize = 1;
+ if (modulo) {
+ panel->taskbar[i].area.width++;
+ modulo--;
+ }
+ }
+}
- XCopyArea (server.dsp, p->area.pix.pmap, p->root_pmap, server.gc, 0, 0, p->area.width, p->area.height, 0, 0);
- // draw child object
- GSList *l = p->area.list;
- for (; l ; l = l->next) {
- refresh (l->data);
- }
+void visible_object()
+{
+ Panel *panel;
+ int i, j;
+
+ for (i=0 ; i < nb_panel ; i++) {
+ panel = &panel1[i];
- XCopyArea(server.dsp, p->root_pmap, p->main_win, server.gc, 0, 0, p->area.width, p->area.height, 0, 0);
+ // clock before taskbar because resize(clock) can resize others object
+ if (time1_format)
+ panel->clock.area.visible = 1;
+ else
+ panel->clock.area.visible = 0;
+
+ //panel->area.list = g_slist_append(panel->area.list, &panel->trayer);
- // main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
- // this feature is disabled !
- //XCopyArea (server.dsp, server.pmap, p->main_win, server.gc, p->area.paddingxlr, 0, p->area.width-(2*p->area.paddingxlr), p->area.height, 0, 0);
+ 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 or SINGLE_MONITOR) and not current desktop
+ taskbar->area.visible = 0;
+ }
+ else {
+ taskbar->area.visible = 1;
+ }
+ }
+ }
+ panel_refresh = 1;
}
}
-void visible_object()
-{
- Panel *panel;
- int i, j;
-
- for (i=0 ; i < nb_panel ; i++) {
- panel = &panel1[i];
-
- if (panel->area.list) {
- g_slist_free(panel->area.list);
- panel->area.list = 0;
- }
-
- // list of visible objects
- // start with clock because draw(clock) can resize others object
- if (time1_format)
- panel->area.list = g_slist_append(panel->area.list, &panel->clock);
-
- //panel->area.list = g_slist_append(panel->area.list, &panel->trayer);
-
- 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 or SINGLE_MONITOR) and not current desktop
- continue;
- }
-
- panel->area.list = g_slist_append(panel->area.list, taskbar);
- }
- set_redraw(&panel->area);
- }
- panel_refresh = 1;
-}
-
-
void set_panel_background(Panel *p)
{
get_root_pixmap();
if (p->area.pix.pmap) XFreePixmap (server.dsp, p->area.pix.pmap);
p->area.pix.pmap = XCreatePixmap (server.dsp, server.root_win, p->area.width, p->area.height, server.depth);
- // copy background (server.root_pmap) in panel
+ // copy background (server.root_pmap) in panel.area.pix.pmap
Window dummy;
int x, y;
XTranslateCoordinates(server.dsp, p->main_win, server.root_win, 0, 0, &x, &y, &dummy);
cairo_destroy (c);
cairo_surface_destroy (cs);
- // redraw panel
- set_redraw (&p->area);
-
- // copy background panel on desktop window
- //XCopyArea (server.dsp, p->area.pix.pmap, server.root_win, server.gc_root, 0, 0, p->area.width, p->area.height, p->posx, p->posy);
+ // redraw panel's object
+ GSList *l0;
+ Area *a;
+ for (l0 = p->area.list; l0 ; l0 = l0->next) {
+ a = l0->data;
+ set_redraw(a);
+ }
}
typedef struct {
// always start with area
+ // area.list own all objects of the panel according to config file
Area area;
+ // list of visible objects
+ GSList *list_visible;
+
// --------------------------------------------------
// panel
Window main_win;
- Pixmap root_pmap;
+ Pixmap temp_pmap;
+
// position relative to root window
int posx, posy;
int marginx, marginy;
void init_panel();
void cleanup_panel();
-void visual_refresh(Panel *p);
+void resize_panel(void *obj);
+
void set_panel_properties(Panel *p);
void visible_object();
// draw background panel
void set_panel_background(Panel *p);
+// detect witch panel
Panel *get_panel(Window win);
#endif
sysbar->area.redraw = 1;
-printf("init_systray");
+//printf("init_systray");
net_init();
}
new_tsk2->icon_width = new_tsk.icon_width;
new_tsk2->icon_height = new_tsk.icon_height;
tskbar->area.list = g_slist_append(tskbar->area.list, new_tsk2);
-
+ tskbar->area.resize = 1;
//printf("add_task panel %d, desktop %d, task %s\n", i, j, new_tsk2->title);
- // set_resize (&tskbar->area);
- if (resize_tasks (tskbar))
- set_redraw (&tskbar->area);
}
}
}
// free title and icon just for the first task
// even with task_on_all_desktop and with task_on_all_panel
//printf("remove_task %s %d\n", tsk->title, tsk->desktop);
- //printf("remove_task %s \n", tsk->title);
if (tsk->title)
free (tsk->title);
if (tsk->icon_data)
l0 = l0->next;
if (win == tsk2->win) {
tskbar->area.list = g_slist_remove(tskbar->area.list, tsk2);
- set_resize (&tskbar->area);
- set_redraw (&tskbar->area);
+ tskbar->area.resize = 1;
if (tsk2 == task_active)
task_active = 0;
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
+ if (panel->taskbar) {
+ free(panel->taskbar);
+ panel->taskbar = 0;
+ }
+
// taskbar
panel->g_taskbar._resize = resize_taskbar;
panel->g_taskbar.posy = panel->area.pix.border.width + panel->area.paddingy;
panel->g_taskbar.height = panel->area.height - (2 * panel->g_taskbar.posy);
panel->g_taskbar.redraw = 1;
+ panel->g_taskbar.visible = 1;
// task
panel->g_task.area._draw_foreground = draw_foreground_task;
panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy);
panel->g_task.area.use_active = 1;
panel->g_task.area.redraw = 1;
+ panel->g_task.area.visible = 1;
if (panel->g_task.area.pix.border.rounded > panel->g_task.area.height/2) {
panel->g_task.area.pix.border.rounded = panel->g_task.area.height/2;
tskbar = &panel->taskbar[j];
memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area));
tskbar->desktop = j;
+
+ // add taskbar to the panel
+ panel->area.list = g_slist_append(panel->area.list, tskbar);
}
}
}
void cleanup_taskbar()
{
Panel *panel;
+ Taskbar *tskbar;
int i, j;
GSList *l0;
Task *tsk;
panel = &panel1[i];
for (j=0 ; j < panel->nb_desktop ; j++) {
- l0 = panel->taskbar[j].area.list;
+ tskbar = &panel->taskbar[j];
+ l0 = tskbar->area.list;
while (l0) {
tsk = l0->data;
l0 = l0->next;
// careful : remove_task change l0->next
remove_task (tsk);
}
- free_area (&panel->taskbar[j].area);
+ free_area (&tskbar->area);
+
+ // remove taskbar from the panel
+ panel->area.list = g_slist_remove(panel->area.list, tskbar);
}
}
}
-int resize_tasks (Taskbar *taskbar)
+void resize_taskbar(void *obj)
{
- int ret, task_count, pixel_width, modulo_width=0;
- int x, taskbar_width;
- Task *tsk;
+ Taskbar *taskbar = (Taskbar*)obj;
Panel *panel = (Panel*)taskbar->area.panel;
+ int task_count, pixel_width, modulo_width=0;
+ int x, taskbar_width;
+ Task *tsk;
GSList *l;
+//printf("resize_taskbar : posx et width des taches\n");
+
+ taskbar->area.redraw = 1;
+
// new task width for 'desktop'
task_count = g_slist_length(taskbar->area.list);
-
if (!task_count) pixel_width = panel->g_task.maximum_width;
else {
taskbar_width = taskbar->area.width - (2 * panel->g_taskbar.pix.border.width) - (2 * panel->g_taskbar.paddingxlr);
else
modulo_width = taskbar_width % task_count;
}
- //printf("monitor %d, resize_tasks %d %d\n", panel->monitor, task_count, pixel_width);
if ((taskbar->task_width == pixel_width) && (taskbar->task_modulo == modulo_width)) {
- ret = 0;
}
else {
- ret = 1;
taskbar->task_width = pixel_width;
taskbar->task_modulo = modulo_width;
taskbar->text_width = pixel_width - panel->g_task.text_posx - panel->g_task.area.pix.border.width - panel->g_task.area.paddingx;
tsk = l->data;
tsk->area.posx = x;
tsk->area.width = pixel_width;
+ tsk->area.redraw = 1;
if (modulo_width) {
tsk->area.width++;
modulo_width--;
x += tsk->area.width + panel->g_taskbar.paddingx;
}
- return ret;
}
-// initialise taskbar posx and width
-void resize_taskbar(void *obj)
-{
- Panel *panel = ((Area*)obj)->panel;
- int taskbar_width, modulo_width, taskbar_on_screen;
-
- if (panel_mode == MULTI_DESKTOP) taskbar_on_screen = panel->nb_desktop;
- else taskbar_on_screen = 1;
-
- taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width);
- if (time1_format)
- taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
- //taskbar_width -= (panel->trayer.area.width + panel->area.paddingx);
-
- taskbar_width = (taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx)) / taskbar_on_screen;
-
- if (taskbar_on_screen > 1)
- modulo_width = (taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx)) % taskbar_on_screen;
- else
- modulo_width = 0;
-
- int i, modulo=0, posx=0;
- for (i=0 ; i < panel->nb_desktop ; i++) {
- if ((i % taskbar_on_screen) == 0) {
- posx = panel->area.pix.border.width + panel->area.paddingxlr;
- modulo = modulo_width;
- }
- else posx += taskbar_width + panel->area.paddingx;
-
- panel->taskbar[i].area.posx = posx;
- panel->taskbar[i].area.width = taskbar_width;
- if (modulo) {
- panel->taskbar[i].area.width++;
- modulo--;
- }
-
- set_redraw (&panel->taskbar[i].area);
- resize_tasks(&panel->taskbar[i]);
- }
-}
-
Task *task_get_task (Window win);
void task_refresh_tasklist ();
-// return 1 if task_width changed
-int resize_tasks (Taskbar *tskbar);
-
void resize_taskbar(void *obj);
int y = e->xbutton.y;
for (l0 = panel->area.list; l0 ; l0 = l0->next) {
tskbar = l0->data;
+ if (!tskbar->area.visible) continue;
if (x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
break;
}
GSList *l0;
for (l0 = panel->area.list; l0 ; l0 = l0->next) {
tskbar = l0->data;
+ if (!tskbar->area.visible) continue;
if (x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
goto suite;
}
init_taskbar();
visible_object();
for (i=0 ; i < nb_panel ; i++) {
- set_resize(&panel1[i]);
+ panel1[i].area.resize = 1;
}
task_refresh_tasklist();
panel_refresh = 1;
// task on another monitor
remove_task (tsk);
add_task (win);
+ if (win == window_get_active ()) {
+ Task *tsk = task_get_task (win);
+ tsk->area.is_active = 1;
+ task_active = tsk;
+ }
panel_refresh = 1;
}
}
int i;
for (i=0 ; i < nb_panel ; i++) {
- panel1[i].clock.area.redraw = 1;
panel1[i].clock.area.resize = 1;
}
panel_refresh = 1;
case Expose:
panel = get_panel(e.xany.window);
if (!panel) break;
- //XCopyArea (server.dsp, panel.area.pix.pmap, server.root_win, server.gc_root, 0, 0, panel.area.width, panel.area.height, server.posx, server.posy);
- //XCopyArea (server.dsp, server.pmap, panel.main_win, server.gc, panel.area.paddingxlr, 0, panel.area.width-(2*panel.area.paddingxlr), panel.area.height, 0, 0);
- XCopyArea (server.dsp, panel->root_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
+ XCopyArea (server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
break;
case PropertyNotify:
}
if (panel_refresh) {
+ panel_refresh = 0;
+
for (i=0 ; i < nb_panel ; i++) {
- visual_refresh(&panel1[i]);
- }
+ panel = &panel1[i];
+ if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
+ panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
+
+ refresh(panel);
+ XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
+ }
XFlush (server.dsp);
- panel_refresh = 0;
}
}
}
+// ****************************************************
+// main_win doesn't include panel.area.paddingx, so we have WM capabilities on left and right.
+// this feature is disabled !
+//XCopyArea (server.dsp, server.pmap, p->main_win, server.gc, p->area.paddingxlr, 0, p->area.width-(2*p->area.paddingxlr), p->area.height, 0, 0);
+//XCopyArea (server.dsp, panel.area.pix.pmap, server.root_win, server.gc_root, 0, 0, panel.area.width, panel.area.height, server.posx, server.posy);
+//XCopyArea (server.dsp, server.pmap, panel.main_win, server.gc, panel.area.paddingxlr, 0, panel.area.width-(2*panel.area.paddingxlr), panel.area.height, 0, 0);
void refresh (Area *a)
{
+ if (!a->visible) return;
if (a->resize) {
// resize can generate a redraw
- if (a->_resize)
+ if (a->_resize) {
+ //printf("resize area posx %d, width %d\n", a->posx, a->width);
a->_resize(a);
+ }
a->resize = 0;
}
if (a->redraw) {
- //printf("draw pix\n");
+ //printf("draw area posx %d, width %d\n", a->posx, a->width);
draw(a, 0);
if (a->use_active)
draw(a, 1);
// draw current Area
Pixmap *pmap = (a->is_active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
- XCopyArea (server.dsp, *pmap, ((Panel *)a->panel)->root_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
+ XCopyArea (server.dsp, *pmap, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
// and then refresh child object
GSList *l = a->list;
}
-void set_resize (Area *a)
-{
- a->resize = 1;
-
- GSList *l;
- for (l = a->list ; l ; l = l->next)
- set_resize(l->data);
-}
-
-
void draw (Area *a, int active)
{
Pixmap *pmap = (active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
- //printf("begin draw area\n");
if (*pmap) XFreePixmap (server.dsp, *pmap);
*pmap = XCreatePixmap (server.dsp, server.root_win, a->width, a->height, server.depth);
// add layer of root pixmap
- XCopyArea (server.dsp, ((Panel *)a->panel)->root_pmap, *pmap, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
+ XCopyArea (server.dsp, ((Panel *)a->panel)->temp_pmap, *pmap, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
cairo_surface_t *cs;
cairo_t *c;
x1 = X1 * ((double)a->height / 100);
y0 = Y0 * ((double)a->width / 100);
y1 = Y1 * ((double)a->width / 100);
- printf("repère (%d, %d) points (%lf, %lf) (%lf, %lf)\n", a->width, a->height, x0, y0, x1, y1);
cairo_pattern_t *linpat;
linpat = cairo_pattern_create_linear (x0, y0, x1, y1);
g_slist_free(a->list);
a->list = 0;
}
- if (a->pix.pmap) XFreePixmap (server.dsp, a->pix.pmap);
- if (a->pix_active.pmap) XFreePixmap (server.dsp, a->pix_active.pmap);
+ if (a->pix.pmap) {
+ XFreePixmap (server.dsp, a->pix.pmap);
+ a->pix.pmap = 0;
+ }
+ if (a->pix_active.pmap) {
+ XFreePixmap (server.dsp, a->pix_active.pmap);
+ a->pix_active.pmap = 0;
+ }
}
* Area manage the background and border drawing, size and padding.
* Each Area have 2 Pixmap (pix and pix_active).
*
-* Area also manage the tree of visible objects. Parent object drawn before child object.
+* Area manage the tree of all objects. Parent object drawn before child object.
* panel -> taskbars -> tasks
* -> systray -> icons
* -> clock
// list of child : Area object
GSList *list;
+ int visible;
// need compute position and width
int resize;
// need redraw Pixmap