Lines 1-269
Link Here
|
1 |
--- ./src/aapm.cc.orig 2009-01-25 09:39:51.000000000 -0500 |
1 |
--- ./src/aapm.cc.orig 2010-10-31 10:09:36.000000000 -0400 |
2 |
+++ ./src/aapm.cc 2009-09-03 16:12:50.000000000 -0400 |
2 |
+++ ./src/aapm.cc 2010-11-02 19:56:53.000000000 -0400 |
3 |
@@ -31,8 +31,12 @@ |
3 |
@@ -243,6 +243,7 @@ |
4 |
#include <sys/file.h> |
4 |
} |
5 |
#include <sys/ioctl.h> |
|
|
6 |
#include <sys/types.h> |
7 |
+#ifdef i386 |
8 |
#include <machine/apm_bios.h> |
9 |
#endif |
10 |
+#include <sys/sysctl.h> |
11 |
+#include <dev/acpica/acpiio.h> |
12 |
+#endif |
13 |
|
14 |
#ifdef __NetBSD__ |
15 |
#include <sys/file.h> |
16 |
@@ -63,7 +67,7 @@ |
17 |
|
18 |
|
5 |
|
19 |
void ApmStr(char *s, bool Tool) { |
|
|
20 |
-#ifdef __FreeBSD__ |
21 |
+#if defined(__FreeBSD__) && defined(i386) |
22 |
struct apm_info ai; |
23 |
#elif defined __NetBSD__ |
24 |
struct apm_power_info ai; |
25 |
@@ -88,7 +92,7 @@ |
26 |
error = 1; |
27 |
return ; |
28 |
} |
29 |
-#ifdef __FreeBSD__ |
30 |
+#if defined(__FreeBSD__) && defined(i386) |
31 |
if (ioctl(fd,APMIO_GETINFO, &ai) == -1) |
32 |
{ |
33 |
static int error = 0; |
34 |
@@ -231,6 +235,7 @@ |
35 |
void YApm::AcpiStr(char *s, bool Tool) { |
6 |
void YApm::AcpiStr(char *s, bool Tool) { |
|
|
7 |
+ size_t len; |
36 |
char buf[80], buf2[80], bat_info[250]; |
8 |
char buf[80], buf2[80], bat_info[250]; |
37 |
FILE *fd; |
9 |
FILE *fd; |
38 |
+ int acpifd; |
|
|
39 |
//name of the battery |
10 |
//name of the battery |
40 |
char *BATname; |
|
|
41 |
//battery is present or absent |
42 |
@@ -250,12 +255,14 @@ |
43 |
//status of ac-adapter online/offline |
44 |
int ACstatus; |
45 |
int i; |
46 |
+ size_t len; |
47 |
|
48 |
*s='\0'; |
49 |
|
50 |
//assign some default values, in case |
51 |
//the file in /proc/acpi will contain unexpected values |
52 |
ACstatus = -1; |
53 |
+#ifndef __FreeBSD__ |
54 |
if (acpiACName && acpiACName[0] != 0) { |
55 |
strcat3(buf, "/proc/acpi/ac_adapter/", acpiACName, "/state", sizeof(buf)); |
56 |
fd = fopen(buf, "r"); |
57 |
@@ -285,6 +292,17 @@ |
58 |
fclose(fd); |
59 |
} |
60 |
} |
61 |
+#else |
62 |
+ len = sizeof(i); |
63 |
+ if (sysctlbyname("hw.acpi.acline", &i, &len, NULL, 0) >= 0) { |
64 |
+ if (i == 1) |
65 |
+ ACstatus = AC_ONLINE; |
66 |
+ else if (i = 0) |
67 |
+ ACstatus = AC_OFFLINE; |
68 |
+ else |
69 |
+ ACstatus = AC_UNKNOWN; |
70 |
+ } |
71 |
+#endif |
72 |
|
73 |
int n = 0; |
74 |
for (i = 0; i < batteryNum; i++) { |
75 |
@@ -299,6 +317,7 @@ |
76 |
BATrate = -1; |
77 |
BATtime_remain = -1; |
78 |
|
79 |
+#ifndef __FreeBSD__ |
80 |
strcat3(buf, "/proc/acpi/battery/", BATname, "/state", sizeof(buf)); |
81 |
fd = fopen(buf, "r"); |
82 |
if (fd == NULL) { |
83 |
@@ -347,10 +366,43 @@ |
84 |
} |
85 |
fclose(fd); |
86 |
} |
87 |
+#else |
88 |
+ int acpifd; |
89 |
+ |
90 |
+#define ACPIDEV "/dev/acpi" |
91 |
+ acpifd = open(ACPIDEV, O_RDONLY); |
92 |
+ if (acpifd != -1) { |
93 |
+ union acpi_battery_ioctl_arg battio; |
94 |
+ |
95 |
+ battio.unit = i; |
96 |
+ if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) != -1) { |
97 |
+ if (battio.battinfo.state != ACPI_BATT_STAT_NOT_PRESENT) { |
98 |
+ BATpresent = BAT_PRESENT; |
99 |
+ if (battio.battinfo.state == 0) |
100 |
+ BATstatus = BAT_FULL; |
101 |
+ else if (battio.battinfo.state & ACPI_BATT_STAT_CHARGING) |
102 |
+ BATstatus = BAT_CHARGING; |
103 |
+ else if (battio.battinfo.state & ACPI_BATT_STAT_DISCHARG) |
104 |
+ BATstatus = BAT_DISCHARGING; |
105 |
+ else |
106 |
+ BATstatus = BAT_UNKNOWN; |
107 |
+ if (battio.battinfo.cap != -1 && acpiBatteries[i]->capacity_full != -1) |
108 |
+ BATcapacity_remain = acpiBatteries[i]->capacity_full * |
109 |
+ battio.battinfo.cap / 100; |
110 |
+ if (battio.battinfo.min != -1) |
111 |
+ BATtime_remain = battio.battinfo.min; |
112 |
+ if (battio.battinfo.rate != -1) |
113 |
+ BATrate = battio.battinfo.rate; |
114 |
+ } else |
115 |
+ BATpresent = BAT_ABSENT; |
116 |
+ } |
117 |
+ } |
118 |
+#endif |
119 |
|
120 |
if (BATpresent == BAT_PRESENT) { //battery is present now |
121 |
if (acpiBatteries[i]->present == BAT_ABSENT) { //and previously was absent |
122 |
//read full-capacity value |
123 |
+#ifndef __FreeBSD__ |
124 |
strcat3(buf, "/proc/acpi/battery/", BATname, "/info", sizeof(buf)); |
125 |
fd = fopen(buf, "r"); |
126 |
if (fd != NULL) { |
127 |
@@ -372,6 +424,21 @@ |
128 |
if (BATcapacity_remain > BATcapacity_full && BATcapacity_design > 0) |
129 |
BATcapacity_full = BATcapacity_design; |
130 |
} |
131 |
+#else |
132 |
+ union acpi_battery_ioctl_arg battio; |
133 |
+#define UNKNOWN_CAP 0xffffffff |
134 |
+#define UNKNOWN_VOLTAGE 0xffffffff |
135 |
+ |
136 |
+ battio.unit = i; |
137 |
+ if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) != -1) { |
138 |
+ if (battio.bif.dcap != UNKNOWN_CAP) |
139 |
+ BATcapacity_design = battio.bif.dcap; |
140 |
+ if (battio.bif.lfcap != UNKNOWN_CAP) |
141 |
+ BATcapacity_full = battio.bif.lfcap; |
142 |
+ if (BATcapacity_remain > BATcapacity_full && BATcapacity_design > 0) |
143 |
+ BATcapacity_full = BATcapacity_design; |
144 |
+ } |
145 |
+#endif |
146 |
acpiBatteries[i]->capacity_full = BATcapacity_full; |
147 |
} |
148 |
else { |
149 |
@@ -380,6 +447,11 @@ |
150 |
} |
151 |
acpiBatteries[i]->present = BATpresent; |
152 |
|
153 |
+#ifdef __FreeBSD__ |
154 |
+ close(acpifd); |
155 |
+#endif |
156 |
+ |
157 |
+ bat_info[0] = 0; |
158 |
if (!Tool && |
159 |
taskBarShowApmTime && |
160 |
BATpresent == BAT_PRESENT && |
161 |
@@ -387,7 +459,8 @@ |
162 |
BATstatus == BAT_DISCHARGING && |
163 |
//did we parse the needed values successfully? |
164 |
BATcapacity_full >= 0 && BATcapacity_remain >= 0 && BATrate > 0) { |
165 |
- BATtime_remain = (int) (60 * (double)(BATcapacity_remain) / BATrate); |
166 |
+ if (BATtime_remain == -1) |
167 |
+ BATtime_remain = (int) (60 * (double)(BATcapacity_remain) / BATrate); |
168 |
sprintf(bat_info, "%d:%02d", BATtime_remain / 60, BATtime_remain % 60); |
169 |
} |
170 |
else if (BATpresent == BAT_PRESENT && |
171 |
@@ -397,17 +470,19 @@ |
172 |
sprintf(bat_info, "%3.0f%%", |
173 |
100 * (double)BATcapacity_remain / BATcapacity_full); |
174 |
} |
175 |
- else { |
176 |
- //battery is absent or we didn't parse some needed values |
177 |
- bat_info[0] = 0; |
178 |
- } |
179 |
|
180 |
if (BATstatus == BAT_CHARGING) { |
181 |
if (Tool) |
182 |
strcat(bat_info, _(" - Charging")); |
183 |
else |
184 |
strcat(bat_info, _("C")); |
185 |
- } |
186 |
+ } else if (BATstatus == BAT_FULL && Tool) |
187 |
+ strcat(bat_info, _(" - Full")); |
188 |
+ |
189 |
+ if (Tool && BATrate > 0) { |
190 |
+ sprintf(buf, " %d", BATrate); |
191 |
+ strcat(bat_info, buf); |
192 |
+ } |
193 |
|
194 |
if ((n > 0) && (*bat_info)) { |
195 |
if (Tool) |
196 |
@@ -738,6 +813,7 @@ |
197 |
YApm::YApm(YWindow *aParent): YWindow(aParent) { |
198 |
struct dirent **de; |
199 |
int n, i; |
200 |
+ size_t s; |
201 |
FILE *pmu_info; |
202 |
char buf[80]; |
203 |
FILE *fd; |
204 |
@@ -747,6 +823,7 @@ |
205 |
fCurrentState = 0; |
206 |
|
207 |
//search for acpi info first |
208 |
+#ifndef __FreeBSD__ |
209 |
n = scandir("/sys/class/power_supply", &de, 0, alphasort); |
210 |
if (n < 0) { |
211 |
n = scandir("/proc/acpi/battery", &de, 0, alphasort); |
212 |
@@ -824,7 +901,34 @@ |
213 |
acpiACName = (char*)malloc(sizeof(char)); |
214 |
*acpiACName = '\0'; |
215 |
} |
216 |
+#else |
217 |
+ int acpifd; |
218 |
+ |
219 |
+ acpifd = open(ACPIDEV, O_RDONLY); |
220 |
+ if (acpifd != -1) { |
221 |
+ mode = ACPI; |
222 |
+ |
223 |
+ //scan for batteries |
224 |
+ i = 0; |
225 |
+ while (i < 64 && batteryNum < MAX_ACPI_BATTERY_NUM) { |
226 |
+ union acpi_battery_ioctl_arg battio; |
227 |
+ |
228 |
+ battio.unit = i; |
229 |
+ if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) != -1) { |
230 |
+ acpiBatteries[batteryNum] = |
231 |
+ (bat_info*)malloc(sizeof(bat_info)); |
232 |
+ asprintf(&acpiBatteries[batteryNum]->name, "Battery%d", i); |
233 |
+ //initially set as absent, to force reading of |
234 |
+ //full-capacity value |
235 |
+ acpiBatteries[batteryNum]->present = BAT_ABSENT; |
236 |
+ acpiBatteries[batteryNum]->capacity_full = -1; |
237 |
+ batteryNum++; |
238 |
+ } |
239 |
+ i++; |
240 |
+ } |
241 |
|
242 |
+ asprintf(&acpiACName, "AC1"); |
243 |
+#endif |
244 |
} else if ( (pmu_info = fopen("/proc/pmu/info", "r")) != NULL) { |
245 |
mode = PMU; |
246 |
char line[80]; |
247 |
@@ -870,7 +974,21 @@ |
248 |
} |
249 |
|
250 |
void YApm::updateToolTip() { |
251 |
- setToolTip(fCurrentState); |
252 |
+ char s[64] = {' ', ' ', ' ', 0, 0, 0, 0, 0}; |
253 |
+ |
254 |
+ switch (mode) { |
255 |
+ case ACPI: |
256 |
+ AcpiStr(s, 1); |
257 |
+ break; |
258 |
+ case APM: |
259 |
+ ApmStr(s, 1); |
260 |
+ break; |
261 |
+ case PMU: |
262 |
+ PmuStr(s, 1); |
263 |
+ break; |
264 |
+ } |
265 |
+ |
266 |
+ setToolTip(s); |
267 |
} |
268 |
|
269 |
int YApm::calcInitialWidth() { |