summaryrefslogtreecommitdiffstats
path: root/x11/gnomeapplets2/files
diff options
context:
space:
mode:
authormarcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059>2004-09-28 14:53:12 +0800
committermarcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059>2004-09-28 14:53:12 +0800
commit6639295d3ad47714e594dc4b69cf94bdf90699ba (patch)
tree148948c9cf8355ff008eb355b0c4b72e87bb57fd /x11/gnomeapplets2/files
parentf3c97fedc85a1f1b96d56fa47bb234805dc03b1b (diff)
downloadmarcuscom-ports-6639295d3ad47714e594dc4b69cf94bdf90699ba.tar
marcuscom-ports-6639295d3ad47714e594dc4b69cf94bdf90699ba.tar.gz
marcuscom-ports-6639295d3ad47714e594dc4b69cf94bdf90699ba.tar.bz2
marcuscom-ports-6639295d3ad47714e594dc4b69cf94bdf90699ba.tar.lz
marcuscom-ports-6639295d3ad47714e594dc4b69cf94bdf90699ba.tar.xz
marcuscom-ports-6639295d3ad47714e594dc4b69cf94bdf90699ba.tar.zst
marcuscom-ports-6639295d3ad47714e594dc4b69cf94bdf90699ba.zip
Add ACPI support to the battstat applet. The only known issue is that
rechargning time does not work, but this is a problem with ACPI reporting on FreeBSD. Tested by: Scott Dodson <sdodson@sdodson.com> git-svn-id: svn://creme-brulee.marcuscom.com/ports/trunk@2890 df743ca5-7f9a-e211-a948-0013205c9059
Diffstat (limited to 'x11/gnomeapplets2/files')
-rw-r--r--x11/gnomeapplets2/files/patch-aa36
-rw-r--r--x11/gnomeapplets2/files/patch-battstat-acpi432
2 files changed, 463 insertions, 5 deletions
diff --git a/x11/gnomeapplets2/files/patch-aa b/x11/gnomeapplets2/files/patch-aa
index 458a8552b..373cc9a2b 100644
--- a/x11/gnomeapplets2/files/patch-aa
+++ b/x11/gnomeapplets2/files/patch-aa
@@ -1,6 +1,15 @@
---- configure.orig Wed Aug 4 00:16:47 2004
-+++ configure Wed Aug 4 00:17:57 2004
-@@ -23969,6 +23969,7 @@
+--- configure.orig Mon Sep 27 18:39:29 2004
++++ configure Mon Sep 27 18:42:06 2004
+@@ -463,7 +463,7 @@
+ # include <unistd.h>
+ #endif"
+
+-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM AWK SET_MAKE MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT INTLTOOL_DESKTOP_RULE INTLTOOL_DIRECTORY_RULE INTLTOOL_KEYS_RULE INTLTOOL_PROP_RULE INTLTOOL_OAF_RULE INTLTOOL_PONG_RULE INTLTOOL_SERVER_RULE INTLTOOL_SHEET_RULE INTLTOOL_SOUNDLIST_RULE INTLTOOL_UI_RULE INTLTOOL_XAM_RULE INTLTOOL_KBD_RULE INTLTOOL_XML_RULE INTLTOOL_CAVES_RULE INTLTOOL_SCHEMAS_RULE INTLTOOL_THEME_RULE INTLTOOL_EXTRACT INTLTOOL_MERGE INTLTOOL_UPDATE INTLTOOL_PERL CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB CXX CXXFLAGS ac_ct_CXX CXXDEPMODE CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL PATH_TO_XRDB X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS WARN_CFLAGS PKG_CONFIG GAILUTIL_CFLAGS GAILUTIL_LIBS GNOME_APPLETS_CFLAGS GNOME_APPLETS_LIBS GNOME_LIBS2_CFLAGS GNOME_LIBS2_LIBS GNOME_VFS_APPLETS_CFLAGS GNOME_VFS_APPLETS_LIBS BUILD_GNOME_VFS_APPLETS_TRUE BUILD_GNOME_VFS_APPLETS_FALSE LIBGLADE_CFLAGS LIBGLADE_LIBS GDK_PIXBUF_CSOURCE GCONFTOOL GCONF_SCHEMA_CONFIG_SOURCE GCONF_SCHEMA_FILE_DIR GCONF_SCHEMAS_INSTALL_TRUE GCONF_SCHEMAS_INSTALL_FALSE GTOP_APPLETS_CFLAGS GTOP_APPLETS_LIBS BUILD_GTOP_APPLETS_TRUE BUILD_GTOP_APPLETS_FALSE LIBXKLAVIER_CFLAGS LIBXKLAVIER_LIBS ENABLE_FLAGS_TRUE ENABLE_FLAGS_FALSE INCLUDE_GSWITCHIT_DEVEL_TRUE INCLUDE_GSWITCHIT_DEVEL_FALSE GETTEXT_PACKAGE USE_NLS MSGFMT GMSGFMT XGETTEXT CATALOGS CATOBJEXT DATADIRNAME GMOFILES INSTOBJEXT INTLLIBS PO_IN_DATADIR_TRUE PO_IN_DATADIR_FALSE POFILES POSUB MKINSTALLDIRS gnomelocaledir SCROLLKEEPER_CONFIG SCROLLKEEPER_REQUIRED JW HAVE_JW_TRUE HAVE_JW_FALSE HAVE_JW GKB_SUN_TRUE GKB_SUN_FALSE CDDA_SOLARIS_TRUE CDDA_SOLARIS_FALSE APPLET_CDPLAYER_TRUE APPLET_CDPLAYER_FALSE CDROM_HOST CDROM_LIBS HAVE_LIBAPM NEED_LIBAPM HAVE_LIBAPM_TRUE HAVE_LIBAPM_FALSE NEED_LIBAPM_TRUE NEED_LIBAPM_FALSE BUILD_BATTSTAT_APPLET_TRUE BUILD_BATTSTAT_APPLET_FALSE MIXER_CFLAGS MIXER_LIBS APPLET_MIXER_TRUE APPLET_MIXER_FALSE APPLET_ACCESSX_TRUE APPLET_ACCESSX_FALSE APPLET_GSWITCHIT_TRUE APPLET_GSWITCHIT_FALSE APPLET_MODEMLIGHTS_TRUE APPLET_MODEMLIGHTS_FALSE LIBOBJS LTLIBOBJS'
++ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO AMTAR install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM AWK SET_MAKE MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT INTLTOOL_DESKTOP_RULE INTLTOOL_DIRECTORY_RULE INTLTOOL_KEYS_RULE INTLTOOL_PROP_RULE INTLTOOL_OAF_RULE INTLTOOL_PONG_RULE INTLTOOL_SERVER_RULE INTLTOOL_SHEET_RULE INTLTOOL_SOUNDLIST_RULE INTLTOOL_UI_RULE INTLTOOL_XAM_RULE INTLTOOL_KBD_RULE INTLTOOL_XML_RULE INTLTOOL_CAVES_RULE INTLTOOL_SCHEMAS_RULE INTLTOOL_THEME_RULE INTLTOOL_EXTRACT INTLTOOL_MERGE INTLTOOL_UPDATE INTLTOOL_PERL CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os LN_S ECHO AR ac_ct_AR RANLIB ac_ct_RANLIB CXX CXXFLAGS ac_ct_CXX CXXDEPMODE CXXCPP F77 FFLAGS ac_ct_F77 LIBTOOL PATH_TO_XRDB X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS WARN_CFLAGS PKG_CONFIG GAILUTIL_CFLAGS GAILUTIL_LIBS GNOME_APPLETS_CFLAGS GNOME_APPLETS_LIBS GNOME_LIBS2_CFLAGS GNOME_LIBS2_LIBS GNOME_VFS_APPLETS_CFLAGS GNOME_VFS_APPLETS_LIBS BUILD_GNOME_VFS_APPLETS_TRUE BUILD_GNOME_VFS_APPLETS_FALSE LIBGLADE_CFLAGS LIBGLADE_LIBS GDK_PIXBUF_CSOURCE GCONFTOOL GCONF_SCHEMA_CONFIG_SOURCE GCONF_SCHEMA_FILE_DIR GCONF_SCHEMAS_INSTALL_TRUE GCONF_SCHEMAS_INSTALL_FALSE GTOP_APPLETS_CFLAGS GTOP_APPLETS_LIBS BUILD_GTOP_APPLETS_TRUE BUILD_GTOP_APPLETS_FALSE LIBXKLAVIER_CFLAGS LIBXKLAVIER_LIBS ENABLE_FLAGS_TRUE ENABLE_FLAGS_FALSE INCLUDE_GSWITCHIT_DEVEL_TRUE INCLUDE_GSWITCHIT_DEVEL_FALSE GETTEXT_PACKAGE USE_NLS MSGFMT GMSGFMT XGETTEXT CATALOGS CATOBJEXT DATADIRNAME GMOFILES INSTOBJEXT INTLLIBS PO_IN_DATADIR_TRUE PO_IN_DATADIR_FALSE POFILES POSUB MKINSTALLDIRS gnomelocaledir SCROLLKEEPER_CONFIG SCROLLKEEPER_REQUIRED JW HAVE_JW_TRUE HAVE_JW_FALSE HAVE_JW GKB_SUN_TRUE GKB_SUN_FALSE CDDA_SOLARIS_TRUE CDDA_SOLARIS_FALSE APPLET_CDPLAYER_TRUE APPLET_CDPLAYER_FALSE CDROM_HOST CDROM_LIBS ACPIINC HAVE_LIBAPM NEED_LIBAPM HAVE_LIBAPM_TRUE HAVE_LIBAPM_FALSE NEED_LIBAPM_TRUE NEED_LIBAPM_FALSE BUILD_BATTSTAT_APPLET_TRUE BUILD_BATTSTAT_APPLET_FALSE MIXER_CFLAGS MIXER_LIBS APPLET_MIXER_TRUE APPLET_MIXER_FALSE APPLET_ACCESSX_TRUE APPLET_ACCESSX_FALSE APPLET_GSWITCHIT_TRUE APPLET_GSWITCHIT_FALSE APPLET_MODEMLIGHTS_TRUE APPLET_MODEMLIGHTS_FALSE LIBOBJS LTLIBOBJS'
+ ac_subst_files=''
+
+ # Initialize some variables set by options.
+@@ -23967,6 +23967,7 @@
*irix*) CDROM_HOST=irix; CDROM_LIBS="-lcdaudio -lmediad -lds";cd_device_path="/dev/cdrom";;
*linux*) CDROM_HOST=linux;cd_device_path="/dev/cdrom";;
*netbsd*) CDROM_HOST=netbsd;cd_device_path="/dev/rcd0";;
@@ -8,16 +17,25 @@
*solaris*) CDROM_HOST=solaris;cd_device_path="/vol/dev/aliases/cdrom0";cdplayer_type_sun=true;;
esac
case "$host" in
-@@ -24181,7 +24182,7 @@
+@@ -24028,6 +24029,7 @@
+
+ HAVE_LIBAPM=no
+ NEED_LIBAPM=no
++ACPIINC=
+ build_battstat_applet=no
+
+ if test x$disable_battstat = xno; then
+@@ -24179,7 +24181,8 @@
;;
# list of supported OS cores that do not use libapm
- *-*-freebsd*|*-*-netbsd*|*-*-openbsd*)
+ i386-*-freebsd*|*-*-netbsd*|*-*-openbsd*)
++ ACPIINC="-I/usr/src/sys"
;;
*)
echo "warning: ${host} is not supported by battstat_applet, not building" >&2
-@@ -26261,14 +26262,14 @@
+@@ -26259,14 +26262,14 @@
ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
cat >>confdefs.h <<_ACEOF
@@ -34,3 +52,11 @@
_ACEOF
cat >>confdefs.h <<_ACEOF
+@@ -27413,6 +27416,7 @@
+ s,@APPLET_CDPLAYER_FALSE@,$APPLET_CDPLAYER_FALSE,;t t
+ s,@CDROM_HOST@,$CDROM_HOST,;t t
+ s,@CDROM_LIBS@,$CDROM_LIBS,;t t
++s,@ACPIINC@,$ACPIINC,;t t
+ s,@HAVE_LIBAPM@,$HAVE_LIBAPM,;t t
+ s,@NEED_LIBAPM@,$NEED_LIBAPM,;t t
+ s,@HAVE_LIBAPM_TRUE@,$HAVE_LIBAPM_TRUE,;t t
diff --git a/x11/gnomeapplets2/files/patch-battstat-acpi b/x11/gnomeapplets2/files/patch-battstat-acpi
new file mode 100644
index 000000000..da50846f1
--- /dev/null
+++ b/x11/gnomeapplets2/files/patch-battstat-acpi
@@ -0,0 +1,432 @@
+--- battstat/Makefile.in.orig Mon Sep 27 18:39:44 2004
++++ battstat/Makefile.in Mon Sep 27 18:40:56 2004
+@@ -173,6 +173,8 @@
+ pixmapsdir = $(datadir)/pixmaps
+ pixmaps_DATA = battstat.png
+
++ACPIINC = @ACPIINC@
++
+ @HAVE_LIBAPM_FALSE@@NEED_LIBAPM_TRUE@APMLIB = apmlib/libapm.a
+ @HAVE_LIBAPM_TRUE@@NEED_LIBAPM_TRUE@APMLIB = -lapm
+ @NEED_LIBAPM_FALSE@APMLIB =
+@@ -191,6 +193,7 @@
+ $(GNOME_APPLETS_CFLAGS) \
+ $(LIBGLADE_CFLAGS) \
+ $(APMINC) \
++ $(ACPIINC) \
+ -DDATA_DIR=\"$(datadir)\" \
+ -DGLADE_DIR=\"$(gladedir)\" \
+ -DG_LOG_DOMAIN=\"battstat_applet\" \
+@@ -205,7 +208,9 @@
+ properties.c \
+ battstat_applet.c \
+ acpi-linux.c \
+- acpi-linux.h
++ acpi-linux.h \
++ acpi-freebsd.c \
++ acpi-freebsd.h
+
+
+ battstat_applet_2_LDADD = \
+@@ -242,7 +247,7 @@
+ PROGRAMS = $(libexec_PROGRAMS)
+
+ am_battstat_applet_2_OBJECTS = properties.$(OBJEXT) \
+- battstat_applet.$(OBJEXT) acpi-linux.$(OBJEXT)
++ battstat_applet.$(OBJEXT) acpi-freebsd.$(OBJEXT) acpi-linux.$(OBJEXT)
+ battstat_applet_2_OBJECTS = $(am_battstat_applet_2_OBJECTS)
+ @HAVE_LIBAPM_FALSE@@NEED_LIBAPM_TRUE@battstat_applet_2_DEPENDENCIES = \
+ @HAVE_LIBAPM_FALSE@@NEED_LIBAPM_TRUE@ apmlib/libapm.a
+@@ -259,6 +264,7 @@
+ depcomp = $(SHELL) $(top_srcdir)/depcomp
+ am__depfiles_maybe = depfiles
+ @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/acpi-linux.Po \
++@AMDEP_TRUE@ ./$(DEPDIR)/acpi-freebsd.Po \
+ @AMDEP_TRUE@ ./$(DEPDIR)/battstat_applet.Po \
+ @AMDEP_TRUE@ ./$(DEPDIR)/properties.Po
+ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+@@ -330,6 +336,7 @@
+ -rm -f *.tab.c
+
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acpi-linux.Po@am__quote@
++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acpi-freebsd.Po@am__quote@
+ @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.
++ * Copyright (C) 2000 by Jörgen Pehrson <jp@spektr.eu.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.
++ *
++ $Id: patch-battstat-acpi,v 1.1 2004-09-28 06:53:12 marcus Exp $
++ */
++
++/*
++ * ACPI battery functions for FreeBSD >= 5.2.
++ * September 2004 by Joe Marcus Clarke <marcus@FreeBSD.org>
++ */
++
++#ifdef HAVE_CONFIG_H
++#include <config.h>
++#endif
++
++#ifdef __FreeBSD__
++
++#include <stdio.h>
++#include <sys/types.h>
++#include <sys/sysctl.h>
++#include <sys/ioctl.h>
++#include <machine/apm_bios.h>
++#include <stdlib.h>
++#include <errno.h>
++#include <unistd.h>
++#include <fcntl.h>
++#include <glib.h>
++
++#include <dev/acpica/acpiio.h>
++#include <contrib/dev/acpica/acpi.h>
++
++#include "acpi-freebsd.h"
++
++static gboolean
++update_ac_info(struct acpi_info * acpiinfo)
++{
++ int acline;
++ size_t len = sizeof(acline);
++
++ acpiinfo->ac_online = FALSE;
++
++ if (sysctlbyname(ACPI_ACLINE, &acline, &len, NULL, 0) == -1) {
++ return FALSE;
++ }
++
++ acpiinfo->ac_online = acline ? TRUE : FALSE;
++
++ return TRUE;
++}
++
++static gboolean
++update_battery_info(struct acpi_info * acpiinfo)
++{
++ union acpi_battery_ioctl_arg battio;
++ int i;
++
++ for(i = BATT_MIN; i < BATT_MAX; i++) {
++ battio.unit = i;
++ if (ioctl(acpiinfo->acpifd, ACPIIO_CMBAT_GET_BIF, &battio) == -1) {
++ continue;
++ }
++
++ acpiinfo->max_capacity += battio.bif.lfcap;
++ acpiinfo->low_capacity += battio.bif.wcap;
++ acpiinfo->critical_capacity += battio.bif.lcap;
++ }
++
++ return TRUE;
++}
++
++gboolean
++acpi_freebsd_init(struct acpi_info * acpiinfo)
++{
++ int acpi_fd;
++
++ g_assert(acpiinfo);
++
++ acpi_fd = open(ACPIDEV, O_RDONLY);
++ if (acpi_fd >= 0) {
++ acpiinfo->acpifd = acpi_fd;
++ }
++ else {
++ acpiinfo->acpifd = -1;
++ return FALSE;
++ }
++
++ update_battery_info(acpiinfo);
++ update_ac_info(acpiinfo);
++
++ return TRUE;
++}
++
++void
++acpi_freebsd_cleanup(struct acpi_info * acpiinfo)
++{
++ g_assert(acpiinfo);
++
++ if (acpiinfo->acpifd >= 0) {
++ close(acpiinfo->acpifd);
++ acpiinfo->acpifd = -1;
++ }
++}
++
++/* XXX This is a hack since user-land applications can't get ACPI events yet.
++ * Devd provides this (or supposedly provides this), but you need to be
++ * root to access devd.
++ */
++gboolean
++acpi_process_event(struct acpi_info * acpiinfo)
++{
++ g_assert(acpiinfo);
++
++ update_ac_info(acpiinfo);
++ update_battery_info(acpiinfo);
++
++ return TRUE;
++}
++
++gboolean
++acpi_freebsd_read(struct apm_info *apminfo, struct acpi_info * acpiinfo)
++{
++ int time;
++ int life;
++ int acline;
++ int state;
++ size_t len;
++ int rate;
++ int remain;
++ union acpi_battery_ioctl_arg battio;
++ gboolean charging;
++ int i;
++
++ g_assert(acpiinfo);
++
++ charging = FALSE;
++
++ for(i = BATT_MIN; i < BATT_MAX; i++) {
++ battio.unit = i;
++ if (ioctl(acpiinfo->acpifd, ACPIIO_CMBAT_GET_BST, &battio) == -1) {
++ continue;
++ }
++
++ remain += battio.bst.cap;
++ rate += battio.bst.rate;
++ }
++
++ len = sizeof(time);
++ if (sysctlbyname(ACPI_TIME, &time, &len, NULL, 0) == -1) {
++ return FALSE;
++ }
++
++ len = sizeof(life);
++ if (sysctlbyname(ACPI_LIFE, &life, &len, NULL, 0) == -1) {
++ return FALSE;
++ }
++
++ len = sizeof(state);
++ if (sysctlbyname(ACPI_STATE, &state, &len, NULL, 0) == -1) {
++ return FALSE;
++ }
++
++ apminfo->ai_acline = acpiinfo->ac_online ? 1 : 0;
++ if (state & ACPI_BATT_STAT_CHARGING) {
++ apminfo->ai_batt_stat = 3;
++ charging = TRUE;
++ }
++ else if (state & ACPI_BATT_STAT_CRITICAL) {
++ apminfo->ai_batt_stat = 2;
++ }
++ else {
++ apminfo->ai_batt_stat = remain < acpiinfo->low_capacity ? 1 : remain < acpiinfo->critical_capacity ? 2 : 0;
++ }
++ apminfo->ai_batt_life = life;
++ if (!charging) {
++ apminfo->ai_batt_time = time * 60;
++ }
++ else if (charging && rate > 0) {
++ 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);
++ }
++
++ 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
+