#include "epplet.h" Epplet_gadget b_close, image, label, label2; static void cb_timer(void *data); static void cb_close(void *data); static void cb_in(void *data, Window w); static void cb_out(void *data, Window w); static void cb_timer(void *data) { static FILE *f; char string[255], ac_state[16], lfc[10], rc[10], l[64]; double prc, range; f = fopen("/proc/acpi/ac_adapter/ADP0/state", "r"); if (f) { fgets(string, 255, f); sscanf(string, "%*s %s", ac_state); } printf("AC state: %s\n", ac_state); fclose(f); f = fopen("/proc/acpi/battery/BAT0/info", "r"); if (f) { while (fgets(string, 255, f) != NULL) sscanf(string, "last %*s %*s %s", lfc); } printf("last full charge: %s\n", lfc); fclose(f); f = fopen("/proc/acpi/battery/BAT0/state", "r"); if (f) { while (fgets(string, 255, f) != NULL) sscanf(string, "remaining %*s %s", rc); } printf("remaining charge: %s\n", rc); fclose(f); prc = round(floor((atof(rc) / atof(lfc)) * 100)); printf("%.0f%% remaining charge.\n", prc); if (prc < 10) range = 0; else if (prc == 100) range = 100; else range = floor((prc / 100) * 10) * 10; sprintf(l, "%.0f%%", prc); Epplet_change_label(label, l); sprintf(l, "AC: %s", ac_state); Epplet_change_label(label2, l); sprintf(string, "/usr/share/enlightenment/epplet_data/E-Power/E-Power-Bat-%.0f.png", range); printf("using image: %s\n", string); Epplet_change_image(image, 44, 24, string); Epplet_timer(cb_timer, NULL, 120.0, "TIMER"); return; data = NULL; } static void cb_close(void *data) { Epplet_unremember(); Esync(); Epplet_cleanup(); data = NULL; exit(0); } static void cb_in(void *data, Window w) { Epplet_gadget_show(b_close); return; data = NULL; w = (Window) 0; } static void cb_out(void *data, Window w) { Epplet_gadget_hide(b_close); return; data = NULL; w = (Window) 0; } int main(int argc, char **argv) { atexit(Epplet_cleanup); Epplet_Init("E-Power", "0.1", "Enlightenment Laptop Power Epplet", 3, 3, argc, argv, 0); b_close = Epplet_create_button(NULL, NULL, 2, 2, 0, 0, "CLOSE", 0, NULL, cb_close, NULL); Epplet_gadget_show(image = Epplet_create_image (2, 2, 44, 24, "/usr/share/enlightenment/epplet_data/E-Power/E-Power-Bat-100.png")); Epplet_gadget_show(label = Epplet_create_label (10, 28, "E-Power", 2)); Epplet_gadget_show(label2 = Epplet_create_label (1, 38, "E-Power", 0)); Epplet_register_focus_in_handler(cb_in, NULL); Epplet_register_focus_out_handler(cb_out, NULL); Epplet_show(); cb_timer(NULL); Epplet_Loop(); return 0; }