Gentoo Archives: gentoo-commits

From: "Samuli Suominen (ssuominen)" <ssuominen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in xfce-extra/xfce4-battery-plugin/files: 0.5.1-libacpi.patch 0.5.1-2.6.24-headers.patch 0.5.1-sysfs.patch 0.5.1-freebsd.patch
Date: Fri, 28 Aug 2009 20:15:45
Message-Id: E1MftM3-0007c3-Jj@stork.gentoo.org
1 ssuominen 09/08/25 10:34:19
2
3 Added: 0.5.1-libacpi.patch 0.5.1-2.6.24-headers.patch
4 0.5.1-sysfs.patch 0.5.1-freebsd.patch
5 Log:
6 Rename xfce4-battery to xfce4-battery-plugin.
7 (Portage version: 2.2_rc40/cvs/Linux x86_64, RepoMan options: --force)
8
9 Revision Changes Path
10 1.1 xfce-extra/xfce4-battery-plugin/files/0.5.1-libacpi.patch
11
12 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-libacpi.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-libacpi.patch?rev=1.1&content-type=text/plain
14
15 Index: 0.5.1-libacpi.patch
16 ===================================================================
17 diff -ur xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.c xfce4-battery-plugin-0.5.0/panel-plugin/libacpi.c
18 --- xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.c 2007-01-17 19:56:51.000000000 +0200
19 +++ xfce4-battery-plugin-0.5.0/panel-plugin/libacpi.c 2007-02-09 16:34:40.000000000 +0200
20 @@ -30,6 +30,7 @@
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <dirent.h>
24 +#include <glob.h>
25
26 #if HAVE_SYSCTL
27
28 @@ -181,6 +182,22 @@
29 #endif
30 #endif
31
32 +/* expand file name and fopen first match */
33 +static FILE *
34 +fopen_glob(const char *name, const char *mode)
35 +{
36 + glob_t globbuf;
37 + FILE *fd;
38 +
39 + if (glob(name, 0, NULL, &globbuf) != 0)
40 + return NULL;
41 +
42 + fd = fopen(globbuf.gl_pathv[0], mode);
43 + globfree(&globbuf);
44 +
45 + return fd;
46 +}
47 +
48 /* see if we have ACPI support */
49 int check_acpi(void)
50 {
51 @@ -693,7 +710,7 @@
52 else return 0;
53 }
54 proc_fan_status="/proc/acpi/fan/*/state";
55 - if ( (fp=fopen(proc_fan_status, "r")) == NULL ) return 0;
56 + if ( (fp=fopen_glob(proc_fan_status, "r")) == NULL ) return 0;
57
58 fgets(line,255,fp);
59 fclose(fp);
60 @@ -706,10 +723,10 @@
61 {
62 #ifdef __linux__
63 FILE *fp;
64 - char *proc_temperature="/proc/acpi/thermal_zone/*0/temperature";
65 + char *proc_temperature="/proc/acpi/thermal_zone/*/temperature";
66 static char *p,line[256];
67
68 - if ( (fp=fopen(proc_temperature, "r")) == NULL) return NULL;
69 + if ( (fp=fopen_glob(proc_temperature, "r")) == NULL) return NULL;
70 fgets(line,255,fp);
71 fclose(fp);
72 p=strtok(line," ");
73
74
75
76 1.1 xfce-extra/xfce4-battery-plugin/files/0.5.1-2.6.24-headers.patch
77
78 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-2.6.24-headers.patch?rev=1.1&view=markup
79 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-2.6.24-headers.patch?rev=1.1&content-type=text/plain
80
81 Index: 0.5.1-2.6.24-headers.patch
82 ===================================================================
83 --- xfce4-battery-plugin-0.5.0/panel-plugin/libapm.h.orig 2008-03-18 20:10:58.000000000 +0100
84 +++ xfce4-battery-plugin-0.5.0/panel-plugin/libapm.h 2008-03-18 20:14:45.000000000 +0100
85 @@ -17,8 +17,8 @@
86 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
87 */
88
89 -#include <linux/apm_bios.h>
90 #include <sys/types.h>
91 +#include <linux/apm_bios.h>
92
93 #define APM_PROC "/proc/apm"
94 #define APM_DEVICE "/dev/apm_bios"
95
96
97
98 1.1 xfce-extra/xfce4-battery-plugin/files/0.5.1-sysfs.patch
99
100 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-sysfs.patch?rev=1.1&view=markup
101 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-sysfs.patch?rev=1.1&content-type=text/plain
102
103 Index: 0.5.1-sysfs.patch
104 ===================================================================
105 diff -ru xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.c xfce4-battery-plugin-0.5.0-fixed/panel-plugin/libacpi.c
106 --- xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.c 2008-04-06 02:56:10.502679698 +0200
107 +++ xfce4-battery-plugin-0.5.0-fixed/panel-plugin/libacpi.c 2008-04-06 03:15:11.306678469 +0200
108 @@ -54,6 +54,10 @@
109
110 static char batteries[MAXBATT][128];
111 static char battinfo[MAXBATT][128];
112 +/* path to AC adapter because not all AC adapter are listed
113 +in /sys/class/power_supply/AC/ this obviously only supports one AC adapter. */
114 +static char sysfsacdir[128];
115 +
116 #ifndef __linux__
117 #if HAVE_SYSCTL
118 static int
119 @@ -181,9 +185,76 @@
120 #endif
121 #endif
122
123 +int check_acpi_sysfs(void)
124 +{
125 + DIR *sysfs;
126 + struct dirent *batt;
127 + char *name;
128 + FILE *typefile;
129 + char typepath[128];
130 + char tmptype[8];
131 +
132 + sysfs = opendir("/sys/class/power_supply");
133 + if (sysfs == 0)
134 + {
135 + #ifdef DEBUG
136 + printf("DBG:No acpi support for sysfs. Trying procfs...\n");
137 + #endif
138 + return 2;
139 + }
140 +
141 + while ((batt = readdir(sysfs)))
142 + {
143 + name = batt->d_name;
144 + if (!strncmp(".", name, 1)) continue;
145 + /* check whether /sys/class/power_supply/$name/type exists and
146 + contains "Battery" or "Mains" */
147 + sprintf(typepath, "/sys/class/power_supply/%s/type",name);
148 + if(!(typefile = fopen(typepath, "r"))) continue;
149 + fgets(tmptype, 8, typefile);
150 + fclose(typefile);
151 + if(strncmp("Battery", tmptype, 7)==0)
152 + {
153 + sprintf(batteries[batt_count], "/sys/class/power_supply/%s", name);
154 + #ifdef DEBUG
155 + printf("DBG:battery number %d at:\n",batt_count);
156 + printf("DBG:sysfs dir->%s\n",batteries[batt_count]);
157 + printf("DBG:------------------------\n");
158 + #endif
159 + batt_count++;
160 + }
161 + /* I guess that the type of the AC adapter is always "Mains" (?) */
162 + else if(strncmp("Mains", tmptype, 5)==0){
163 + sprintf(sysfsacdir, "/sys/class/power_supply/%s", name);
164 + #ifdef DEBUG
165 + printf("DBG:sysfs AC dir->%s\n",sysfsacdir);
166 + printf("DBG:------------------------\n");
167 + #endif
168 + }
169 + }
170 + closedir(sysfs);
171 + if ( batt_count == 0 )
172 + {
173 +#ifdef DEBUG
174 + printf("DBG:No acpi support for sysfs. Trying procfs...\n");
175 +#endif
176 + acpi_sysfs = 0;
177 + return 2;
178 + }
179 + else
180 + {
181 + acpi_sysfs = 1;
182 + return 0;
183 + }
184 +}
185 +
186 /* see if we have ACPI support */
187 int check_acpi(void)
188 {
189 +#ifdef __linux__
190 + if ( check_acpi_sysfs() == 0 )
191 + return 0;
192 +#endif
193 DIR *battdir;
194 struct dirent *batt;
195 char *name;
196 @@ -262,9 +333,82 @@
197 #endif
198 }
199
200 +int read_sysfs_int(char* filename)
201 +{
202 + FILE* f;
203 + f = fopen(filename,"r");
204 + if ( !f )
205 + {
206 +#ifdef DEBUG
207 + printf("DBG:Could not open %s\n",filename);
208 +#endif
209 + return 0;
210 + }
211 + int out;
212 + fscanf(f,"%d",&out);
213 + fclose(f);
214 + return out;
215 +}
216 +
217 +char* read_sysfs_string(char* filename)
218 +{
219 + FILE* f;
220 + f = fopen(filename,"r");
221 + if ( !f )
222 + {
223 +#ifdef DEBUG
224 + printf("DBG:Could not open %s\n",filename);
225 +#endif
226 + return NULL;
227 + }
228 + fscanf(f,"%s",buf2);
229 + fclose(f);
230 + return buf2;
231 +}
232 +
233 +int read_acad_state_sysfs(void)
234 +{
235 + DIR *sysfs;
236 + struct dirent *propety;
237 + char *name;
238 + char onlinefilepath[128];
239 +
240 + sysfs = opendir(sysfsacdir);
241 + if (sysfs == 0)
242 + {
243 + #ifdef DEBUG
244 + printf("DBG:Can't open %s",sysfsacdir);
245 + #endif
246 + return 0;
247 + }
248 + closedir(sysfs);
249 +
250 + if (!acadstate) acadstate=(ACADstate *)malloc(sizeof(ACADstate));
251 + /* this code doesn't make much sense.. why look at the whole directory?!
252 + while ((propety = readdir(sysfs)))
253 + {
254 + name = propety->d_name;
255 + if (!strncmp(".", name, 1) || !strncmp("..", name, 2)) continue;
256 +
257 + if (strcmp(name,"online") == 0)
258 + {
259 + acadstate->state = ( read_sysfs_int("/sys/class/power_supply/AC/online") == 1 ) ;
260 + }
261 + }
262 + */
263 + sprintf(onlinefilepath, "%s/online", sysfsacdir);
264 + /* if onlinefilepath doesn't exist read_sysfs_int() will return 0
265 + so acadstate->state will be 0, that should be ok */
266 + acadstate->state = ( read_sysfs_int(onlinefilepath) == 1 );
267 +
268 + return acadstate->state;
269 +}
270 +
271 int read_acad_state(void)
272 {
273 #ifdef __linux__
274 + if (acpi_sysfs)
275 + return read_acad_state_sysfs();
276 FILE *acpi;
277 char *ptr;
278 char stat;
279 @@ -354,20 +498,83 @@
280 #endif
281 }
282
283 +int read_acpi_info_sysfs(int battery)
284 +{
285 + DIR *sysfs;
286 + struct dirent *propety;
287 + char *name;
288 +
289 + sysfs = opendir(batteries[battery]);
290 + if (sysfs == 0)
291 + {
292 + #ifdef DEBUG
293 + printf("DBG:Can't open %s!\n", batteries[battery]);
294 + #endif
295 + return 0;
296 + }
297 + /* malloc.. might explain the random battery level values on 2.6.24
298 + systems (energe_full is called charge_full so the value isn't initialised
299 + and some random data from the heap is displayed..)
300 + if (!acpiinfo) acpiinfo=(ACPIinfo *)malloc(sizeof(ACPIinfo));
301 + */
302 + if (!acpiinfo) acpiinfo=(ACPIinfo *)calloc(1, sizeof(ACPIinfo));
303 +
304 + while ((propety = readdir(sysfs)))
305 + {
306 + name = propety->d_name;
307 + if (!strncmp(".", name, 1) || !strncmp("..", name, 2)) continue;
308 + /* at least on my system this is called charge_full */
309 + if ((strcmp(name,"energy_full") == 0) || (strcmp(name,"charge_full") == 0))
310 + {
311 + sprintf(buf,"%s/%s",batteries[battery], name);
312 + acpiinfo->last_full_capacity = read_sysfs_int(buf);
313 + }
314 + if ((strcmp(name,"energy_full_design") == 0) || (strcmp(name,"charge_full_design") == 0))
315 + {
316 + sprintf(buf,"%s/%s",batteries[battery], name);
317 + acpiinfo->design_capacity = read_sysfs_int(buf);
318 + }
319 + if (strcmp(name,"technology") == 0)
320 + {
321 + char *tmp;
322 + sprintf(buf,"%s/%s",batteries[battery], name);
323 + tmp = read_sysfs_string(buf);
324 + if (tmp != NULL)
325 + {
326 + if (strcmp(tmp,"Li-ion") == 0)
327 + acpiinfo->battery_technology = 1;
328 + else
329 + acpiinfo->battery_technology = 0;
330 + }
331 + }
332 + if (strcmp(name,"present") == 0)
333 + {
334 + sprintf(buf,"%s/%s",batteries[battery], name);
335 + acpiinfo->present = read_sysfs_int(buf);
336 + }
337 + }
338 + closedir(sysfs);
339 + return acpiinfo->present;
340 +}
341 +
342 int read_acpi_info(int battery)
343 {
344 #ifdef __linux__
345 - FILE *acpi;
346 - char *ptr;
347 - char stat;
348 - int temp;
349 -
350 if (battery > MAXBATT) {
351 #ifdef DEBUG
352 printf("DBG: error, battery > MAXBATT (%d)\n",MAXBATT);
353 #endif
354 return 0;
355 }
356 +
357 + if (acpi_sysfs)
358 + return read_acpi_info_sysfs(battery);
359 +
360 + FILE *acpi;
361 + char *ptr;
362 + char stat;
363 + int temp;
364 +
365 if (!(acpi = fopen (battinfo[battery], "r"))) {
366 #ifdef DEBUG
367 printf("DBG:cannot open %s for read!\n",battinfo[battery]);
368 @@ -514,9 +721,80 @@
369
370 }
371
372 +int read_acpi_state_sysfs(int battery)
373 +{
374 + DIR *sysfs;
375 + struct dirent *propety;
376 + char *name;
377 +
378 + sysfs = opendir(batteries[battery]);
379 + if (sysfs == 0)
380 + {
381 + #ifdef DEBUG
382 + printf("DBG:Can't open %s!\n", batteries[battery]);
383 + #endif
384 + return 0;
385 + }
386 +
387 + /* again it might be better to use calloc
388 + if (!acpistate) acpistate=(ACPIstate *)malloc(sizeof(ACPIstate));
389 + */
390 + if (!acpistate) acpistate=(ACPIstate *)calloc(1, sizeof(ACPIstate));
391 +
392 + while ((propety = readdir(sysfs)))
393 + {
394 + name = propety->d_name;
395 + if (!strncmp(".", name, 1) || !strncmp("..", name, 2)) continue;
396 +
397 + if (strcmp(name,"status") == 0)
398 + {
399 + char *tmp;
400 + sprintf(buf,"%s/%s",batteries[battery], name);
401 + tmp = read_sysfs_string(buf);
402 + if ( tmp != NULL )
403 + {
404 + if (strcmp(tmp,"Charging") == 0)
405 + acpistate->state = CHARGING;
406 + else if (strcmp(tmp,"Discharging") == 0)
407 + acpistate->state = DISCHARGING;
408 + else if (strcmp(tmp,"Full") == 0)
409 + acpistate->state = POWER;
410 + else
411 + acpistate->state = UNKNOW;
412 + }
413 + }
414 + /* on my system this is called charge_now */
415 + if ((strcmp(name,"energy_now") == 0) || (strcmp(name,"charge_now") == 0))
416 + {
417 + sprintf(buf,"%s/%s",batteries[battery], name);
418 + acpistate->rcapacity = read_sysfs_int(buf);
419 + acpistate->percentage = (((float) acpistate->rcapacity)/acpiinfo->last_full_capacity) * 100;
420 + }
421 + if (strcmp(name,"current_now") == 0)
422 + {
423 + sprintf(buf,"%s/%s",batteries[battery], name);
424 + acpistate->prate = read_sysfs_int(buf);
425 + if ( acpistate->prate < 0 )
426 + acpistate->prate = 0;
427 + if ( acpistate->prate > 0 )
428 + acpistate->rtime = (((float) acpistate->rcapacity) / acpistate->prate) * 60;
429 + }
430 + if (strcmp(name,"voltage_now") == 0)
431 + {
432 + sprintf(buf,"%s/%s",batteries[battery], name);
433 + acpistate->pvoltage = read_sysfs_int(buf);
434 + }
435 + }
436 + closedir(sysfs);
437 + return acpiinfo->present;
438 +}
439 +
440 int read_acpi_state(int battery)
441 {
442 #ifdef __linux__
443 + if (acpi_sysfs)
444 + return read_acpi_state_sysfs(battery);
445 +
446 FILE *acpi;
447 char *ptr;
448 char stat;
449 diff -ru xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.h xfce4-battery-plugin-0.5.0-fixed/panel-plugin/libacpi.h
450 --- xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.h 2007-01-17 18:56:51.000000000 +0100
451 +++ xfce4-battery-plugin-0.5.0-fixed/panel-plugin/libacpi.h 2008-04-05 22:13:55.522679792 +0200
452 @@ -80,6 +80,8 @@
453 int batt_count;
454 /* temp buffer */
455 char buf[512];
456 +char buf2[512];
457 +int acpi_sysfs;
458 #else
459 extern int batt_count;
460 extern ACPIstate *acpistate;
461
462
463
464 1.1 xfce-extra/xfce4-battery-plugin/files/0.5.1-freebsd.patch
465
466 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-freebsd.patch?rev=1.1&view=markup
467 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/xfce-extra/xfce4-battery-plugin/files/0.5.1-freebsd.patch?rev=1.1&content-type=text/plain
468
469 Index: 0.5.1-freebsd.patch
470 ===================================================================
471 --- panel-plugin/battery.c.orig 2008-09-04 22:53:40.000000000 +0200
472 +++ panel-plugin/battery.c 2008-09-08 18:12:12.000000000 +0200
473 @@ -382,6 +382,7 @@
474 rate = last_rate;
475 }
476
477 +#ifdef __linux__
478 charge = (((float)ccapacity)/((float)lcapacity))*100;
479
480 if ( last_acline )
481 @@ -394,6 +395,20 @@
482
483 last_acline = acline;
484
485 +#elif __FreeBSD__
486 + charge = acpistate->percentage;
487 +
488 + if ( last_acline )
489 + time_remaining = acpistate->rtime;
490 + else
491 + time_remaining = acpistate->rtime;
492 +
493 + if ( time_remaining < 0 )
494 + time_remaining = 0;
495 +
496 + last_acline = acline;
497 +#endif
498 +
499 }
500 #ifdef __linux__
501 else {