=== modified file 'panel-plugin/Makefile.am' --- panel-plugin/Makefile.am 2007-09-03 14:54:36 +0000 +++ panel-plugin/Makefile.am 2007-09-03 14:55:28 +0000 @@ -27,13 +27,15 @@ $(LIBXFCEGUI4_CFLAGS) \ $(LIBXFCE4UTIL_CFLAGS) \ $(GTK_CFLAGS) \ + $(GHTREAD_CFLAGS) \ $(PLATFORM_CFLAGS) xfce4_battery_plugin_LDADD = \ $(LIBXFCE4PANEL_LIBS) \ $(LIBXFCEGUI4_LIBS) \ $(LIBXFCE4UTIL_LIBS) \ - $(GTK_LIBS) + $(GTK_LIBS) \ + $(GTHREAD_LIBS) # # Desktop file === modified file 'panel-plugin/battery.c' --- panel-plugin/battery.c 2007-09-03 14:54:36 +0000 +++ panel-plugin/battery.c 2007-09-03 14:55:28 +0000 @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -1368,6 +1369,8 @@ static void battmon_construct (XfcePanelPlugin *plugin) { + if (!g_thread_supported ()) g_thread_init (NULL); + t_battmon *battmon; xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); === modified file 'panel-plugin/libacpi.c' --- panel-plugin/libacpi.c 2007-09-03 14:54:36 +0000 +++ panel-plugin/libacpi.c 2007-09-03 14:55:28 +0000 @@ -30,6 +30,7 @@ #include #include #include +#include #if HAVE_SYSCTL @@ -44,7 +45,6 @@ #include #include #include - #endif #include "libacpi.h" @@ -52,8 +52,14 @@ #define ACBASE "/proc/acpi/ac_adapter" +static char acpath[128]; +static char battinfo[MAXBATT][128]; static char batteries[MAXBATT][128]; -static char battinfo[MAXBATT][128]; + +static char acad_state[513]; +static char acpi_info[MAXBATT][513]; +static char acpi_state[MAXBATT][513]; + #ifndef __linux__ #if HAVE_SYSCTL static int @@ -203,6 +209,7 @@ /* yep, all good */ fclose (acpi); + strcpy(acad_state,""); /* now enumerate batteries */ batt_count = 0; battdir = opendir ("/proc/acpi/battery"); @@ -227,6 +234,8 @@ else fclose (acpi); sprintf (battinfo[batt_count], "/proc/acpi/battery/%s/info", name); + strcpy (acpi_info[batt_count], ""); + strcpy (acpi_state[batt_count], ""); #ifdef DEBUG printf("DBG:battery number %d at:\n",batt_count); printf("DBG:info->%s\n",battinfo[batt_count]); @@ -264,14 +273,60 @@ #endif } +typedef struct{ + char *filename; + char *output; +} request_info; + +int proc_read(request_info *req) +{ + FILE *acpi; + if (!(acpi = fopen (req->filename, "r"))) { +#ifdef DEBUG + printf("DBG:cannot open %s for read!\n",req->filename); +#endif + free(req); + return 0; + } + +#ifdef DEBUG + { + int jj= fread (req->output, 1,512, acpi); + printf("DBG:%d characters read from %s\n",jj,req->filename); + } +#else + fread (req->output, 1,512, acpi); +#endif + fclose (acpi); + free(req); + return 1; +} + +int request_proc_read(char *filename, char *output) +{ + request_info *req; + req = malloc(sizeof(request_info)); + req->filename = filename; + req->output = output; + + if (strlen(output) == 0) + { + if (!proc_read(req)) + return 0; + strcpy(buf,output); + } else { + strcpy(buf,output); + g_thread_create ((GThreadFunc)proc_read, req, 0, NULL); + } + return 1; +} + int read_acad_state(void) { #ifdef __linux__ - FILE *acpi; char *ptr; char stat; - char acpath[64]; char *name; DIR *acdir; struct dirent *ac; @@ -296,11 +351,11 @@ break; //only one ac adapter supported } closedir(acdir); - acpi = fopen (acpath, "r"); - fread (buf, 512, 1, acpi); - fclose (acpi); - if (!acadstate) acadstate=(ACADstate *)malloc(sizeof(ACADstate)); + if ( !request_proc_read(acpath, acad_state) ) + return 0; + + if (!acadstate) acadstate=(ACADstate *)malloc(sizeof(ACADstate)); if ( (ptr = strstr(buf, "state:")) ) { @@ -359,7 +414,6 @@ int read_acpi_info(int battery) { #ifdef __linux__ - FILE *acpi; char *ptr; char stat; int temp; @@ -370,22 +424,9 @@ #endif return 0; } - if (!(acpi = fopen (battinfo[battery], "r"))) { -#ifdef DEBUG - printf("DBG:cannot open %s for read!\n",battinfo[battery]); -#endif - return 0; - } - -#ifdef DEBUG - { - int jj= fread (buf, 1,512, acpi); - printf("DBG:%d characters read from %s\n",jj,battinfo[battery]); - } -#else - fread (buf, 1,512, acpi); -#endif - fclose (acpi); + + if ( !request_proc_read(battinfo[battery], acpi_info[battery]) ) + return 0; if (!acpiinfo) acpiinfo=(ACPIinfo *)malloc(sizeof(ACPIinfo)); @@ -519,22 +560,15 @@ int read_acpi_state(int battery) { #ifdef __linux__ - FILE *acpi; char *ptr; char stat; int percent = 100; /* battery percentage */ int ptemp, rate, rtime = 0; - if (!(acpi = fopen (batteries[battery], "r"))) { -#ifdef DEBUG - printf("DBG:Could not open %s (%d)\n",batteries[battery],battery); -#endif - return 0; - } + if ( !request_proc_read(batteries[battery], acpi_state[battery]) ) + return 0; - fread (buf, 512, 1, acpi); - fclose (acpi); if (!acpistate) acpistate=(ACPIstate *)malloc(sizeof(ACPIstate)); if ((ptr = strstr (buf, "present:")) || (ptr = strstr (buf, "Present:")))