aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/xbattbar/files
diff options
context:
space:
mode:
authorsumikawa <sumikawa@FreeBSD.org>2006-12-14 09:59:53 +0800
committersumikawa <sumikawa@FreeBSD.org>2006-12-14 09:59:53 +0800
commitc0053a48ad51e66e0180f595d4ce70bb7b06ea59 (patch)
treef9ecc1bb57b92630609e4b80c7a4432f2275df4a /sysutils/xbattbar/files
parentb5b633d372154ab7a21493b8e374740b3ff488b5 (diff)
downloadfreebsd-ports-gnome-c0053a48ad51e66e0180f595d4ce70bb7b06ea59.tar.gz
freebsd-ports-gnome-c0053a48ad51e66e0180f595d4ce70bb7b06ea59.tar.zst
freebsd-ports-gnome-c0053a48ad51e66e0180f595d4ce70bb7b06ea59.zip
Add ACPI supporting.
Submitted by: rafan
Diffstat (limited to 'sysutils/xbattbar/files')
-rw-r--r--sysutils/xbattbar/files/patch-ab13
-rw-r--r--sysutils/xbattbar/files/patch-xbattbar.c140
2 files changed, 140 insertions, 13 deletions
diff --git a/sysutils/xbattbar/files/patch-ab b/sysutils/xbattbar/files/patch-ab
index a911d7528037..e69de29bb2d1 100644
--- a/sysutils/xbattbar/files/patch-ab
+++ b/sysutils/xbattbar/files/patch-ab
@@ -1,13 +0,0 @@
---- xbattbar.c.old Mon Dec 31 03:32:04 2001
-+++ xbattbar.c Mon Dec 31 03:32:08 2001
-@@ -522,8 +522,8 @@
- int fd, r, p;
- struct apm_info info;
-
-- if ((fd = open(APMDEV21, O_RDWR)) == -1 &&
-- (fd = open(APMDEV22, O_RDWR)) == -1) {
-+ if ((fd = open(APMDEV21, O_RDONLY)) == -1 &&
-+ (fd = open(APMDEV22, O_RDONLY)) == -1) {
- fprintf(stderr, "xbattbar: cannot open apm device\n");
- exit(1);
- }
diff --git a/sysutils/xbattbar/files/patch-xbattbar.c b/sysutils/xbattbar/files/patch-xbattbar.c
new file mode 100644
index 000000000000..3b26d420158e
--- /dev/null
+++ b/sysutils/xbattbar/files/patch-xbattbar.c
@@ -0,0 +1,140 @@
+--- xbattbar.c.orig Fri Feb 2 13:25:29 2001
++++ xbattbar.c Wed Dec 13 00:35:49 2006
+@@ -501,6 +501,10 @@
+
+ #ifdef __FreeBSD__
+
++#include <sys/types.h>
++#include <sys/sysctl.h>
++
++#if defined(__i386__)
+ #include <machine/apm_bios.h>
+
+ #define APMDEV21 "/dev/apm0"
+@@ -515,54 +519,90 @@
+ #define APM_STAT_BATT_LOW 1
+ #define APM_STAT_BATT_CRITICAL 2
+ #define APM_STAT_BATT_CHARGING 3
++#endif /* i386 */
+
+ int first = 1;
+ void battery_check(void)
+ {
+- int fd, r, p;
+- struct apm_info info;
++ int r, p;
++ static int sysctl = 1;
+
+- if ((fd = open(APMDEV21, O_RDWR)) == -1 &&
+- (fd = open(APMDEV22, O_RDWR)) == -1) {
+- fprintf(stderr, "xbattbar: cannot open apm device\n");
+- exit(1);
+- }
+- if (ioctl(fd, APMIO_GETINFO, &info) == -1) {
+- fprintf(stderr, "xbattbar: ioctl APMIO_GETINFO failed\n");
+- exit(1);
++ if (sysctl) {
++ size_t r_size, p_size;
++
++ /* get current status */
++ r_size = sizeof(r);
++ if (sysctl && sysctlbyname("hw.acpi.battery.life", &r, &r_size, NULL, 0) == -1) {
++#if defined(__i386__)
++ fprintf(stderr, "xbattbar: fall back to apm interface\n");
++ sysctl = 0;
++#else /* !i386 */
++ fprintf(stderr, "xbattbar: can not get battery status\n");
++ exit(1);
++#endif /* i386 */
++ }
++
++ /* get AC-line status */
++ p_size = sizeof(p);
++ if (sysctl && sysctlbyname("hw.acpi.acline", &p, &p_size, NULL, 0) == -1) {
++#if defined(__i386__)
++ fprintf(stderr, "xbattbar: fall back to apm interface\n");
++ sysctl = 0;
++#else /* !i386 */
++ fprintf(stderr, "xbattbar: can not get AC-line status\n");
++ exit(1);
++#endif /* i386 */
++ }
+ }
+- close (fd);
+
+- ++elapsed_time;
++#if defined(__i386__)
++ if (!sysctl) {
++ int fd;
++ struct apm_info info;
++
++ if ((fd = open(APMDEV21, O_RDONLY)) == -1 &&
++ (fd = open(APMDEV22, O_RDONLY)) == -1) {
++ fprintf(stderr, "xbattbar: cannot open apm device\n");
++ exit(1);
++ }
++ if (ioctl(fd, APMIO_GETINFO, &info) == -1) {
++ fprintf(stderr, "xbattbar: ioctl APMIO_GETINFO failed\n");
++ exit(1);
++ }
++ close (fd);
+
+- /* get current status */
+- if (info.ai_batt_life == APM_STAT_UNKNOWN) {
+- switch (info.ai_batt_stat) {
+- case APM_STAT_BATT_HIGH:
+- r = 100;
+- break;
+- case APM_STAT_BATT_LOW:
+- r = 40;
+- break;
+- case APM_STAT_BATT_CRITICAL:
+- r = 10;
+- break;
+- default: /* expected to be APM_STAT_UNKNOWN */
++ /* get current status */
++ if (info.ai_batt_life == APM_STAT_UNKNOWN) {
++ switch (info.ai_batt_stat) {
++ case APM_STAT_BATT_HIGH:
++ r = 100;
++ break;
++ case APM_STAT_BATT_LOW:
++ r = 40;
++ break;
++ case APM_STAT_BATT_CRITICAL:
++ r = 10;
++ break;
++ default: /* expected to be APM_STAT_UNKNOWN */
++ r = 100;
++ }
++ } else if (info.ai_batt_life > 100) {
++ /* some APM BIOSes return values slightly > 100 */
+ r = 100;
++ } else {
++ r = info.ai_batt_life;
+ }
+- } else if (info.ai_batt_life > 100) {
+- /* some APM BIOSes return values slightly > 100 */
+- r = 100;
+- } else {
+- r = info.ai_batt_life;
+- }
+
+- /* get AC-line status */
+- if (info.ai_acline == APM_STAT_LINE_ON) {
+- p = APM_STAT_LINE_ON;
+- } else {
+- p = APM_STAT_LINE_OFF;
++ /* get AC-line status */
++ if (info.ai_acline == APM_STAT_LINE_ON) {
++ p = APM_STAT_LINE_ON;
++ } else {
++ p = APM_STAT_LINE_OFF;
++ }
+ }
++#endif /* i386 */
++
++ ++elapsed_time;
+
+ if (first || ac_line != p || battery_level != r) {
+ first = 0;