]> Dogcows Code - chaz/tint2/commitdiff
fixed issue 84 with battery
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Sat, 16 May 2009 15:23:20 +0000 (15:23 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Sat, 16 May 2009 15:23:20 +0000 (15:23 +0000)
src/battery/battery.c
src/tint.c
src/tint2

index a0b122d39d21849b73d41ed599f2ee1692546c59..7bd6f949fff415443c6ddce98541e1b64c67a70a 100644 (file)
@@ -54,27 +54,27 @@ void update_battery(struct batstate *data) {
                fgets(tmp, sizeof tmp, fp);
                energy_now = atoi(tmp);
                fclose(fp);
-       } else printf("ERROR: battery applet can't open energy_now\n");
+       }
 
        fp = fopen("/sys/class/power_supply/BAT0/energy_full", "r");
        if(fp != NULL) {
                fgets(tmp, sizeof tmp, fp);
                energy_full = atoi(tmp);
                fclose(fp);
-       } else printf("ERROR: battery applet can't open energy_full\n");
+       }
 
        fp = fopen("/sys/class/power_supply/BAT0/current_now", "r");
        if(fp != NULL) {
                fgets(tmp, sizeof tmp, fp);
                current_now = atoi(tmp);
                fclose(fp);
-       } else printf("ERROR: battery applet can't open current_now\n");
+       }
 
        fp = fopen("/sys/class/power_supply/BAT0/status", "r");
        if(fp != NULL) {
                fgets(tmp, sizeof tmp, fp);
                fclose(fp);
-       } else printf("ERROR: battery applet can't open status");
+       }
 
        data->state = BATTERY_UNKNOWN;
        if(strcasecmp(tmp, "Charging\n")==0) data->state = BATTERY_CHARGING;
@@ -110,8 +110,10 @@ void update_battery(struct batstate *data) {
        data->percentage = new_percentage;
 }
 
+
 void init_battery()
 {
+       FILE *fp;
    Panel *panel;
    Battery *battery;
    int i, bat_percentage_height, bat_percentage_height_ink, bat_time_height, bat_time_height_ink;
@@ -126,6 +128,30 @@ void init_battery()
                battery->area._resize = resize_battery;
 
                if (!battery->area.on_screen) continue;
+               if((fp = fopen("/sys/class/power_supply/BAT0/energy_now", "r")) == NULL) {
+                       fprintf(stderr, "ERROR: battery applet can't open energy_now\n");
+                       panel->battery.area.on_screen = 0;
+                       continue;
+               }
+               fclose(fp);
+               if((fp = fopen("/sys/class/power_supply/BAT0/energy_full", "r")) == NULL) {
+                       fprintf(stderr, "ERROR: battery applet can't open energy_full\n");
+                       panel->battery.area.on_screen = 0;
+                       continue;
+               }
+               fclose(fp);
+               if((fp = fopen("/sys/class/power_supply/BAT0/current_now", "r")) == NULL) {
+                       fprintf(stderr, "ERROR: battery applet can't open current_now\n");
+                       panel->battery.area.on_screen = 0;
+                       continue;
+               }
+               fclose(fp);
+               if((fp = fopen("/sys/class/power_supply/BAT0/status", "r")) == NULL) {
+                       fprintf(stderr, "ERROR: battery applet can't open status");
+                       panel->battery.area.on_screen = 0;
+                       continue;
+               }
+               fclose(fp);
 
                battery->area.posy = panel->area.pix.border.width + panel->area.paddingy;
                battery->area.height = panel->area.height - (2 * battery->area.posy);
index afb83cba12bd01b297ec5882b9c2c022d92a0cc9..f1c0356657d8b2e83533669db668c2ac181949ae 100644 (file)
@@ -468,7 +468,8 @@ void event_timer()
    if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
 
        // update battery
-       update_battery(&battery_state);
+       if (panel1[0].battery.area.on_screen)
+               update_battery(&battery_state);
 
        // update clock
        time_clock.tv_sec = stv.tv_sec;
index e1830e39b541d09ac760ed6b08dd70467103034e..7e1ff5e612ece418d14b88618127b0d9fea561d0 100755 (executable)
Binary files a/src/tint2 and b/src/tint2 differ
This page took 0.037696 seconds and 4 git commands to generate.