[Pkg-wmaker-commits] [wmbattery] 189/241: wmbattery: Restore BSD support.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:59 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmbattery.

commit c8b52168040e4186fee13a1ed235932f575412a7
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date:   Sun Oct 5 10:30:05 2014 -0500

    wmbattery: Restore BSD support.
    
    Code that was ripped out of wmbattery for version 1.22, which introduced the
    dependency on libapm but dropped support for the BSDs, has been restored.
---
 Makefile     |  2 --
 apm.h        | 29 +++++++++++++++++++++++++++++
 configure.ac |  7 +++++++
 sonypi.c     |  5 +++--
 sonypi.h     | 12 +++++-------
 wmbattery.c  | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 6 files changed, 102 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index b5262d5..e9fcce8 100644
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,6 @@ upower.o: upower.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) $(shell pkg-config --cflags upower-glib) -c upower.c -o upower.o
 endif
 
-LIBS+=-lapm -lXext -lXpm
-
 wmbattery: $(OBJS)
 	$(CC) -o wmbattery $(LDFLAGS) $(OBJS) $(LIBS)
 
diff --git a/apm.h b/apm.h
index 4fd8671..381b7f7 100644
--- a/apm.h
+++ b/apm.h
@@ -1,4 +1,16 @@
+#include "config.h"
+
+#ifdef HAVE_MACHINE_APM_BIOS_H /* for FreeBSD */
+#include <machine/apm_bios.h>
+#endif
+
+#ifdef HAVE_I386_APMVAR_H /* for NetBSD and OpenBSD */
+#include <i386/apmvar.h>
+#endif
+
+#ifdef HAVE_APM_H
 #include <apm.h>
+#endif
 
 /* Symbolic constants for apm may be in system apm.h, or may not. */
 #ifndef AC_LINE_STATUS_ON
@@ -25,3 +37,20 @@
 #define BATTERY_TIME_UNKNOWN        (-1)
 #endif /* AC_LINE_STATUS_ON */
 
+#if defined (HAVE_MACHINE_APM_BIOS_H) || defined (HAVE_I386_APMVAR_H) /* BSD */
+typedef struct {
+	const char driver_version[10];
+	int apm_version_major;
+	int apm_version_minor;
+	int apm_flags;
+	int ac_line_status;
+	int battery_status;
+	int battery_flags;
+	int battery_percentage;
+	int battery_time;
+	int using_minutes;
+} apm_info;
+
+int apm_read(apm_info *i);
+int apm_exists(void);
+#endif
diff --git a/configure.ac b/configure.ac
index dc15b2c..0688913 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,6 +4,9 @@ AC_CONFIG_HEADER(config.h)
 
 AC_CONFIG_AUX_DIR(autoconf)
 
+dnl Checks for the apm device other than /proc/apm.
+AC_CHECK_FILES(/dev/apm)
+
 dnl Checks for programs.
 AC_PROG_CC
 AC_PROG_INSTALL
@@ -32,6 +35,10 @@ AC_CHECK_HEADERS(X11/xpm.h)
 AC_CHECK_HEADERS(X11/extensions/shape.h)
 AC_CHECK_HEADERS(getopt.h)
 AC_CHECK_HEADERS(apm.h)
