summaryrefslogtreecommitdiff
path: root/net/wmnet/patches/patch-ad
blob: 374c93405ab21f18723d352dfeb1c90eb62090d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
$NetBSD: patch-ad,v 1.6 2016/06/23 19:04:54 dholland Exp $

--- wmnet.c.orig	Fri May  5 03:01:14 2000
+++ wmnet.c	Mon Jul  8 16:52:30 2002
@@ -55,9 +55,14 @@
 #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<alloca.h>
+# 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);