cleanup : Area posx/posy managed by layering engine (area.c)
git-svn-id: http://tint2.googlecode.com/svn/trunk@558 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
@@ -142,7 +142,6 @@ void init_clock_panel(void *p)
|
||||
{
|
||||
Panel *panel =(Panel*)p;
|
||||
Clock *clock = &panel->clock;
|
||||
int time_height, time_height_ink, date_height, date_height_ink;
|
||||
|
||||
clock->area.parent = p;
|
||||
clock->area.panel = p;
|
||||
@@ -156,33 +155,6 @@ void init_clock_panel(void *p)
|
||||
return;
|
||||
|
||||
clock->area.on_screen = 1;
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone));
|
||||
get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time));
|
||||
if (time2_format) {
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
|
||||
get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date));
|
||||
}
|
||||
|
||||
if (panel_horizontal) {
|
||||
// panel horizonal => fixed height and posy
|
||||
clock->area.posy = panel->area.bg->border.width + panel->area.paddingy;
|
||||
clock->area.height = panel->area.height - (2 * clock->area.posy);
|
||||
}
|
||||
else {
|
||||
// panel vertical => fixed width, posx, 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);
|
||||
clock->area.height = time_height + date_height + (2 * clock->area.paddingxlr) + (2*clock->area.bg->border.width);
|
||||
}
|
||||
|
||||
clock->time1_posy = (clock->area.height - time_height) / 2;
|
||||
if (time2_format) {
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
|
||||
get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date));
|
||||
|
||||
clock->time1_posy -= ((date_height_ink + 2) / 2);
|
||||
clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
|
||||
}
|
||||
|
||||
if (time_tooltip_format) {
|
||||
clock->area._get_tooltip_text = clock_get_tooltip;
|
||||
@@ -228,53 +200,46 @@ void draw_clock (void *obj, cairo_t *c)
|
||||
int resize_clock (void *obj)
|
||||
{
|
||||
Clock *clock = obj;
|
||||
PangoLayout *layout;
|
||||
int time_width, date_width, ret = 0;
|
||||
Panel *panel = clock->area.panel;
|
||||
int time_height_ink, time_height, time_width, date_height_ink, date_height, date_width, ret = 0;
|
||||
|
||||
clock->area.redraw = 1;
|
||||
time_width = date_width = 0;
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone));
|
||||
if (time2_format)
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
|
||||
|
||||
// vertical panel doen't adjust width
|
||||
if (!panel_horizontal) return ret;
|
||||
|
||||
//printf(" resize_clock\n");
|
||||
cairo_surface_t *cs;
|
||||
cairo_t *c;
|
||||
Pixmap pmap;
|
||||
pmap = XCreatePixmap (server.dsp, server.root_win, clock->area.width, clock->area.height, server.depth);
|
||||
|
||||
cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, clock->area.width, clock->area.height);
|
||||
c = cairo_create (cs);
|
||||
layout = pango_cairo_create_layout (c);
|
||||
|
||||
// check width/height
|
||||
pango_layout_set_font_description (layout, time1_font_desc);
|
||||
pango_layout_set_indent(layout, 0);
|
||||
pango_layout_set_text (layout, buf_time, strlen(buf_time));
|
||||
pango_layout_get_pixel_size (layout, &time_width, NULL);
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone));
|
||||
get_text_size2(time1_font_desc, &time_height_ink, &time_height, &time_width, panel->area.height, panel->area.width, buf_time, strlen(buf_time));
|
||||
if (time2_format) {
|
||||
pango_layout_set_font_description (layout, time2_font_desc);
|
||||
pango_layout_set_indent(layout, 0);
|
||||
pango_layout_set_text (layout, buf_date, strlen(buf_date));
|
||||
pango_layout_get_pixel_size (layout, &date_width, NULL);
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
|
||||
get_text_size2(time2_font_desc, &date_height_ink, &date_height, &date_width, panel->area.height, panel->area.width, buf_date, strlen(buf_date));
|
||||
}
|
||||
|
||||
if (panel_horizontal) {
|
||||
int new_size = (time_width > date_width) ? time_width : date_width;
|
||||
new_size += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width);
|
||||
if (new_size > clock->area.width || new_size < (clock->area.width-6)) {
|
||||
// we try to limit the number of resize
|
||||
clock->area.width = new_size + 1;
|
||||
clock->time1_posy = (clock->area.height - time_height) / 2;
|
||||
if (time2_format) {
|
||||
clock->time1_posy -= ((date_height_ink + 2) / 2);
|
||||
clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
|
||||
}
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int new_size = time_height + date_height + (2 * (clock->area.paddingxlr + clock->area.bg->border.width));
|
||||
if (new_size != clock->area.height) {
|
||||
// we try to limit the number of resize
|
||||
clock->area.height = new_size;
|
||||
clock->time1_posy = (clock->area.height - time_height) / 2;
|
||||
if (time2_format) {
|
||||
clock->time1_posy -= ((date_height_ink + 2) / 2);
|
||||
clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
|
||||
}
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int new_width = (time_width > date_width) ? time_width : date_width;
|
||||
new_width += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width);
|
||||
if (new_width > clock->area.width || new_width < (clock->area.width-6)) {
|
||||
// we try to limit the number of resize
|
||||
clock->area.width = new_width + 1;
|
||||
ret = 1;
|
||||
panel_refresh = 1;
|
||||
}
|
||||
|
||||
g_object_unref (layout);
|
||||
cairo_destroy (c);
|
||||
cairo_surface_destroy (cs);
|
||||
XFreePixmap (server.dsp, pmap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user