[Pkg-wmaker-commits] [wmbattery] 62/241: releasing version 2.20

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:32 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 0fc8aed2857e87ac530566806dc8e4258481e075
Author: joey <joey at a4a2c43b-8ac3-0310-8836-e0e880c912e2>
Date:   Thu Nov 25 02:38:02 2004 +0000

    releasing version 2.20
---
 debian/changelog |  10 +++
 wmbattery.1x     |  12 ++--
 wmbattery.c      | 214 ++++++++++++++++++++++++++++++++++++-------------------
 3 files changed, 157 insertions(+), 79 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index fb4a10e..b1c62df 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+wmbattery (2.20) unstable; urgency=low
+
+  * Patch from Kris Verbeeck to add a -a option to play an au file
+    on low battery.
+  * Document it in the man page.
+  * Unicode dash fixes on man page.
+  * Some indentation fixes.
+
+ -- Joey Hess <joeyh at debian.org>  Wed, 24 Nov 2004 16:20:39 -0500
+
 wmbattery (2.19) unstable; urgency=low
 
   * Use the proper new-style acpi string when looking for ac adaptor status.
diff --git a/wmbattery.1x b/wmbattery.1x
index 6089009..3d89404 100644
--- a/wmbattery.1x
+++ b/wmbattery.1x
@@ -15,8 +15,8 @@ can get battery information using APM, ACPI, or the SPIC controller in some
 Sony laptops. You need to build your kernel with support for at least one
 of these for the program to work.
 .B wmbattery
-is dockable using WindowMaker and AfterStep window-managers; under
-other window-managers
+is dockable using WindowMaker and AfterStep window managers; under
+other window managers
 .B wmbattery
 appears as a nicely-sized 64x64 application.
 .PP
@@ -82,13 +82,13 @@ one battery. The default is to display the first battery found.
 .B \-l percent
 Set the percentaqge at which the battery is considered to be running low. By
 default, this percentage is determined by APM or ACPI, and you shouldn't
-need to set it. If you set this, you should probably also set the -c
+need to set it. If you set this, you should probably also set the \-c
 switch.
 .TP
 .B \-c percent
 Set the percentage at which the battery is considered to be critically low.
 By default, this percentage is determined by APM or ACPI, and you shouldn't
-need to set it. If you set this, you should probably also set the -l
+need to set it. If you set this, you should probably also set the \-l
 switch.
 .TP
 .B \-e
@@ -96,5 +96,9 @@ wmbattery contains code for estimating the time remaining before discharge,
 and until full charge,and this code is used if no other source of this
 informaton is available. This switch makes wmbattery use its time 
 estimation code even if some other estimate is available.
+.TP
+.B \-a file.au
+Play the specified au file (by sending it to /dev/audio) when the battery
+is low.
 .SH AUTHOR
 Joey Hess <joey at kitenet.net>
diff --git a/wmbattery.c b/wmbattery.c
index fa4370b..e5c696d 100644
--- a/wmbattery.c
+++ b/wmbattery.c
@@ -9,6 +9,9 @@
 #include <signal.h>
 #include <time.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
@@ -27,6 +30,10 @@ Display *display;
 GC NormalGC;
 int pos[2] = {0, 0};
 
+char *crit_audio_fn = NULL;
+char *crit_audio;
+int crit_audio_size;
+
 int battnum = 1;
 int use_sonypi = 0;
 int use_acpi = 0;
@@ -37,15 +44,15 @@ signed int low_pct = -1;
 signed int critical_pct = -1;
 
 void error(const char *fmt, ...) {
-  	va_list arglist;
+	va_list arglist;
   
 	va_start(arglist, fmt);
 	fprintf(stderr, "Error: ");
 	vfprintf(stderr, fmt, arglist);
 	fprintf(stderr, "\n");
 	va_end(arglist);
-  
-  	exit(1);
+
+	exit(1);
 }
 
 int apm_change(apm_info *cur) {
@@ -160,6 +167,31 @@ void load_images() {
     }
 }
 
