diff options
-rw-r--r-- | x11/gnome-applets/Makefile | 2 | ||||
-rw-r--r-- | x11/gnome-applets/files/patch-battstat-acpi | 378 | ||||
-rw-r--r-- | x11/gnomeapplets2/Makefile | 2 | ||||
-rw-r--r-- | x11/gnomeapplets2/files/patch-battstat-acpi | 378 |
4 files changed, 394 insertions, 366 deletions
diff --git a/x11/gnome-applets/Makefile b/x11/gnome-applets/Makefile index ad0a01c58..a0ea6e686 100644 --- a/x11/gnome-applets/Makefile +++ b/x11/gnome-applets/Makefile @@ -7,7 +7,7 @@ PORTNAME= gnomeapplets2 PORTVERSION= 2.8.0 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= x11 gnome MASTER_SITES= ${MASTER_SITE_GNOME} MASTER_SITE_SUBDIR= sources/gnome-applets/2.8 diff --git a/x11/gnome-applets/files/patch-battstat-acpi b/x11/gnome-applets/files/patch-battstat-acpi index da50846f1..84d1c9844 100644 --- a/x11/gnome-applets/files/patch-battstat-acpi +++ b/x11/gnome-applets/files/patch-battstat-acpi @@ -53,10 +53,185 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/battstat_applet.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/properties.Po@am__quote@ ---- battstat/acpi-freebsd.c.orig Mon Sep 27 18:39:30 2004 -+++ battstat/acpi-freebsd.c Mon Sep 27 22:08:10 2004 -@@ -0,0 +1,199 @@ -+/* battstat A GNOME battery meter for laptops. +--- battstat/acpi-freebsd.h.orig Mon Sep 27 18:39:30 2004 ++++ battstat/acpi-freebsd.h Mon Sep 27 18:39:30 2004 +@@ -0,0 +1,45 @@ ++/* ++ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org> ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. ++ */ ++ ++#ifndef __ACPI_FREEBSD_H__ ++#define __ACPI_FREEBSD_H__ ++ ++#define ACPIDEV "/dev/acpi" ++ ++#define BATT_MIN 0 ++#define BATT_MAX 64 ++ ++#define ACPI_ACLINE "hw.acpi.acline" ++#define ACPI_TIME "hw.acpi.battery.time" ++#define ACPI_LIFE "hw.acpi.battery.life" ++#define ACPI_STATE "hw.acpi.battery.state" ++ ++struct acpi_info { ++ gboolean ac_online; ++ int acpifd; ++ int max_capacity; ++ int low_capacity; ++ int critical_capacity; ++}; ++ ++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo); ++gboolean acpi_process_event(struct acpi_info * acpiinfo); ++gboolean acpi_freebsd_init(struct acpi_info * acpiinfo); ++void acpi_freebsd_cleanup(struct acpi_info * acpiinfo); ++ ++#endif /* __ACPI_FREEBSD_H__ */ +--- battstat/battstat_applet.c.orig Mon Sep 13 04:33:31 2004 ++++ battstat/battstat_applet.c Mon Sep 27 21:51:15 2004 +@@ -62,6 +62,9 @@ + #ifdef __linux__ + #include "acpi-linux.h" + #endif ++#ifdef __FreeBSD__ ++#include "acpi-freebsd.h" ++#endif + + #ifndef gettext_noop + #define gettext_noop(String) (String) +@@ -237,6 +240,24 @@ + #endif + + #ifdef __FreeBSD__ ++struct acpi_info acpiinfo; ++gboolean using_acpi; ++int acpi_count; ++ ++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo); ++ ++gboolean acpi_callback (gpointer data) ++{ ++ ProgressData * battstat = (ProgressData *) data; ++ ++ if (acpi_process_event(&acpiinfo)) { ++ acpi_freebsd_read(&apminfo, &acpiinfo); ++ pixmap_timeout(data); ++ } ++ ++ return TRUE; ++} ++ + void + apm_readinfo (PanelApplet *applet, ProgressData * battstat) + { +@@ -247,13 +268,22 @@ + int fd; + if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n"); + +- fd = open(APMDEVICE, O_RDONLY); +- if (fd == -1) cleanup (applet, 1); ++ if (using_acpi) { ++ if (acpi_count <= 0) { ++ acpi_count = 30; ++ acpi_freebsd_read(&apminfo, &acpiinfo); ++ } ++ acpi_count--; ++ } ++ else { ++ fd = open(APMDEVICE, O_RDONLY); ++ if (fd == -1) cleanup (applet, 1); + +- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) +- err(1, "ioctl(APMIO_GETINFO)"); ++ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) ++ err(1, "ioctl(APMIO_GETINFO)"); + +- close(fd); ++ close(fd); ++ } + } + #elif defined(__NetBSD__) || defined(__OpenBSD__) + void +@@ -361,7 +391,7 @@ + + #ifdef __FreeBSD__ + acline_status = apminfo.ai_acline ? 1 : 0; +- time = apminfo.ai_batt_time; ++ time = (int) (apminfo.ai_batt_time / 60); + batt_life = apminfo.ai_batt_life; + #elif defined (__NetBSD__) || defined(__OpenBSD__) + acline_status = apminfo.ac_state ? 1 : 0; +@@ -912,6 +942,13 @@ + pdata->acpiwatch = 0; + acpi_linux_cleanup(&acpiinfo); + } ++#elif defined(__FreeBSD__) ++ if (using_acpi) { ++ if (pdata->acpiwatch != 0) ++ g_source_remove(pdata->acpiwatch); ++ pdata->acpiwatch = 0; ++ acpi_freebsd_cleanup(&acpiinfo); ++ } + #endif + + if (pdata->suspend_cmd) +@@ -1052,6 +1089,7 @@ + "Lennart Poettering <lennart@poettering.de> (Linux ACPI support)", + "Seth Nickell <snickell@stanford.edu> (GNOME2 port)", + "Davyd Madeley <davyd@ucc.asn.au>", ++ "Joe Marcus Clarke <marcus@FreeBSD.org> (FreeBSD ACPI support)", + NULL + }; + +@@ -1760,11 +1798,18 @@ + using_acpi = TRUE; + acpi_count = 0; + } ++#elif defined(__FreeBSD__) ++ if (acpi_freebsd_init(&acpiinfo)) { ++ using_acpi = TRUE; ++ acpi_count = 0; ++ } ++ else ++ using_acpi = FALSE; + #endif + apm_readinfo (applet, NULL); + + #ifdef __FreeBSD__ +- if(apminfo.ai_status == 0) cleanup (applet, 2); ++ if(!using_acpi && apminfo.ai_status == 0) cleanup (applet, 2); + #endif + + battstat = g_new0 (ProgressData, 1); +@@ -1803,6 +1848,10 @@ + battstat->acpiwatch = g_io_add_watch (acpiinfo.channel, + G_IO_IN | G_IO_ERR | G_IO_HUP, + acpi_callback, battstat); ++ } ++#elif defined(__FreeBSD__) ++ if (using_acpi) { ++ battstat->acpiwatch = g_timeout_add (2000, acpi_callback, battstat); + } + #endif + +--- battstat/acpi-freebsd.c.orig Tue Sep 28 16:55:52 2004 ++++ battstat/acpi-freebsd.c Tue Sep 28 17:00:32 2004 +@@ -0,0 +1,213 @@ ++/* battstat A GNOME battery meter for laptops. + * Copyright (C) 2000 by Jörgen Pehrson <jp@spektr.eu.org> + * + * This program is free software; you can redistribute it and/or modify @@ -73,7 +248,7 @@ + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * -+ $Id: patch-battstat-acpi,v 1.1 2004-09-28 06:53:12 marcus Exp $ ++ $Id: patch-battstat-acpi,v 1.2 2004-09-28 21:04:43 marcus Exp $ + */ + +/* @@ -126,6 +301,11 @@ + union acpi_battery_ioctl_arg battio; + int i; + ++ /* We really don't have to do this here. All of the relevant battery ++ * info can be obtained through sysctl. However, one day, the rate ++ * may be useful to get time left to full charge. ++ */ ++ + for(i = BATT_MIN; i < BATT_MAX; i++) { + battio.unit = i; + if (ioctl(acpiinfo->acpifd, ACPIIO_CMBAT_GET_BIF, &battio) == -1) { @@ -237,6 +417,9 @@ + charging = TRUE; + } + else if (state & ACPI_BATT_STAT_CRITICAL) { ++ /* Add a special check here since FreeBSD's ACPI interface will tell us ++ * when the battery is critical. ++ */ + apminfo->ai_batt_stat = 2; + } + else { @@ -250,183 +433,14 @@ + apminfo->ai_batt_time = (int) ((acpiinfo->max_capacity-remain)/(float)rate * 60); + } + else -+ apminfo->ai_batt_time = -1; -+ -+ return TRUE; -+} -+#endif ---- battstat/acpi-freebsd.h.orig Mon Sep 27 18:39:30 2004 -+++ battstat/acpi-freebsd.h Mon Sep 27 18:39:30 2004 -@@ -0,0 +1,45 @@ -+/* -+ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org> -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation; either version 2 of the License, or -+ * (at your option) any later version. -+ * -+ * This program is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with this program; if not, write to the Free Software -+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. -+ */ -+ -+#ifndef __ACPI_FREEBSD_H__ -+#define __ACPI_FREEBSD_H__ -+ -+#define ACPIDEV "/dev/acpi" -+ -+#define BATT_MIN 0 -+#define BATT_MAX 64 -+ -+#define ACPI_ACLINE "hw.acpi.acline" -+#define ACPI_TIME "hw.acpi.battery.time" -+#define ACPI_LIFE "hw.acpi.battery.life" -+#define ACPI_STATE "hw.acpi.battery.state" -+ -+struct acpi_info { -+ gboolean ac_online; -+ int acpifd; -+ int max_capacity; -+ int low_capacity; -+ int critical_capacity; -+}; -+ -+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo); -+gboolean acpi_process_event(struct acpi_info * acpiinfo); -+gboolean acpi_freebsd_init(struct acpi_info * acpiinfo); -+void acpi_freebsd_cleanup(struct acpi_info * acpiinfo); -+ -+#endif /* __ACPI_FREEBSD_H__ */ ---- battstat/battstat_applet.c.orig Mon Sep 13 04:33:31 2004 -+++ battstat/battstat_applet.c Mon Sep 27 21:51:15 2004 -@@ -62,6 +62,9 @@ - #ifdef __linux__ - #include "acpi-linux.h" - #endif -+#ifdef __FreeBSD__ -+#include "acpi-freebsd.h" -+#endif - - #ifndef gettext_noop - #define gettext_noop(String) (String) -@@ -237,6 +240,24 @@ - #endif - - #ifdef __FreeBSD__ -+struct acpi_info acpiinfo; -+gboolean using_acpi; -+int acpi_count; -+ -+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo); -+ -+gboolean acpi_callback (gpointer data) -+{ -+ ProgressData * battstat = (ProgressData *) data; -+ -+ if (acpi_process_event(&acpiinfo)) { -+ acpi_freebsd_read(&apminfo, &acpiinfo); -+ pixmap_timeout(data); -+ } ++ /* This multiplication is a hack to make sure the -1 survives so the applet ++ * can process it. Battstat wants the remaining time in minutes, but ++ * ai_batt_time is in seconds. In order to make both ACPI and APM work ++ * with the fewest amount of hacks, we will just assume everything is ++ * in seconds. ++ */ ++ apminfo->ai_batt_time = -1 * 60; + + return TRUE; +} -+ - void - apm_readinfo (PanelApplet *applet, ProgressData * battstat) - { -@@ -247,13 +268,22 @@ - int fd; - if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n"); - -- fd = open(APMDEVICE, O_RDONLY); -- if (fd == -1) cleanup (applet, 1); -+ if (using_acpi) { -+ if (acpi_count <= 0) { -+ acpi_count = 30; -+ acpi_freebsd_read(&apminfo, &acpiinfo); -+ } -+ acpi_count--; -+ } -+ else { -+ fd = open(APMDEVICE, O_RDONLY); -+ if (fd == -1) cleanup (applet, 1); - -- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) -- err(1, "ioctl(APMIO_GETINFO)"); -+ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) -+ err(1, "ioctl(APMIO_GETINFO)"); - -- close(fd); -+ close(fd); -+ } - } - #elif defined(__NetBSD__) || defined(__OpenBSD__) - void -@@ -361,7 +391,7 @@ - - #ifdef __FreeBSD__ - acline_status = apminfo.ai_acline ? 1 : 0; -- time = apminfo.ai_batt_time; -+ time = (int) (apminfo.ai_batt_time / 60); - batt_life = apminfo.ai_batt_life; - #elif defined (__NetBSD__) || defined(__OpenBSD__) - acline_status = apminfo.ac_state ? 1 : 0; -@@ -912,6 +942,13 @@ - pdata->acpiwatch = 0; - acpi_linux_cleanup(&acpiinfo); - } -+#elif defined(__FreeBSD__) -+ if (using_acpi) { -+ if (pdata->acpiwatch != 0) -+ g_source_remove(pdata->acpiwatch); -+ pdata->acpiwatch = 0; -+ acpi_freebsd_cleanup(&acpiinfo); -+ } - #endif - - if (pdata->suspend_cmd) -@@ -1052,6 +1089,7 @@ - "Lennart Poettering <lennart@poettering.de> (Linux ACPI support)", - "Seth Nickell <snickell@stanford.edu> (GNOME2 port)", - "Davyd Madeley <davyd@ucc.asn.au>", -+ "Joe Marcus Clarke <marcus@FreeBSD.org> (FreeBSD ACPI support)", - NULL - }; - -@@ -1760,11 +1798,18 @@ - using_acpi = TRUE; - acpi_count = 0; - } -+#elif defined(__FreeBSD__) -+ if (acpi_freebsd_init(&acpiinfo)) { -+ using_acpi = TRUE; -+ acpi_count = 0; -+ } -+ else -+ using_acpi = FALSE; - #endif - apm_readinfo (applet, NULL); - - #ifdef __FreeBSD__ -- if(apminfo.ai_status == 0) cleanup (applet, 2); -+ if(!using_acpi && apminfo.ai_status == 0) cleanup (applet, 2); - #endif - - battstat = g_new0 (ProgressData, 1); -@@ -1803,6 +1848,10 @@ - battstat->acpiwatch = g_io_add_watch (acpiinfo.channel, - G_IO_IN | G_IO_ERR | G_IO_HUP, - acpi_callback, battstat); -+ } -+#elif defined(__FreeBSD__) -+ if (using_acpi) { -+ battstat->acpiwatch = g_timeout_add (2000, acpi_callback, battstat); - } - #endif - ++#endif diff --git a/x11/gnomeapplets2/Makefile b/x11/gnomeapplets2/Makefile index ad0a01c58..a0ea6e686 100644 --- a/x11/gnomeapplets2/Makefile +++ b/x11/gnomeapplets2/Makefile @@ -7,7 +7,7 @@ PORTNAME= gnomeapplets2 PORTVERSION= 2.8.0 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= x11 gnome MASTER_SITES= ${MASTER_SITE_GNOME} MASTER_SITE_SUBDIR= sources/gnome-applets/2.8 diff --git a/x11/gnomeapplets2/files/patch-battstat-acpi b/x11/gnomeapplets2/files/patch-battstat-acpi index da50846f1..84d1c9844 100644 --- a/x11/gnomeapplets2/files/patch-battstat-acpi +++ b/x11/gnomeapplets2/files/patch-battstat-acpi @@ -53,10 +53,185 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/battstat_applet.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/properties.Po@am__quote@ ---- battstat/acpi-freebsd.c.orig Mon Sep 27 18:39:30 2004 -+++ battstat/acpi-freebsd.c Mon Sep 27 22:08:10 2004 -@@ -0,0 +1,199 @@ -+/* battstat A GNOME battery meter for laptops. +--- battstat/acpi-freebsd.h.orig Mon Sep 27 18:39:30 2004 ++++ battstat/acpi-freebsd.h Mon Sep 27 18:39:30 2004 +@@ -0,0 +1,45 @@ ++/* ++ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org> ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. ++ */ ++ ++#ifndef __ACPI_FREEBSD_H__ ++#define __ACPI_FREEBSD_H__ ++ ++#define ACPIDEV "/dev/acpi" ++ ++#define BATT_MIN 0 ++#define BATT_MAX 64 ++ ++#define ACPI_ACLINE "hw.acpi.acline" ++#define ACPI_TIME "hw.acpi.battery.time" ++#define ACPI_LIFE "hw.acpi.battery.life" ++#define ACPI_STATE "hw.acpi.battery.state" ++ ++struct acpi_info { ++ gboolean ac_online; ++ int acpifd; ++ int max_capacity; ++ int low_capacity; ++ int critical_capacity; ++}; ++ ++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo); ++gboolean acpi_process_event(struct acpi_info * acpiinfo); ++gboolean acpi_freebsd_init(struct acpi_info * acpiinfo); ++void acpi_freebsd_cleanup(struct acpi_info * acpiinfo); ++ ++#endif /* __ACPI_FREEBSD_H__ */ +--- battstat/battstat_applet.c.orig Mon Sep 13 04:33:31 2004 ++++ battstat/battstat_applet.c Mon Sep 27 21:51:15 2004 +@@ -62,6 +62,9 @@ + #ifdef __linux__ + #include "acpi-linux.h" + #endif ++#ifdef __FreeBSD__ ++#include "acpi-freebsd.h" ++#endif + + #ifndef gettext_noop + #define gettext_noop(String) (String) +@@ -237,6 +240,24 @@ + #endif + + #ifdef __FreeBSD__ ++struct acpi_info acpiinfo; ++gboolean using_acpi; ++int acpi_count; ++ ++gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo); ++ ++gboolean acpi_callback (gpointer data) ++{ ++ ProgressData * battstat = (ProgressData *) data; ++ ++ if (acpi_process_event(&acpiinfo)) { ++ acpi_freebsd_read(&apminfo, &acpiinfo); ++ pixmap_timeout(data); ++ } ++ ++ return TRUE; ++} ++ + void + apm_readinfo (PanelApplet *applet, ProgressData * battstat) + { +@@ -247,13 +268,22 @@ + int fd; + if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n"); + +- fd = open(APMDEVICE, O_RDONLY); +- if (fd == -1) cleanup (applet, 1); ++ if (using_acpi) { ++ if (acpi_count <= 0) { ++ acpi_count = 30; ++ acpi_freebsd_read(&apminfo, &acpiinfo); ++ } ++ acpi_count--; ++ } ++ else { ++ fd = open(APMDEVICE, O_RDONLY); ++ if (fd == -1) cleanup (applet, 1); + +- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) +- err(1, "ioctl(APMIO_GETINFO)"); ++ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) ++ err(1, "ioctl(APMIO_GETINFO)"); + +- close(fd); ++ close(fd); ++ } + } + #elif defined(__NetBSD__) || defined(__OpenBSD__) + void +@@ -361,7 +391,7 @@ + + #ifdef __FreeBSD__ + acline_status = apminfo.ai_acline ? 1 : 0; +- time = apminfo.ai_batt_time; ++ time = (int) (apminfo.ai_batt_time / 60); + batt_life = apminfo.ai_batt_life; + #elif defined (__NetBSD__) || defined(__OpenBSD__) + acline_status = apminfo.ac_state ? 1 : 0; +@@ -912,6 +942,13 @@ + pdata->acpiwatch = 0; + acpi_linux_cleanup(&acpiinfo); + } ++#elif defined(__FreeBSD__) ++ if (using_acpi) { ++ if (pdata->acpiwatch != 0) ++ g_source_remove(pdata->acpiwatch); ++ pdata->acpiwatch = 0; ++ acpi_freebsd_cleanup(&acpiinfo); ++ } + #endif + + if (pdata->suspend_cmd) +@@ -1052,6 +1089,7 @@ + "Lennart Poettering <lennart@poettering.de> (Linux ACPI support)", + "Seth Nickell <snickell@stanford.edu> (GNOME2 port)", + "Davyd Madeley <davyd@ucc.asn.au>", ++ "Joe Marcus Clarke <marcus@FreeBSD.org> (FreeBSD ACPI support)", + NULL + }; + +@@ -1760,11 +1798,18 @@ + using_acpi = TRUE; + acpi_count = 0; + } ++#elif defined(__FreeBSD__) ++ if (acpi_freebsd_init(&acpiinfo)) { ++ using_acpi = TRUE; ++ acpi_count = 0; ++ } ++ else ++ using_acpi = FALSE; + #endif + apm_readinfo (applet, NULL); + + #ifdef __FreeBSD__ +- if(apminfo.ai_status == 0) cleanup (applet, 2); ++ if(!using_acpi && apminfo.ai_status == 0) cleanup (applet, 2); + #endif + + battstat = g_new0 (ProgressData, 1); +@@ -1803,6 +1848,10 @@ + battstat->acpiwatch = g_io_add_watch (acpiinfo.channel, + G_IO_IN | G_IO_ERR | G_IO_HUP, + acpi_callback, battstat); ++ } ++#elif defined(__FreeBSD__) ++ if (using_acpi) { ++ battstat->acpiwatch = g_timeout_add (2000, acpi_callback, battstat); + } + #endif + +--- battstat/acpi-freebsd.c.orig Tue Sep 28 16:55:52 2004 ++++ battstat/acpi-freebsd.c Tue Sep 28 17:00:32 2004 +@@ -0,0 +1,213 @@ ++/* battstat A GNOME battery meter for laptops. + * Copyright (C) 2000 by Jörgen Pehrson <jp@spektr.eu.org> + * + * This program is free software; you can redistribute it and/or modify @@ -73,7 +248,7 @@ + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * -+ $Id: patch-battstat-acpi,v 1.1 2004-09-28 06:53:12 marcus Exp $ ++ $Id: patch-battstat-acpi,v 1.2 2004-09-28 21:04:43 marcus Exp $ + */ + +/* @@ -126,6 +301,11 @@ + union acpi_battery_ioctl_arg battio; + int i; + ++ /* We really don't have to do this here. All of the relevant battery ++ * info can be obtained through sysctl. However, one day, the rate ++ * may be useful to get time left to full charge. ++ */ ++ + for(i = BATT_MIN; i < BATT_MAX; i++) { + battio.unit = i; + if (ioctl(acpiinfo->acpifd, ACPIIO_CMBAT_GET_BIF, &battio) == -1) { @@ -237,6 +417,9 @@ + charging = TRUE; + } + else if (state & ACPI_BATT_STAT_CRITICAL) { ++ /* Add a special check here since FreeBSD's ACPI interface will tell us ++ * when the battery is critical. ++ */ + apminfo->ai_batt_stat = 2; + } + else { @@ -250,183 +433,14 @@ + apminfo->ai_batt_time = (int) ((acpiinfo->max_capacity-remain)/(float)rate * 60); + } + else -+ apminfo->ai_batt_time = -1; -+ -+ return TRUE; -+} -+#endif ---- battstat/acpi-freebsd.h.orig Mon Sep 27 18:39:30 2004 -+++ battstat/acpi-freebsd.h Mon Sep 27 18:39:30 2004 -@@ -0,0 +1,45 @@ -+/* -+ * Copyright (C) 2004 by Joe Marcus Clarke <marcus@FreeBSD.org> -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License as published by -+ * the Free Software Foundation; either version 2 of the License, or -+ * (at your option) any later version. -+ * -+ * This program is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with this program; if not, write to the Free Software -+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. -+ */ -+ -+#ifndef __ACPI_FREEBSD_H__ -+#define __ACPI_FREEBSD_H__ -+ -+#define ACPIDEV "/dev/acpi" -+ -+#define BATT_MIN 0 -+#define BATT_MAX 64 -+ -+#define ACPI_ACLINE "hw.acpi.acline" -+#define ACPI_TIME "hw.acpi.battery.time" -+#define ACPI_LIFE "hw.acpi.battery.life" -+#define ACPI_STATE "hw.acpi.battery.state" -+ -+struct acpi_info { -+ gboolean ac_online; -+ int acpifd; -+ int max_capacity; -+ int low_capacity; -+ int critical_capacity; -+}; -+ -+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo); -+gboolean acpi_process_event(struct acpi_info * acpiinfo); -+gboolean acpi_freebsd_init(struct acpi_info * acpiinfo); -+void acpi_freebsd_cleanup(struct acpi_info * acpiinfo); -+ -+#endif /* __ACPI_FREEBSD_H__ */ ---- battstat/battstat_applet.c.orig Mon Sep 13 04:33:31 2004 -+++ battstat/battstat_applet.c Mon Sep 27 21:51:15 2004 -@@ -62,6 +62,9 @@ - #ifdef __linux__ - #include "acpi-linux.h" - #endif -+#ifdef __FreeBSD__ -+#include "acpi-freebsd.h" -+#endif - - #ifndef gettext_noop - #define gettext_noop(String) (String) -@@ -237,6 +240,24 @@ - #endif - - #ifdef __FreeBSD__ -+struct acpi_info acpiinfo; -+gboolean using_acpi; -+int acpi_count; -+ -+gboolean acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info *acpiinfo); -+ -+gboolean acpi_callback (gpointer data) -+{ -+ ProgressData * battstat = (ProgressData *) data; -+ -+ if (acpi_process_event(&acpiinfo)) { -+ acpi_freebsd_read(&apminfo, &acpiinfo); -+ pixmap_timeout(data); -+ } ++ /* This multiplication is a hack to make sure the -1 survives so the applet ++ * can process it. Battstat wants the remaining time in minutes, but ++ * ai_batt_time is in seconds. In order to make both ACPI and APM work ++ * with the fewest amount of hacks, we will just assume everything is ++ * in seconds. ++ */ ++ apminfo->ai_batt_time = -1 * 60; + + return TRUE; +} -+ - void - apm_readinfo (PanelApplet *applet, ProgressData * battstat) - { -@@ -247,13 +268,22 @@ - int fd; - if (DEBUG) g_print("apm_readinfo() (FreeBSD)\n"); - -- fd = open(APMDEVICE, O_RDONLY); -- if (fd == -1) cleanup (applet, 1); -+ if (using_acpi) { -+ if (acpi_count <= 0) { -+ acpi_count = 30; -+ acpi_freebsd_read(&apminfo, &acpiinfo); -+ } -+ acpi_count--; -+ } -+ else { -+ fd = open(APMDEVICE, O_RDONLY); -+ if (fd == -1) cleanup (applet, 1); - -- if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) -- err(1, "ioctl(APMIO_GETINFO)"); -+ if (ioctl(fd, APMIO_GETINFO, &apminfo) == -1) -+ err(1, "ioctl(APMIO_GETINFO)"); - -- close(fd); -+ close(fd); -+ } - } - #elif defined(__NetBSD__) || defined(__OpenBSD__) - void -@@ -361,7 +391,7 @@ - - #ifdef __FreeBSD__ - acline_status = apminfo.ai_acline ? 1 : 0; -- time = apminfo.ai_batt_time; -+ time = (int) (apminfo.ai_batt_time / 60); - batt_life = apminfo.ai_batt_life; - #elif defined (__NetBSD__) || defined(__OpenBSD__) - acline_status = apminfo.ac_state ? 1 : 0; -@@ -912,6 +942,13 @@ - pdata->acpiwatch = 0; - acpi_linux_cleanup(&acpiinfo); - } -+#elif defined(__FreeBSD__) -+ if (using_acpi) { -+ if (pdata->acpiwatch != 0) -+ g_source_remove(pdata->acpiwatch); -+ pdata->acpiwatch = 0; -+ acpi_freebsd_cleanup(&acpiinfo); -+ } - #endif - - if (pdata->suspend_cmd) -@@ -1052,6 +1089,7 @@ - "Lennart Poettering <lennart@poettering.de> (Linux ACPI support)", - "Seth Nickell <snickell@stanford.edu> (GNOME2 port)", - "Davyd Madeley <davyd@ucc.asn.au>", -+ "Joe Marcus Clarke <marcus@FreeBSD.org> (FreeBSD ACPI support)", - NULL - }; - -@@ -1760,11 +1798,18 @@ - using_acpi = TRUE; - acpi_count = 0; - } -+#elif defined(__FreeBSD__) -+ if (acpi_freebsd_init(&acpiinfo)) { -+ using_acpi = TRUE; -+ acpi_count = 0; -+ } -+ else -+ using_acpi = FALSE; - #endif - apm_readinfo (applet, NULL); - - #ifdef __FreeBSD__ -- if(apminfo.ai_status == 0) cleanup (applet, 2); -+ if(!using_acpi && apminfo.ai_status == 0) cleanup (applet, 2); - #endif - - battstat = g_new0 (ProgressData, 1); -@@ -1803,6 +1848,10 @@ - battstat->acpiwatch = g_io_add_watch (acpiinfo.channel, - G_IO_IN | G_IO_ERR | G_IO_HUP, - acpi_callback, battstat); -+ } -+#elif defined(__FreeBSD__) -+ if (using_acpi) { -+ battstat->acpiwatch = g_timeout_add (2000, acpi_callback, battstat); - } - #endif - ++#endif |