summaryrefslogtreecommitdiff
path: root/x11-wm/icewm/files/patch-ak
blob: 88a64b028ff62bb84c5484593eb77b18922fbd3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--- src/aapm.cc.orig	Mon Jan 15 06:49:39 2001
+++ src/aapm.cc	Mon Jan 15 22:18:05 2001
@@ -21,15 +21,32 @@
 #include <string.h>
 #include <stdio.h>
 
+#ifdef __FreeBSD__
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <machine/apm_bios.h>
+#endif
+
 #ifdef CONFIG_APPLET_APM
 
 YColor *YApm::apmBg = 0;
 YColor *YApm::apmFg = 0;
 YFont *YApm::apmFont = 0;
 
+#ifdef __FreeBSD__
+#define APMDEV "/dev/apm"
+#else
+#define APMDEV "/proc/apm"
+#endif
+
 void ApmStr(char *s, bool Tool) {
+#ifdef __FreeBSD__
+    struct apm_info ai;
+#else
     char buf[45];
-    int len, i, fd = open("/proc/apm", O_RDONLY);
+#endif
+    int len, i, fd = open(APMDEV, O_RDONLY);
     char driver[16];
     char apmver[16];
     int apmflags;
@@ -41,9 +58,27 @@
     char units[16];
 
     if (fd == -1) {
+        static int error = 0;
+        if (!error)
+            perror("Can't open the apm device");
+        error = 1;
         return ;
     }
-
+#ifdef __FreeBSD__
+    if (ioctl(fd,APMIO_GETINFO, &ai) == -1)
+    {
+        static int error = 0;
+        if (!error)
+            perror("Can't ioctl the apm device");
+        error = 1;
+        close(fd);
+        return;
+    }
+    close(fd);
+    BATlife = ai.ai_batt_life;
+    ACstatus = ai.ai_acline ;
+    BATflag = ai.ai_batt_stat == 3 ? 8 : 0;
+#else
     len = read(fd, buf, sizeof(buf) - 1);
     close(fd);
 
@@ -61,6 +96,7 @@
         }
         return ;
     }
+#endif
     if (BATlife == -1)
         BATlife = 0;