]> Dogcows Code - chaz/tint2/blobdiff - src/battery/battery.c
lower battery drawing : update to 10s and battery_hide config
[chaz/tint2] / src / battery / battery.c
index fadf968caa7cc2ce2c5dbb95906a38864d9a84e9..d10c10163a491f62562ac03ede1255afda805dcf 100644 (file)
@@ -37,6 +37,7 @@ PangoFontDescription *bat1_font_desc=0;
 PangoFontDescription *bat2_font_desc=0;
 struct batstate battery_state;
 int battery_enabled;
+int percentage_hide = 101;
 static timeout* battery_timeout=0;
 
 static char buf_bat_percentage[10];
@@ -54,8 +55,26 @@ void update_batterys(void* arg)
 {
        int i;
        update_battery();
-       for (i=0 ; i < nb_panel ; i++)
+       for (i=0 ; i < nb_panel ; i++) {
+               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;
+               }
+               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;
+                       }
+               }
                panel1[i].battery.area.resize = 1;
+       }
 }
 
 
@@ -133,7 +152,7 @@ void init_battery()
        g_free(battery_dir);
 
        if (battery_enabled && battery_timeout==0)
-               battery_timeout = add_timeout(10, 5000, update_batterys, 0);
+               battery_timeout = add_timeout(10, 10000, update_batterys, 0);
 }
 
 
@@ -212,36 +231,30 @@ void update_battery() {
 
        fp = fopen(path_status, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
+               if (fgets(tmp, sizeof tmp, fp)) {
+                       battery_state.state = BATTERY_UNKNOWN;
+                       if(strcasecmp(tmp, "Charging\n")==0) battery_state.state = BATTERY_CHARGING;
+                       if(strcasecmp(tmp, "Discharging\n")==0) battery_state.state = BATTERY_DISCHARGING;
+                       if(strcasecmp(tmp, "Full\n")==0) battery_state.state = BATTERY_FULL;
+               }
                fclose(fp);
        }
-       battery_state.state = BATTERY_UNKNOWN;
-       if(strcasecmp(tmp, "Charging\n")==0) battery_state.state = BATTERY_CHARGING;
-       if(strcasecmp(tmp, "Discharging\n")==0) battery_state.state = BATTERY_DISCHARGING;
-       if(strcasecmp(tmp, "Full\n")==0) battery_state.state = BATTERY_FULL;
-       if (battery_state.state == BATTERY_DISCHARGING) {
-       }
-       else {
-       }
 
        fp = fopen(path_energy_now, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
-               energy_now = atoi(tmp);
+               if (fgets(tmp, sizeof tmp, fp)) energy_now = atoi(tmp);
                fclose(fp);
        }
 
        fp = fopen(path_energy_full, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
-               energy_full = atoi(tmp);
+               if (fgets(tmp, sizeof tmp, fp)) energy_full = atoi(tmp);
                fclose(fp);
        }
 
        fp = fopen(path_current_now, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
-               current_now = atoi(tmp);
+               if (fgets(tmp, sizeof tmp, fp)) current_now = atoi(tmp);
                fclose(fp);
        }
 
@@ -268,15 +281,14 @@ void update_battery() {
        if(energy_full > 0)
                new_percentage = (energy_now*100)/energy_full;
 
-  if(battery_low_status > new_percentage && battery_state.state == BATTERY_DISCHARGING && !battery_low_cmd_send) {
-    printf("battery low, executing: %s\n", battery_low_cmd);
-    if (battery_low_cmd)
-      system(battery_low_cmd);
-    battery_low_cmd_send = 1;
+       if(battery_low_status > new_percentage && battery_state.state == BATTERY_DISCHARGING && !battery_low_cmd_send) {
+               if (battery_low_cmd)
+                       if (-1 != system(battery_low_cmd))
+                               battery_low_cmd_send = 1;
+       }
+       if(battery_low_status < new_percentage && battery_state.state == BATTERY_CHARGING && battery_low_cmd_send) {
+               battery_low_cmd_send = 0;
        }
-  if(battery_low_status < new_percentage && battery_state.state == BATTERY_CHARGING && battery_low_cmd_send) {
-    battery_low_cmd_send = 0;
-  }
 
        battery_state.percentage = new_percentage;
 
This page took 0.027325 seconds and 4 git commands to generate.