From: Hugo Villeneuve Date: Thu, 18 Jul 2013 00:14:15 +0000 (-0400) Subject: Adjust color bar to be visible for capacity >= 1% X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=3677e9ea066851bfcd62a0d6bdf777b444845579;p=dockapps%2Fdockbatmon.git Adjust color bar to be visible for capacity >= 1% --- diff --git a/src/batmon.c b/src/batmon.c index 05095c8..ed056ea 100644 --- a/src/batmon.c +++ b/src/batmon.c @@ -51,6 +51,7 @@ #include "dockapp.h" #include "dockapp-mask.xpm" +#define BAT_BORDER 2 #define BAT_W 35 #define BAT_H 49 #define BAT_TIP_W (BAT_W / 2) @@ -234,14 +235,15 @@ display_capacity(cairo_t *cr) static void draw_background(GtkWidget *clock, cairo_t *cr) { - int y; + int y_start; + int height; read_ac_status(); read_battery_status(); cairo_save(cr); - cairo_set_line_width(cr, 2); + cairo_set_line_width(cr, BAT_BORDER); /* Draw battery tip. */ color_set_gray(cr); @@ -270,12 +272,20 @@ draw_background(GtkWidget *clock, cairo_t *cr) color_set_green(cr); } - y = BAT_START_Y + BAT_TIP_H + BAT_H - ((BAT_H * capacity) / 100); + y_start = BAT_START_Y + BAT_TIP_H + BAT_H; - /* Draw remaining capacity. */ - cairo_rectangle(cr, BAT_START_X, y, BAT_W, - BAT_START_Y + BAT_TIP_H + BAT_H - y); + /* Compute colored height (no borders). */ + height = ((BAT_H - BAT_BORDER) * capacity) / 100; + + /* Make sure capacity > 0 gets a colored line. */ + if ((capacity != 0) && (height == 0)) + height = 1; + /* Add border width: */ + height += BAT_BORDER; + + /* Draw remaining capacity. */ + cairo_rectangle(cr, BAT_START_X, y_start, BAT_W, -height); cairo_fill_preserve(cr); color_set_black(cr); cairo_stroke(cr);