From 7a03bbf353324d6803aa84ca8fd41e6c6f4d099c Mon Sep 17 00:00:00 2001 From: Thierry Lorthiois Date: Sat, 18 Sep 2010 10:41:34 +0000 Subject: [PATCH] order of panel items : position of each object is update by layering engine (area) --- src/battery/battery.c | 26 +++------- src/clock/clock.c | 9 +--- src/launcher/launcher.c | 4 +- src/panel.c | 2 +- src/systray/systraybar.c | 106 +++++++++++++++++---------------------- src/taskbar/taskbar.c | 23 ++++----- src/tint.c | 8 +-- src/util/area.c | 36 +++++++++++-- src/util/area.h | 4 +- 9 files changed, 104 insertions(+), 114 deletions(-) diff --git a/src/battery/battery.c b/src/battery/battery.c index 3ad2899..8fd6aa0 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -38,11 +38,8 @@ #include "window.h" #include "server.h" -#include "area.h" #include "panel.h" -#include "taskbar.h" #include "battery.h" -#include "clock.h" #include "timer.h" #include "common.h" @@ -76,8 +73,6 @@ void update_batterys(void* arg) if (battery_state.percentage >= percentage_hide) { if (panel1[i].battery.area.on_screen == 1) { panel1[i].battery.area.on_screen = 0; - // force resize on panel - panel1[i].area.resize = 1; panel_refresh = 1; } continue; @@ -85,8 +80,6 @@ void update_batterys(void* arg) else { if (panel1[i].battery.area.on_screen == 0) { panel1[i].battery.area.on_screen = 1; - // force resize on panel - panel1[i].area.resize = 1; panel_refresh = 1; } } @@ -250,8 +243,6 @@ void init_battery_panel(void *p) } else { // panel vertical => fixed width, height, posy and posx - battery->area.posy = panel->clock.area.posy + panel->clock.area.height + panel->area.paddingx; - battery->area.height = (2 * battery->area.paddingxlr) + (bat_time_height + bat_percentage_height); battery->area.posx = panel->area.bg->border.width + panel->area.paddingy; battery->area.width = panel->area.width - (2 * panel->area.bg->border.width) - (2 * panel->area.paddingy); } @@ -465,7 +456,11 @@ int 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 ret; + if (!panel_horizontal) { +// battery->area.posy = panel->clock.area.posy + panel->clock.area.height + panel->area.paddingx; +// battery->area.height = (2 * battery->area.paddingxlr) + (bat_time_height + bat_percentage_height); + return ret; + } cairo_surface_t *cs; cairo_t *c; @@ -490,16 +485,11 @@ int resize_battery(void *obj) if(percentage_width > time_width) new_width = percentage_width; else new_width = time_width; - new_width += (2*battery->area.paddingxlr) + (2*battery->area.bg->border.width); - int old_width = battery->area.width; - - Panel *panel = ((Area*)obj)->panel; + + new_width += (2*battery->area.paddingxlr) + (2*battery->area.bg->border.width); battery->area.width = new_width + 1; - battery->area.posx = panel->area.width - battery->area.width - panel->area.paddingxlr - panel->area.bg->border.width; - 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)) { // refresh and resize other objects on panel // we try to limit the number of refresh diff --git a/src/clock/clock.c b/src/clock/clock.c index bd741c2..783f7e9 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -26,9 +26,7 @@ #include "window.h" #include "server.h" -#include "area.h" #include "panel.h" -#include "taskbar.h" #include "clock.h" #include "timer.h" #include "common.h" @@ -169,8 +167,8 @@ void init_clock_panel(void *p) } else { // panel vertical => fixed width, height, posy and posx - clock->area.posy = panel->area.bg->border.width + panel->area.paddingxlr; - clock->area.height = (2 * clock->area.paddingxlr) + (time_height + date_height); +// clock->area.posy = panel->area.bg->border.width + panel->area.paddingxlr; +// clock->area.height = (2 * clock->area.paddingxlr) + (time_height + date_height); clock->area.posx = panel->area.bg->border.width + panel->area.paddingy; clock->area.width = panel->area.width - (2 * panel->area.bg->border.width) - (2 * panel->area.paddingy); } @@ -266,7 +264,6 @@ int resize_clock (void *obj) else new_width = date_width; new_width += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width); - Panel *panel = ((Area*)obj)->panel; if (new_width > clock->area.width || new_width < (clock->area.width-6)) { // resize clock // we try to limit the number of resize @@ -277,8 +274,6 @@ int resize_clock (void *obj) ret = 1; panel_refresh = 1; } - clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.bg->border.width; - g_object_unref (layout); cairo_destroy (c); diff --git a/src/launcher/launcher.c b/src/launcher/launcher.c index 3a7c4ca..50d3829 100644 --- a/src/launcher/launcher.c +++ b/src/launcher/launcher.c @@ -223,7 +223,7 @@ int resize_launcher(void *obj) launcher->area.width = (2 * launcher->area.bg->border.width) + (2 * launcher->area.paddingxlr) + (icon_size * icons_per_row) + ((icons_per_row-1) * launcher->area.paddingx); } - launcher->area.posx = panel->area.bg->border.width + panel->area.paddingxlr; +// launcher->area.posx = panel->area.bg->border.width + panel->area.paddingxlr; launcher->area.posy = panel->area.bg->border.width; } else { @@ -238,7 +238,7 @@ int resize_launcher(void *obj) } launcher->area.posx = panel->area.bg->border.width; - launcher->area.posy = panel->area.height - panel->area.bg->border.width - panel->area.paddingxlr - launcher->area.height; +// launcher->area.posy = panel->area.height - panel->area.bg->border.width - panel->area.paddingxlr - launcher->area.height; } int i, posx, posy; diff --git a/src/panel.c b/src/panel.c index 21604e4..b3b8547 100644 --- a/src/panel.c +++ b/src/panel.c @@ -393,7 +393,7 @@ int resize_panel(void *obj) posy += panel->taskbar[i].area.height + panel->area.paddingx; } } - return 1; + return 0; } diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 9592fdc..4161a6a 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -116,6 +116,53 @@ void init_systray_panel(void *p) void draw_systray(void *obj, cairo_t *c) { + // TODO : position and size the icon window when position of systray is known + Systraybar *sysbar = obj; + Panel *panel = sysbar->area.panel; + int i, posx, posy, marging=3, icons_per_column=1, icons_per_row=1; + int icon_size = 24; + int start = panel->area.bg->border.width + panel->area.paddingy + systray.area.bg->border.width + systray.area.paddingy +marging/2; + if (panel_horizontal) { + posy = start; + posx = systray.area.posx + systray.area.bg->border.width + systray.area.paddingxlr; + } + else { + posx = start; + posy = systray.area.posy + systray.area.bg->border.width + systray.area.paddingxlr; + } + + TrayWindow *traywin; + GSList *l; + for (i=1, l = systray.list_icons; l ; i++, l = l->next) { + traywin = (TrayWindow*)l->data; + if (traywin->hide) continue; + + traywin->y = posy; + traywin->x = posx; + traywin->width = icon_size; + traywin->height = icon_size; + if (panel_horizontal) { + if (i % icons_per_column) + posy += icon_size + sysbar->area.paddingx; + else { + posy = start; + posx += (icon_size + systray.area.paddingx); + } + } + else { + if (i % icons_per_row) + posx += icon_size + systray.area.paddingx; + else { + posx = start; + posy += (icon_size + systray.area.paddingx); + } + } + + // position and size the icon window + XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size); + XResizeWindow(server.dsp, traywin->tray_id, icon_size, icon_size); + } + if (server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { if (render_background) XFreePixmap(server.dsp, render_background); render_background = XCreatePixmap(server.dsp, server.root_win, systray.area.width, systray.area.height, server.depth); @@ -129,8 +176,6 @@ void draw_systray(void *obj, cairo_t *c) int resize_systray(void *obj) { Systraybar *sysbar = obj; - Panel *panel = sysbar->area.panel; - TrayWindow *traywin; GSList *l; int count, icon_size; int icons_per_column=1, icons_per_row=1, marging=0; @@ -159,14 +204,6 @@ int resize_systray(void *obj) icons_per_row = count / icons_per_column + (count%icons_per_column != 0); systray.area.width = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_row) + ((icons_per_row-1) * systray.area.paddingx); } - - systray.area.posx = panel->area.width - panel->area.bg->border.width - panel->area.paddingxlr - systray.area.width; - if (panel->clock.area.on_screen) - systray.area.posx -= (panel->clock.area.width + panel->area.paddingx); -#ifdef ENABLE_BATTERY - if (panel->battery.area.on_screen) - systray.area.posx -= (panel->battery.area.width + panel->area.paddingx); -#endif } else { if (!count) systray.area.height = 0; @@ -178,55 +215,6 @@ int resize_systray(void *obj) icons_per_column = count / icons_per_row+ (count%icons_per_row != 0); systray.area.height = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_column) + ((icons_per_column-1) * systray.area.paddingx); } - - systray.area.posy = panel->area.bg->border.width + panel->area.paddingxlr; - if (panel->clock.area.on_screen) - systray.area.posy += (panel->clock.area.height + panel->area.paddingx); -#ifdef ENABLE_BATTERY - if (panel->battery.area.on_screen) - systray.area.posy += (panel->battery.area.height + panel->area.paddingx); -#endif - } - - int i, posx, posy; - int start = panel->area.bg->border.width + panel->area.paddingy + systray.area.bg->border.width + systray.area.paddingy +marging/2; - if (panel_horizontal) { - posy = start; - posx = systray.area.posx + systray.area.bg->border.width + systray.area.paddingxlr; - } - else { - posx = start; - posy = systray.area.posy + systray.area.bg->border.width + systray.area.paddingxlr; - } - - for (i=1, l = systray.list_icons; l ; i++, l = l->next) { - traywin = (TrayWindow*)l->data; - if (traywin->hide) continue; - - traywin->y = posy; - traywin->x = posx; - traywin->width = icon_size; - traywin->height = icon_size; - if (panel_horizontal) { - if (i % icons_per_column) - posy += icon_size + sysbar->area.paddingx; - else { - posy = start; - posx += (icon_size + systray.area.paddingx); - } - } - else { - if (i % icons_per_row) - posx += icon_size + systray.area.paddingx; - else { - posx = start; - posy += (icon_size + systray.area.paddingx); - } - } - - // position and size the icon window - XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size); - XResizeWindow(server.dsp, traywin->tray_id, icon_size, icon_size); } return 1; } diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index bb351fe..02cfbb0 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -266,7 +266,7 @@ int resize_taskbar(void *obj) if (panel_horizontal) { int pixel_width, modulo_width=0; - int x, taskbar_width; + int taskbar_width; // new task width for 'desktop' task_count = g_slist_length(taskbar->area.list); @@ -287,27 +287,24 @@ int resize_taskbar(void *obj) taskbar->text_width = pixel_width - panel->g_task.text_posx - panel->g_task.area.bg->border.width - panel->g_task.area.paddingx; // change pos_x and width for all tasks - x = taskbar->area.posx + border_width + taskbar->area.paddingxlr; for (l = taskbar->area.list; l ; l = l->next) { tsk = l->data; if (!tsk->area.on_screen) continue; - tsk->area.posx = x; set_task_redraw(tsk); // always redraw task, because the background could have changed (taskbar_active_id) tsk->area.width = pixel_width; - long value[] = { panel->posx+x, panel->posy, pixel_width, panel->area.height }; - XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4); +// TODO : move later (when posx is known) +// long value[] = { panel->posx+x, panel->posy, pixel_width, panel->area.height }; +// XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4); if (modulo_width) { tsk->area.width++; modulo_width--; } - - x += tsk->area.width + panel->g_taskbar.area.paddingx; } } else { int pixel_height, modulo_height=0; - int y, taskbar_height; + int taskbar_height; // new task width for 'desktop' task_count = g_slist_length(taskbar->area.list); @@ -328,23 +325,21 @@ int resize_taskbar(void *obj) taskbar->text_width = taskbar->area.width - (2 * panel->g_taskbar.area.paddingy) - panel->g_task.text_posx - panel->g_task.area.bg->border.width - panel->g_task.area.paddingx; // change pos_y and height for all tasks - y = taskbar->area.posy + border_width + taskbar->area.paddingxlr; for (l = taskbar->area.list; l ; l = l->next) { tsk = l->data; if (!tsk->area.on_screen) continue; - tsk->area.posy = y; set_task_redraw(tsk); // always redraw task, because the background could have changed (taskbar_active_id) tsk->area.height = pixel_height; - long value[] = { panel->posx, panel->posy+y, panel->area.width, pixel_height }; - XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4); +// TODO : move later (when posy is known) +// long value[] = { panel->posx, panel->posy+y, panel->area.width, pixel_height }; +// XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4); if (modulo_height) { tsk->area.height++; modulo_height--; } - - y += tsk->area.height + panel->g_taskbar.area.paddingx; } } return 0; } + diff --git a/src/tint.c b/src/tint.c index 0352aa8..fd89b8c 100644 --- a/src/tint.c +++ b/src/tint.c @@ -186,9 +186,7 @@ void get_snapshot(const char *path) panel->area.width = server.monitor[0].width; panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth); - size_by_content(&panel->area); - size_by_layout(&panel->area); - refresh(&panel->area); + rendering(panel); Imlib_Image img = NULL; imlib_context_set_drawable(panel->temp_pmap); @@ -777,9 +775,7 @@ start: else { 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); - size_by_content(&panel->area); - size_by_layout(&panel->area); - refresh(&panel->area); + rendering(panel); XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0); } } diff --git a/src/util/area.c b/src/util/area.c index 7455561..ce122a2 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -77,6 +77,16 @@ * ************************************************************/ +void rendering(void *obj) +{ + Panel *panel = (Panel*)obj; + + size_by_content(&panel->area); + size_by_layout(&panel->area, 0, 0); + + refresh(&panel->area); +} + void size_by_content (Area *a) { @@ -94,16 +104,16 @@ void size_by_content (Area *a) if (a->_resize) { if (a->_resize(a)) { - // 'size' changed then 'resize = 1' on the parent + // 'size' changed => 'resize = 1' on the parent and redraw object ((Area*)a->parent)->resize = 1; + a->redraw = 1; } - a->redraw = 1; } } } -void size_by_layout (Area *a) +void size_by_layout (Area *a, int pos, int level) { // don't resize hiden objects if (!a->on_screen) return; @@ -125,8 +135,24 @@ void size_by_layout (Area *a) } } - for (l = a->list; l ; l = l->next) - size_by_layout(l->data); + // update position of childs + pos += a->paddingxlr + a->bg->border.width; + int i=0; + for (l = a->list; l ; l = l->next) { + Area *child = ((Area*)l->data); + i++; + + if (pos != child->posx) { + // pos changed => redraw + child->posx = pos; + child->redraw = 1; + } + //printf("level %d, object %d, pos %d\n", level, i, pos); + + size_by_layout(child, pos, level+1); + + pos += child->width + a->paddingx; + } } diff --git a/src/util/area.h b/src/util/area.h index 77f957e..b016674 100644 --- a/src/util/area.h +++ b/src/util/area.h @@ -89,9 +89,9 @@ typedef struct { } Area; - +void rendering(void *panel); void size_by_content (Area *a); -void size_by_layout (Area *a); +void size_by_layout (Area *a, int pos, int level); // draw background and foreground void refresh (Area *a); -- 2.45.2