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.
This commit is contained in:
parent
a750a6b25f
commit
02bce1c90f
|
@ -35,8 +35,6 @@ upower.o: upower.c
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(shell pkg-config --cflags upower-glib) -c upower.c -o upower.o
|
$(CC) $(CPPFLAGS) $(CFLAGS) $(shell pkg-config --cflags upower-glib) -c upower.c -o upower.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LIBS+=-lapm -lXext -lXpm
|
|
||||||
|
|
||||||
wmbattery: $(OBJS)
|
wmbattery: $(OBJS)
|
||||||
$(CC) -o wmbattery $(LDFLAGS) $(OBJS) $(LIBS)
|
$(CC) -o wmbattery $(LDFLAGS) $(OBJS) $(LIBS)
|
||||||
|
|
||||||
|
|
|
@ -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>
|
#include <apm.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Symbolic constants for apm may be in system apm.h, or may not. */
|
/* Symbolic constants for apm may be in system apm.h, or may not. */
|
||||||
#ifndef AC_LINE_STATUS_ON
|
#ifndef AC_LINE_STATUS_ON
|
||||||
|
@ -25,3 +37,20 @@
|
||||||
#define BATTERY_TIME_UNKNOWN (-1)
|
#define BATTERY_TIME_UNKNOWN (-1)
|
||||||
#endif /* AC_LINE_STATUS_ON */
|
#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
|
||||||
|
|
|
@ -4,6 +4,9 @@ AC_CONFIG_HEADER(config.h)
|
||||||
|
|
||||||
AC_CONFIG_AUX_DIR(autoconf)
|
AC_CONFIG_AUX_DIR(autoconf)
|
||||||
|
|
||||||
|
dnl Checks for the apm device other than /proc/apm.
|
||||||
|
AC_CHECK_FILES(/dev/apm)
|
||||||
|
|
||||||
dnl Checks for programs.
|
dnl Checks for programs.
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
|
@ -32,6 +35,10 @@ AC_CHECK_HEADERS(X11/xpm.h)
|
||||||
AC_CHECK_HEADERS(X11/extensions/shape.h)
|
AC_CHECK_HEADERS(X11/extensions/shape.h)
|
||||||
AC_CHECK_HEADERS(getopt.h)
|
AC_CHECK_HEADERS(getopt.h)
|
||||||
AC_CHECK_HEADERS(apm.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.
|
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_C_CONST
|
AC_C_CONST
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "sonypi.h"
|
#include "sonypi.h"
|
||||||
|
|
||||||
|
@ -30,8 +31,8 @@ inline int sonypi_ioctl(int ioctlno, void *param)
|
||||||
* struct. */
|
* struct. */
|
||||||
int sonypi_read(apm_info *info)
|
int sonypi_read(apm_info *info)
|
||||||
{
|
{
|
||||||
__u8 batflags;
|
uint8_t batflags;
|
||||||
__u16 cap, rem;
|
uint16_t cap, rem;
|
||||||
int havebatt = 0;
|
int havebatt = 0;
|
||||||
|
|
||||||
info->using_minutes = info->battery_flags = 0;
|
info->using_minutes = info->battery_flags = 0;
|
||||||
|
|
|
@ -4,16 +4,14 @@ int sonypi_read(apm_info *info);
|
||||||
/* There's no good place to get these constants, so I must define them
|
/* There's no good place to get these constants, so I must define them
|
||||||
* myself. */
|
* myself. */
|
||||||
|
|
||||||
#include <linux/types.h>
|
|
||||||
|
|
||||||
/* get battery full capacity/remaining capacity */
|
/* get battery full capacity/remaining capacity */
|
||||||
#define SONYPI_IOCGBAT1CAP _IOR('v', 2, __u16)
|
#define SONYPI_IOCGBAT1CAP _IOR('v', 2, uint16_t)
|
||||||
#define SONYPI_IOCGBAT1REM _IOR('v', 3, __u16)
|
#define SONYPI_IOCGBAT1REM _IOR('v', 3, uint16_t)
|
||||||
#define SONYPI_IOCGBAT2CAP _IOR('v', 4, __u16)
|
#define SONYPI_IOCGBAT2CAP _IOR('v', 4, uint16_t)
|
||||||
#define SONYPI_IOCGBAT2REM _IOR('v', 5, __u16)
|
#define SONYPI_IOCGBAT2REM _IOR('v', 5, uint16_t)
|
||||||
|
|
||||||
/* get battery flags: battery1/battery2/ac adapter present */
|
/* get battery flags: battery1/battery2/ac adapter present */
|
||||||
#define SONYPI_BFLAGS_B1 0x01
|
#define SONYPI_BFLAGS_B1 0x01
|
||||||
#define SONYPI_BFLAGS_B2 0x02
|
#define SONYPI_BFLAGS_B2 0x02
|
||||||
#define SONYPI_BFLAGS_AC 0x04
|
#define SONYPI_BFLAGS_AC 0x04
|
||||||
#define SONYPI_IOCGBATFLAGS _IOR('v', 7, __u8)
|
#define SONYPI_IOCGBATFLAGS _IOR('v', 7, uint8_t)
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -34,12 +33,12 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include "wmbattery.h"
|
||||||
|
|
||||||
#ifdef HAVE_GETOPT_H
|
#ifdef HAVE_GETOPT_H
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wmbattery.h"
|
|
||||||
#include "mask.xbm"
|
#include "mask.xbm"
|
||||||
#include "sonypi.h"
|
#include "sonypi.h"
|
||||||
#include "acpi.h"
|
#include "acpi.h"
|
||||||
|
@ -58,6 +57,14 @@ Display *display;
|
||||||
GC NormalGC;
|
GC NormalGC;
|
||||||
int pos[2] = {0, 0};
|
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_fn = NULL;
|
||||||
char *crit_audio;
|
char *crit_audio;
|
||||||
int crit_audio_size;
|
int crit_audio_size;
|
||||||
|
@ -93,6 +100,55 @@ void error(const char *fmt, ...)
|
||||||
exit(1);
|
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)
|
int apm_change(apm_info *cur)
|
||||||
{
|
{
|
||||||
static int ac_line_status = 0, battery_status = 0, battery_flags = 0,
|
static int ac_line_status = 0, battery_status = 0, battery_flags = 0,
|
||||||
|
|
Loading…
Reference in a new issue