[Pkg-wmaker-commits] [wmbattery] 10/241: * Added support for using files other than /proc/apm, via a -f switch. (See bug #69585)
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:18 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 e86ab502c27c7db55ff2ee8e4502289350300034
Author: joey <joey at a4a2c43b-8ac3-0310-8836-e0e880c912e2>
Date: Mon Aug 21 18:54:07 2000 +0000
* Added support for using files other than /proc/apm, via a -f switch.
(See bug #69585)
---
debian/changelog | 7 +++++
wmbattery.1x | 5 +++-
wmbattery.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 87 insertions(+), 13 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index c84b1cd..79061a8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+wmbattery (1.13) unstable; urgency=low
+
+ * Added support for using files other than /proc/apm, via a -f switch.
+ (See bug #69585)
+
+ -- Joey Hess <joeyh at debian.org> Mon, 21 Aug 2000 11:52:21 -0700
+
wmbattery (1.12) unstable; urgency=low
* Use /usr/share/icons/wmbattery, not /usr/X11R6/share. Sheesh.
diff --git a/wmbattery.1x b/wmbattery.1x
index 3a6ccdf..7a01c47 100644
--- a/wmbattery.1x
+++ b/wmbattery.1x
@@ -3,7 +3,7 @@
WMBATTERY \- Dockable APM/Battery Monitor
.SH SYNOPSIS
.B wmbattery
-[-h] [-d display]
+[-h] [-d display] [-f apmfile]
.SH DESCRIPTION
.PP
.B wmbattery
@@ -56,6 +56,9 @@ Use the designated X display.
.TP
.B \-g +x+y
Specify geometry to start up at. This specifies position, not size.
+.B \-f [apmfile]
+Use the specified file instead of /proc/apm (and /dev/apm on BSD systems).
+Useful on Apple Macintosh powerbooks which use the pmud for apm handling.
.SH AUTHOR
Joey Hess <joey at kitenet.net>, based on wmapm by
Chris D. Faulhaber <jedgar at speck.ml.org>
diff --git a/wmbattery.c b/wmbattery.c
index 50ad4b7..e6df035 100644
--- a/wmbattery.c
+++ b/wmbattery.c
@@ -4,8 +4,16 @@
#include <string.h>
#include <X11/xpm.h>
#include <X11/extensions/shape.h>
-#include <getopt.h>
#include <stdarg.h>
+
+#ifdef __FreeBSD__
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <machine/apm_bios.h>
+#else
+#include <getopt.h>
+#endif
+
#include "wmbattery.h"
#include "mask.xbm"
@@ -15,6 +23,15 @@ int screen;
XpmIcon icon;
Display *display;
GC NormalGC;
+int pos[2] = {0, 0};
+
+#ifdef __FreeBSD__
+#define APM_STATUS_FILE "/dev/apm"
+#else
+#define APM_STATUS_FILE "/proc/apm"
+#endif
+
+char *apm_status_file = APM_STATUS_FILE;
void error(const char *fmt, ...) {
va_list arglist;
@@ -28,12 +45,38 @@ void error(const char *fmt, ...) {
exit(1);
}
+#ifdef __FreeBSD__
+
+int apm_read(apm_info *i) {
+ int fd;
+ struct apm_info info;
+
+ if ((fd = open(apm_status_file, O_RDONLY)) == -1) {
+ return 0;
+ }
+ if (ioctl(fd, APMIO_GETINFO, &info) == -1) {
+ return 0;
+ }
+ close(fd);
+
+ 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;
+
+ return 1;
+}
+
+#else /* Linux */
+
int apm_read(apm_info *i) {
FILE *str;
char units[10];
char buffer[100];
- if (!(str = fopen("/proc/apm", "r")))
+ if (!(str = fopen(apm_status_file, "r")))
return 0;
fgets(buffer, sizeof(buffer) - 1, str);
buffer[sizeof(buffer) - 1] = '\0';
@@ -108,10 +151,12 @@ int apm_read(apm_info *i) {
return 1;
}
+#endif /* linux */
+
int apm_exists() {
apm_info i;
- if (access("/proc/apm", R_OK))
+ if (access(apm_status_file, R_OK))
return 0;
return apm_read(&i);
}
@@ -137,19 +182,38 @@ void load_images() {
char *parse_commandline(int argc, char *argv[]) {
int c=0;
char *ret=NULL;
+ char *s;
extern char *optarg;
while (c != -1) {
- c=getopt(argc, argv, "hd:");
+ c=getopt(argc, argv, "hd:g:f:");
switch (c) {
case 'h':
printf("\nUsage: wmbattery [options]\n");
printf("\t-d <display>\tselects target display\n");
- printf("\t-h\t\tdisplay this help\n\n");
+ printf("\t-h\t\tdisplay this help\n");
+ printf("\t-g +x+y\t\tposition of the window\n");
+ printf("\t-f file\t\tapm status file to use instead of " APM_STATUS_FILE "\n\n");
exit(0);
break;
case 'd':
- ret=optarg;
+ ret=strdup(optarg);
+ break;
+ case 'g':
+ s = strtok(optarg, "+");
+ if (s) {
+ pos[0]=atoi(s);
+ if ((s = strtok(NULL, "+")) != NULL) {
+ pos[1]=atoi(s);
+ }
+ else {
+ pos[0]=0;
+ }
+ }
+ break;
+ case 'f':
+ apm_status_file = strdup(optarg);
+ break;
}
}
@@ -184,6 +248,8 @@ void make_window(char *display_name, int argc, char *argv[]) {
sizehints.width = 64;
sizehints.height = 64;
+ sizehints.x = pos[0];
+ sizehints.y = pos[1];
back_pix = WhitePixel(display, screen);
fore_pix = BlackPixel(display, screen);
win = XCreateSimpleWindow(display, root, sizehints.x, sizehints.y,
@@ -284,7 +350,7 @@ int main(int argc, char *argv[]) {
make_window(parse_commandline(argc, argv), argc ,argv);
/* Check for APM support */
- if (! apm_exists)
+ if (! apm_exists())
error("No APM support in kernel.");
load_images();
@@ -319,13 +385,11 @@ int main(int argc, char *argv[]) {
}
/* Show if the battery is charging. */
- switch (cur_info.battery_status) {
- case 3:
+ if (cur_info.battery_flags & 8) {
draw_image(CHARGING);
- break;
- default: /* Not charging */
+ }
+ else {
draw_image(NOCHARGING);
- break;
}
/*
--
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