$NetBSD: patch-ad,v 1.4 2002/09/18 10:40:13 tron Exp $

--- wmnet.c.orig	Fri May  5 03:01:14 2000
+++ wmnet.c	Mon Jul  8 16:52:30 2002
@@ -55,9 +55,13 @@
 #include<X11/Xlib.h>
 #include<X11/Xutil.h>
 #include<X11/Xatom.h>
-#if defined (__FreeBSD__) || defined (__OpenBSD__)
+#if defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) || defined(__DragonFly__)
 # include<sys/socket.h>
 # include"getopt.h"
+#elif defined (sun)
+# include<sys/socket.h>
+# include<sys/sockio.h>
+# include "getopt.h"
 #else
 # include<getopt.h>
 #endif
@@ -97,17 +101,19 @@
 	int c;
 	XColor thecolor;
 	struct sigaction signal_action;
-	char *txcolorString = NULL, *rxcolorString = NULL, *labelfgcolorString = NULL, *labelbgcolorString = NULL;
+	char *txcolorString = NULL, *rxcolorString = NULL, *labelfgcolorString = NULL, *labelbgcolorString = NULL, *bgcolorString = NULL;
 	char *parser = NULL;
 #ifdef linux
-	const struct option long_options[19] = {
+	const struct option long_options[21] = {
 #else
-	const struct option long_options[17] = {
+	const struct option long_options[19] = {
 #endif
 		{"device", required_argument, NULL, 'W'},
 		{"label", required_argument, NULL, 'L'},
 		{"labelfg", required_argument, NULL, 'F'},
 		{"labelbg", required_argument, NULL, 'B'},
+		{"bg", required_argument, NULL, 'b'},
+		{"no3d", no_argument, NULL, 'N'},
 		{"logscale", no_argument, NULL, 'l'},
 		{"help", no_argument, NULL, 'h'},
 		{"execute", required_argument, NULL, 'e'}, 
@@ -131,9 +137,9 @@
 
 	/* Get options */
 #ifdef linux
-	while((c = getopt_long(argc, argv, "W:F:B:L:vp:u:wnle:R:T:r:t:D:d:x:h", long_options, NULL)) != EOF) {
+	while((c = getopt_long(argc, argv, "W:F:B:b:L:vp:u:wnNle:R:T:r:t:D:d:x:h", long_options, NULL)) != EOF) {
 #else
-	while((c = getopt_long(argc, argv, "W:F:B:L:vp:u:wnle:r:t:D:d:x:h", long_options, NULL)) != EOF) {
+	while((c = getopt_long(argc, argv, "W:F:B:b:L:vp:u:wnNle:r:t:D:d:x:h", long_options, NULL)) != EOF) {
 #endif
 		switch(c) {
 			case 'v':
@@ -176,6 +182,15 @@
 					exit(23);
 				}
 				break;
+			case 'b':
+				if (bgcolorString == NULL) {
+					bgcolorString = (char *)alloca(strlen(optarg)+1);
+					strncpy(bgcolorString, optarg, strlen(optarg)+1);
+				} else {
+					fprintf(stderr, "wmnet: duplicate --bg\n");
+					exit(23);
+				}
+				break;
 			case 'F':
 				if (labelfgcolorString == NULL) {
 					labelfgcolorString = (char *)alloca(strlen(optarg)+1);
@@ -228,6 +243,9 @@
 			case 'n':
 				specified_state = NormalState;
 				break;
+			case 'N':
+				no3d = True;
+				break;
 			case 'u':
 				{
 					int fds;
@@ -283,6 +301,7 @@
                                        "  -L, --label=LABEL        display LABEL on bottom of window\n"
                                        "  -F, --labelfg=COLOR      foreground color for the label\n"
                                        "  -B, --labelbg=COLOR      background color for the label\n"
+                                       "  -b, --bg=COLOR           background color\n"
                                        "  -e, --execute=COMMAND    run COMMAND on click\n"
 #ifdef linux
 				       "  -T, --txrule=RULE        accounting rule number (ipfwadm) or\n"
@@ -320,6 +339,7 @@
 	if (rxcolorString == NULL) rxcolorString = "red";
 	if (labelfgcolorString == NULL) labelfgcolorString = "white";
 	if (labelbgcolorString == NULL) labelbgcolorString = "black";
+	if (bgcolorString == NULL) bgcolorString = "black";
 
 	/* Change dir to /, security precaution, and common courtesy */
 	if (chdir("/") == -1) {
@@ -384,6 +404,14 @@
 		XAllocColor(dpy, DefaultColormap(dpy, screen), &thecolor);
 		labelbg_pixel = thecolor.pixel;
 	}
+	if(bgcolorString) {
+		if(!XParseColor(dpy, DefaultColormap(dpy, screen), bgcolorString, &thecolor)) {
+			fprintf(stderr, "wmnet: what the heck is %s for a color?\n", bgcolorString);
+			exit(25);
+		}
+		XAllocColor(dpy, DefaultColormap(dpy, screen), &thecolor);
+		bg_pixel = thecolor.pixel;
+	}
 
 	/* usleep() in between polls to /proc/net/ip_acct */
 	if (delayTime <= 0) delayTime = 25000;
@@ -442,7 +470,7 @@
 	}
 	gcv.graphics_exposures = False;
 	gcv.foreground = tx_pixel[HIGH_INTENSITY]; 
-	gcv.background = darkgrey_pixel;
+	gcv.background = bg_pixel /* HF: darkgrey_pixel */;
 	gcv.font = XLoadFont(dpy, "5x8");
 	graphics_context = XCreateGC(dpy, root_window, (GCFont|GCGraphicsExposures|GCForeground|GCBackground), &gcv);
 	black_pixel = BlackPixel(dpy, screen);
@@ -494,12 +522,12 @@
 /* Handles Expose events, repaints the window */
 void redraw(XExposeEvent *ee) {
         static XRectangle cliprect = { 4, 51, 56, 9 };
-	XSetForeground(dpy, graphics_context, darkgrey_pixel);
+	XSetForeground(dpy, graphics_context, bg_pixel /* HF: darkgrey_pixel*/);
 /*	if (wmaker_present == False) XFillRectangle(dpy, *visible_window, graphics_context, 0, 0, 64, 64); */
 	XFillRectangle(dpy, *visible_window, graphics_context, GRAPHBOX_X, GRAPHBOX_Y, GRAPHBOX_WIDTH, GRAPHBOX_HEIGHT); 
 
 
-	XSetForeground(dpy, graphics_context, black_pixel);
+	XSetForeground(dpy, graphics_context, bg_pixel);
 	XFillRectangle(dpy, *visible_window, graphics_context, TOPBOX_X, TOPBOX_Y, TOPBOX_WIDTH, TOPBOX_HEIGHT);
 	XDrawLine(dpy, *visible_window, graphics_context, GRAPHBOX_X_LEFT, GRAPHBOX_Y_TOP, GRAPHBOX_X_LEFT, GRAPHBOX_Y_BOTTOM);
 	XDrawPoint(dpy, *visible_window, graphics_context, GRAPHBOX_X_RIGHT, GRAPHBOX_Y_TOP);
@@ -513,15 +541,19 @@
 	}
 
 
+	if (! no3d) {
 	XSetForeground(dpy, graphics_context, white_pixel);
 	XDrawLine(dpy, *visible_window, graphics_context, GRAPHBOX_X_RIGHT, GRAPHBOX_Y_BOTTOM, GRAPHBOX_X_RIGHT, (GRAPHBOX_Y_TOP + 1)); 
 	XDrawLine(dpy, *visible_window, graphics_context, GRAPHBOX_X_LEFT, GRAPHBOX_Y_BOTTOM, GRAPHBOX_X_RIGHT, GRAPHBOX_Y_BOTTOM);
+	}
 
 
+	if (! no3d) { /* OK, this is cheating, but I don't want to add yet another switch; I have NFC what these arrows are for - HF */
 	XSetForeground(dpy, graphics_context, grey_pixel);
-	XSetBackground(dpy, graphics_context, black_pixel);
+		XSetBackground(dpy, graphics_context, bg_pixel);
 	XCopyPlane(dpy, arrow, *visible_window, graphics_context, 7, 0, 7, 9, 53, 5, 1);
 	XCopyPlane(dpy, arrow, *visible_window, graphics_context, 0, 0, 7, 9, 46, 5, 1);
+	}
 }
 	
 	
@@ -572,7 +604,7 @@
 		if (blank < (GRAPH_WIDTH + 1) ) {
 			XCopyArea(dpy, *visible_window, *visible_window, graphics_context, GRAPH_X + 1,
 			   GRAPH_Y, GRAPH_WIDTH - 1, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y);
-			XSetForeground(dpy, graphics_context, darkgrey_pixel);
+			XSetForeground(dpy, graphics_context, bg_pixel /* HF: darkgrey_pixel*/ );
 			XDrawLine(dpy, *visible_window, graphics_context, GRAPH_X_RIGHT, y, GRAPH_X_RIGHT, yy);
 			if (( (yy == GRAPH_Y_UPPER && diffbytes_out > 0 && rate_rx > rate_tx) || (rate_rx >= rate_tx && yy != GRAPH_Y_UPPER)) ) {
 				drawColoredLine(GRAPH_Y_UPPER, yy, tx_pixel);				
@@ -593,7 +625,7 @@
 	if (!stat_gather()) {  /* Anything change? */
 		current_rx = rx;
 		current_tx = tx;
-		XSetBackground(dpy, graphics_context, black_pixel);
+		XSetBackground(dpy, graphics_context, bg_pixel);
 		if(current_tx == True) {
 			XSetForeground(dpy, graphics_context, tx_pixel[HIGH_INTENSITY]);
 			XCopyPlane(dpy, arrow, *visible_window, graphics_context, 7, 0, 7, 9, 53, 5, 1);
@@ -646,7 +678,7 @@
 
 
 	if (!clear) {
-		XSetForeground(dpy, graphics_context, black_pixel);
+		XSetForeground(dpy, graphics_context, bg_pixel);
 		XFillRectangle(dpy, *visible_window, graphics_context, 4, 5, 37, 9);
 	}
 	if (rate < .1) {
@@ -732,6 +732,7 @@
 			case ButtonPress:
 				if(event.xbutton.button == Button1 && click_command != NULL) {
 					if (fork() == 0) {
+						setgid(getgid());
 						execl("/bin/sh", "sh", "-c", click_command, NULL);
 						perror("wmnet: execl()");
 						exit(15);
