]> Dogcows Code - chaz/tint2/blobdiff - src/clock/clock.c
panel_items : fixed hide/unhide of baterry and systray
[chaz/tint2] / src / clock / clock.c
index af6778efa50a28c649d305b793288be764cd35d0..79c4266f3b239e86c318033c8a9b38833c2f459b 100644 (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"
@@ -144,46 +142,19 @@ 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;
        clock->area._draw_foreground = draw_clock;
        clock->area.size_mode = SIZE_BY_CONTENT;
        clock->area._resize = resize_clock;
+       // check consistency
+       if (time1_format == 0)
+               return;
+
        clock->area.resize = 1;
-       clock->area.redraw = 1;
        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, 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.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->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;
                strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone));
@@ -225,69 +196,51 @@ 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;
+       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;
+       
+       date_height = 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;
-
-       //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
-       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);
+       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 (time_width > date_width) new_width = time_width;
-       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
-               // printf("clock_width %d, new_width %d\n", clock->area.width, new_width);
-               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;
-               panel_refresh = 1;
+       
+       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;
+               }
        }
-       clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.bg->border.width;
-
 
-       g_object_unref (layout);
-       cairo_destroy (c);
-       cairo_surface_destroy (cs);
-       XFreePixmap (server.dsp, pmap);
+       return ret;
 }
 
 
This page took 0.028811 seconds and 4 git commands to generate.