order of panel items : position of each object is update by layering engine (area)

git-svn-id: http://tint2.googlecode.com/svn/trunk@547 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
thilor77 2010-09-18 10:41:34 +00:00
parent 438dbfed02
commit 52eb843047
9 changed files with 116 additions and 126 deletions

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -393,7 +393,7 @@ int resize_panel(void *obj)
posy += panel->taskbar[i].area.height + panel->area.paddingx;
}
}
return 1;
return 0;
}

View file

@ -116,79 +116,11 @@ void init_systray_panel(void *p)
void draw_systray(void *obj, cairo_t *c)
{
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);
XCopyArea(server.dsp, systray.area.pix, render_background, server.gc, 0, 0, systray.area.width, systray.area.height, 0, 0);
}
refresh_systray = 1;
}
int resize_systray(void *obj)
{
// TODO : position and size the icon window when position of systray is known
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;
if (panel_horizontal)
icon_size = sysbar->area.height;
else
icon_size = sysbar->area.width;
icon_size = icon_size - (2 * sysbar->area.bg->border.width) - (2 * sysbar->area.paddingy);
if (systray_max_icon_size > 0 && icon_size > systray_max_icon_size)
icon_size = systray_max_icon_size;
count = 0;
for (l = systray.list_icons; l ; l = l->next) {
if (!((TrayWindow*)l->data)->hide)
count++;
}
//printf("count %d\n", count);
if (panel_horizontal) {
if (!count) systray.area.width = 0;
else {
int height = sysbar->area.height - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
// here icons_per_column always higher than 0
icons_per_column = (height+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
marging = height - (icons_per_column-1)*(icon_size+sysbar->area.paddingx) - icon_size;
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;
else {
int width = sysbar->area.width - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
// here icons_per_row always higher than 0
icons_per_row = (width+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
marging = width - (icons_per_row-1)*(icon_size+sysbar->area.paddingx) - icon_size;
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 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;
@ -199,6 +131,8 @@ int resize_systray(void *obj)
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;
@ -228,6 +162,60 @@ int 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);
}
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);
XCopyArea(server.dsp, systray.area.pix, render_background, server.gc, 0, 0, systray.area.width, systray.area.height, 0, 0);
}
refresh_systray = 1;
}
int resize_systray(void *obj)
{
Systraybar *sysbar = obj;
GSList *l;
int count, icon_size;
int icons_per_column=1, icons_per_row=1, marging=0;
if (panel_horizontal)
icon_size = sysbar->area.height;
else
icon_size = sysbar->area.width;
icon_size = icon_size - (2 * sysbar->area.bg->border.width) - (2 * sysbar->area.paddingy);
if (systray_max_icon_size > 0 && icon_size > systray_max_icon_size)
icon_size = systray_max_icon_size;
count = 0;
for (l = systray.list_icons; l ; l = l->next) {
if (!((TrayWindow*)l->data)->hide)
count++;
}
//printf("count %d\n", count);
if (panel_horizontal) {
if (!count) systray.area.width = 0;
else {
int height = sysbar->area.height - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
// here icons_per_column always higher than 0
icons_per_column = (height+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
marging = height - (icons_per_column-1)*(icon_size+sysbar->area.paddingx) - icon_size;
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);
}
}
else {
if (!count) systray.area.height = 0;
else {
int width = sysbar->area.width - 2*sysbar->area.bg->border.width - 2*sysbar->area.paddingy;
// here icons_per_row always higher than 0
icons_per_row = (width+sysbar->area.paddingx) / (icon_size+sysbar->area.paddingx);
marging = width - (icons_per_row-1)*(icon_size+sysbar->area.paddingx) - icon_size;
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);
}
}
return 1;
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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);