+dnl FreeBSD needs apm_bios.h
+AC_CHECK_HEADERS(machine/apm_bios.h)
+dnl NetBSD and OpenBSD need apmvar.h
+AC_CHECK_HEADERS(i386/apmvar.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
diff --git a/sonypi.c b/sonypi.c
index c3190be..92ba106 100644
--- a/sonypi.c
+++ b/sonypi.c
@@ -4,6 +4,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <stdint.h>
 
 #include "sonypi.h"
 
@@ -30,8 +31,8 @@ inline int sonypi_ioctl(int ioctlno, void *param)
  * struct. */
 int sonypi_read(apm_info *info)
 {
-	__u8 batflags;
-	__u16 cap, rem;
+	uint8_t batflags;
+	uint16_t cap, rem;
 	int havebatt = 0;
 
 	info->using_minutes = info->battery_flags = 0;
diff --git a/sonypi.h b/sonypi.h
index 9e132e6..9abd2f4 100644
--- a/sonypi.h
+++ b/sonypi.h
@@ -4,16 +4,14 @@ int sonypi_read(apm_info *info);
 /* There's no good place to get these constants, so I must define them
  * myself. */
 
-#include <linux/types.h>
-
 /* get battery full capacity/remaining capacity */
-#define SONYPI_IOCGBAT1CAP	_IOR('v', 2, __u16)
-#define SONYPI_IOCGBAT1REM	_IOR('v', 3, __u16)
-#define SONYPI_IOCGBAT2CAP	_IOR('v', 4, __u16)
-#define SONYPI_IOCGBAT2REM	_IOR('v', 5, __u16)
+#define SONYPI_IOCGBAT1CAP	_IOR('v', 2, uint16_t)
+#define SONYPI_IOCGBAT1REM	_IOR('v', 3, uint16_t)
+#define SONYPI_IOCGBAT2CAP	_IOR('v', 4, uint16_t)
+#define SONYPI_IOCGBAT2REM	_IOR('v', 5, uint16_t)
 
 /* get battery flags: battery1/battery2/ac adapter present */
 #define SONYPI_BFLAGS_B1	0x01
 #define SONYPI_BFLAGS_B2	0x02
 #define SONYPI_BFLAGS_AC	0x04
-#define SONYPI_IOCGBATFLAGS	_IOR('v', 7, __u8)
+#define SONYPI_IOCGBATFLAGS	_IOR('v', 7, uint8_t)
diff --git a/wmbattery.c b/wmbattery.c
index 26fd283..8f9cbb5 100644
--- a/wmbattery.c
+++ b/wmbattery.c
@@ -20,7 +20,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include "config.h"
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -34,12 +33,12 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include "wmbattery.h"
 
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
 
-#include "wmbattery.h"
 #include "mask.xbm"
 #include "sonypi.h"
 #include "acpi.h"
@@ -58,6 +57,14 @@ Display *display;
 GC NormalGC;
 int pos[2] = {0, 0};
 
+#ifdef HAVE__DEV_APM
+#define APM_STATUS_FILE "/dev/apm"
+#else
+#define APM_STATUS_FILE "/proc/apm"
+#endif
+
+char *apm_status_file = APM_STATUS_FILE;
+
 char *crit_audio_fn = NULL;
 char *crit_audio;
 int crit_audio_size;
@@ -93,6 +100,55 @@ void error(const char *fmt, ...)
 	exit(1);
 }
 
+#if defined (HAVE_MACHINE_APM_BIOS_H) || defined (HAVE_I386_APMVAR_H) /* BSD */
+int apm_read(apm_info *i)
+{
+	int fd;
+#ifdef HAVE_MACHINE_APM_BIOS_H /* FreeBSD */
+	unsigned long request = APMIO_GETINFO;
+	struct apm_info info;
+#else /* NetBSD or OpenBSD */
+	unsigned long request= APM_IOC_GETPOWER;
+	struct apm_power_info info;
+#endif
+
+	if ((fd = open(apm_status_file, O_RDONLY)) == -1) {
+		return 0;
+	}
+	if (ioctl(fd, request, &info) == -1) {
+		return 0;
+	}
+	close(fd);
+
+#ifdef HAVE_MACHINE_APM_BIOS_H /* FreeBSD */
+	i->ac_line_status = info.ai_acline;
+	i->battery_status = info.ai_batt_stat;
+	i->battery_flags = (info.ai_batt_stat == 3) ? 8: 0;
+	i->battery_percentage = info.ai_batt_life;
+	i->battery_time = info.ai_batt_time;
+	i->using_minutes = 0;
+#else /* NetBSD or OpenBSD */
+	i->ac_line_status = info.ac_state;
+	i->battery_status = info.battery_state;
+	i->battery_flags = (info.battery_state == 3) ? 8: 0;
+	i->battery_percentage = info.battery_life;
+	i->battery_time = info.minutes_left;
+	i->using_minutes = 1;
+#endif
+
+	return 1;
+}
+
+int apm_exists(void)
+{
+	apm_info i;
+
+	if (access(apm_status_file, R_OK))
+		return 0;
+	return apm_read(&i);
+}
+#endif
+
 int apm_change(apm_info *cur)
 {
 	static int ac_line_status = 0, battery_status = 0, battery_flags = 0,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbattery.git



More information about the Pkg-wmaker-commits mailing list