+void load_audio() {
+	int fd;
+	struct stat s;
+
+	crit_audio = NULL;
+	if (crit_audio_fn == NULL) {
+		return;
+	}
+	fd = open(crit_audio_fn, 0);
+	if (fd == -1) {
+		error("unable to open audio file");
+	}
+	if (fstat(fd, &s) == 0) {
+		crit_audio_size = s.st_size;
+		crit_audio = malloc(crit_audio_size);
+		/* XXX: make this more robust? (loop?) */
+		if (read(fd, crit_audio, crit_audio_size) != crit_audio_size) {
+			free(crit_audio);
+			crit_audio = NULL;
+			error("unable to read audio file");
+		}
+	}
+	close(fd);
+}
+
 /* Returns the display to run on (or NULL for default). */
 char *parse_commandline(int argc, char *argv[]) {
 	int c=0;
@@ -168,7 +200,7 @@ char *parse_commandline(int argc, char *argv[]) {
 	extern char *optarg;
 	
   	while (c != -1) {
-  		c=getopt(argc, argv, "hd:g:f:b:w:c:l:e");
+  		c=getopt(argc, argv, "hd:g:f:b:w:c:l:ea:");
 		switch (c) {
 		  case 'h':
 			printf("Usage: wmbattery [options]\n");
@@ -180,23 +212,24 @@ char *parse_commandline(int argc, char *argv[]) {
 			printf("\t-l percent\tlow percentage\n");
 			printf("\t-c percent\tcritical percentage\n");
 			printf("\t-e\t\tuse own time estimates\n");
+			printf("\t-a file\t\twhen critical send file to /dv/audio\n");
                		exit(0);
 		 	break;
 		  case 'd':
 		  	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 '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 'b':
 			battnum = atoi(optarg);
 			break;
@@ -211,108 +244,112 @@ char *parse_commandline(int argc, char *argv[]) {
 			break;
 		  case 'r':
 			always_estimate_remaining = 1;
-      		}
-    	}
-  
-  	return ret;
+			break;
+		  case 'a':
+			crit_audio_fn = strdup(optarg);
+			break;
+		}
+	}
+
+	return ret;
 }
 
 /* Sets up the window and icon and all the nasty X stuff. */
 void make_window(char *display_name, int argc, char *argv[]) {
 	XClassHint classhint;
 	char *wname = argv[0];
-  	XTextProperty name;
-  	XGCValues gcv;
-  	int dummy=0, borderwidth = 1;
+	XTextProperty name;
+	XGCValues gcv;
+	int dummy=0, borderwidth = 1;
 	XSizeHints sizehints;
-  	XWMHints wmhints;
+	XWMHints wmhints;
 	Pixel back_pix, fore_pix;
 	Pixmap pixmask;
 
-  	if (!(display = XOpenDisplay(display_name)))
-    		error("can't open display %s",XDisplayName(display_name));
+	if (!(display = XOpenDisplay(display_name)))
+		error("can't open display %s",XDisplayName(display_name));
 
 	screen=DefaultScreen(display);
-  	root=RootWindow(display, screen);
+	root=RootWindow(display, screen);
 
-  	/* Create window. */
-  	sizehints.flags = USSize | USPosition;
-  	sizehints.x = 0;
-  	sizehints.y = 0;
-  	XWMGeometry(display, screen, "", NULL, borderwidth,
+	/* Create window. */
+	sizehints.flags = USSize | USPosition;
+	sizehints.x = 0;
+	sizehints.y = 0;
+	XWMGeometry(display, screen, "", NULL, borderwidth,
 		    &sizehints, &sizehints.x, &sizehints.y,
 		    &sizehints.width, &sizehints.height, &dummy);
 
 	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,
+	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,
 				  sizehints.width, sizehints.height,
 				  borderwidth, fore_pix, back_pix);
-  	iconwin = XCreateSimpleWindow(display, win, sizehints.x,
+	iconwin = XCreateSimpleWindow(display, win, sizehints.x,
 				      sizehints.y, sizehints.width,
 				      sizehints.height, borderwidth,
 				      fore_pix, back_pix);
 
-  	/* Activate hints */
-       	XSetWMNormalHints(display, win, &sizehints);
-        classhint.res_name = wname;
-   	classhint.res_class = wname;
-       	XSetClassHint(display, win, &classhint);
+	/* Activate hints */
+	XSetWMNormalHints(display, win, &sizehints);
+	classhint.res_name = wname;
+	classhint.res_class = wname;
+	XSetClassHint(display, win, &classhint);
   
-  	if (! XStringListToTextProperty(&wname, 1, &name))
-	  	error("Can't allocate window name.");
-  	
-  	XSetWMName(display, win, &name);
+	if (! XStringListToTextProperty(&wname, 1, &name))
+		error("Can't allocate window name.");
+
+	XSetWMName(display, win, &name);
   
-  	/* Create GC for drawing */
-  	gcv.foreground = fore_pix;
-  	gcv.background = back_pix;
-  	gcv.graphics_exposures = 0;
-  	NormalGC = XCreateGC(display, root, 
+	/* Create GC for drawing */
+	gcv.foreground = fore_pix;
+	gcv.background = back_pix;
+	gcv.graphics_exposures = 0;
+	NormalGC = XCreateGC(display, root, 
 			     GCForeground | GCBackground | GCGraphicsExposures,
 			     &gcv);
 
-  	pixmask = XCreateBitmapFromData(display, win, mask_bits,
+	pixmask = XCreateBitmapFromData(display, win, mask_bits,
 					mask_width,mask_height);
-  	XShapeCombineMask(display, win, ShapeBounding, 0, 0,
+	XShapeCombineMask(display, win, ShapeBounding, 0, 0,
 			  pixmask, ShapeSet);
-  	XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0,
+	XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0,
 			  pixmask, ShapeSet);
 	
-  	wmhints.initial_state = WithdrawnState;
-  	wmhints.icon_window = iconwin;
-  	wmhints.icon_x = sizehints.x;
-  	wmhints.icon_y = sizehints.y;
-  	wmhints.window_group = win;
-  	wmhints.flags = StateHint | IconWindowHint | 
+	wmhints.initial_state = WithdrawnState;
+	wmhints.icon_window = iconwin;
+	wmhints.icon_x = sizehints.x;
+	wmhints.icon_y = sizehints.y;
+	wmhints.window_group = win;
+	wmhints.flags = StateHint | IconWindowHint | 
     			IconPositionHint | WindowGroupHint;
   
-  	XSetWMHints(display, win, &wmhints);
-  	XSetCommand(display, win, argv, argc);
+	XSetWMHints(display, win, &wmhints);
+	XSetCommand(display, win, argv, argc);
 
 	XSelectInput(display, iconwin, ExposureMask);
 	XSelectInput(display, win, ExposureMask);
 
- 	XMapWindow(display, win);
+	XMapWindow(display, win);
 }
 
 void flush_expose(Window w) {
-  	XEvent dummy;
+	XEvent dummy;
   
-  	while (XCheckTypedWindowEvent(display, w, Expose, &dummy));
+	while (XCheckTypedWindowEvent(display, w, Expose, &dummy));
 }
 
 void redraw_window() {
-  	XCopyArea(display, images[FACE], iconwin, NormalGC, 0, 0,
+	XCopyArea(display, images[FACE], iconwin, NormalGC, 0, 0,
 		  image_info[FACE].width, image_info[FACE].height, 0,0);
-  	flush_expose(iconwin);
-  	XCopyArea(display, images[FACE], win, NormalGC, 0, 0, 
+	flush_expose(iconwin);
+	XCopyArea(display, images[FACE], win, NormalGC, 0, 0, 
 		  image_info[FACE].width, image_info[FACE].height, 0,0);
-  	flush_expose(win);
+	flush_expose(win);
 }
 
 /*
@@ -320,9 +357,9 @@ void redraw_window() {
  * located anywhere.
  */
 void copy_image(int image, int xoffset, int yoffset,
-		int width, int height, int x, int y) {
+                int width, int height, int x, int y) {
 	XCopyArea(display, images[image], images[FACE], NormalGC,
-		  xoffset, yoffset, width, height, x, y);
+	          xoffset, yoffset, width, height, x, y);
 }
 
 /*
@@ -448,9 +485,26 @@ void recalc_window(apm_info cur_info) {
 	redraw_window();
 }
 
+void snd_crit() {
+	int audio, n;
+
+	if (crit_audio) {
+		audio = open("/dev/audio", O_WRONLY);
+		if (audio >= 0) {
+			n = write(audio, crit_audio, crit_audio_size);
+			if (n != crit_audio_size) {
+				fprintf(stderr, "write failed (%d/%d bytes)\n", n, crit_audio_size);
+			}
+			close(audio);
+		}
+	}
+}
+
 void alarmhandler(int sig) {
 	apm_info cur_info;
-	
+	int old_status;
+
+	old_status = cur_info.battery_status;
 	if (use_acpi) {
 		if (acpi_read(battnum, &cur_info) != 0)
 			error("Cannot read ACPI information.");
@@ -486,6 +540,14 @@ void alarmhandler(int sig) {
 	if (!apm_change(&cur_info) || cur_info.battery_status == BATTERY_STATUS_CRITICAL)
 		recalc_window(cur_info);
 
+	if ((old_status == BATTERY_STATUS_HIGH) &&
+	    (cur_info.battery_status == BATTERY_STATUS_LOW)) {
+		snd_crit();
+	}
+	else if (cur_info.battery_status == BATTERY_STATUS_CRITICAL) {
+		snd_crit();
+	}
+
 	alarm(delay);
 }
 
@@ -518,11 +580,13 @@ int main(int argc, char *argv[]) {
 			delay = 1;
 	}
 	else {
+	
 		error("No APM, ACPI, or SPIC support in kernel.");
 	}
 		
 	load_images();
-	
+        load_audio();
+
 	signal(SIGALRM, alarmhandler);
 	alarmhandler(SIGALRM);
 

-- 
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