27 |
#include <stdlib.h> |
#include <stdlib.h> |
28 |
#include <unistd.h> |
#include <unistd.h> |
29 |
#include <sys/sysinfo.h> |
#include <sys/sysinfo.h> |
30 |
|
#include <time.h> |
31 |
|
|
32 |
/* This is a debug marking function. */ |
/* This is a debug marking function. */ |
33 |
#define ARBUG \ |
#define ARBUG \ |
45 |
Window iconwin; |
Window iconwin; |
46 |
char *swap; |
char *swap; |
47 |
char *users; |
char *users; |
|
char commands[17][16]; |
|
48 |
|
|
49 |
char* |
char* |
50 |
antiright_pipe_read(char *command_string) |
antiright_pipe_read(char *command_string) |
99 |
} |
} |
100 |
|
|
101 |
void |
void |
102 |
|
get_values() |
103 |
|
{ |
104 |
|
if(swap != NULL) |
105 |
|
{ |
106 |
|
free(swap); |
107 |
|
} |
108 |
|
swap= |
109 |
|
antiright_pipe_read("echo `free | grep Swap" |
110 |
|
" | awk '{print $4}'`/1024 | bc"); |
111 |
|
swap[strlen(swap)-1]='\0'; |
112 |
|
if(users != NULL) |
113 |
|
{ |
114 |
|
free(users); |
115 |
|
} |
116 |
|
users=antiright_pipe_read("users | wc | awk '{print $2}'"); |
117 |
|
users[strlen(users)-1]='\0'; |
118 |
|
} |
119 |
|
|
120 |
|
void |
121 |
expose() |
expose() |
122 |
{ |
{ |
123 |
char *string; |
char *string; |
124 |
double load[3]; |
double load[3]; |
125 |
char *hostname=getenv("HOSTNAME"); |
char *hostname=getenv("HOSTNAME"); |
126 |
|
|
127 |
|
get_values(); |
128 |
arshell_set_foreground(220, 218, 213); |
arshell_set_foreground(220, 218, 213); |
129 |
XFillRectangle(display, iconwin, gc, 0, 0, 64, 64); |
XFillRectangle(display, iconwin, gc, 0, 0, 64, 64); |
130 |
getloadavg(load, 3); |
getloadavg(load, 3); |
155 |
|
|
156 |
XFlush(display); |
XFlush(display); |
157 |
} |
} |
158 |
|
void |
159 |
|
event_loop() |
160 |
|
{ |
161 |
|
time_t time0, time1; |
162 |
|
XEvent event; |
163 |
|
int done=0; |
164 |
|
time(&time0); |
165 |
|
time(&time1); |
166 |
|
expose(); |
167 |
|
while(!done) |
168 |
|
{ |
169 |
|
while(XPending(display)) |
170 |
|
{ |
171 |
|
XNextEvent(display, &event); |
172 |
|
switch(event.type) |
173 |
|
{ |
174 |
|
case Expose: |
175 |
|
expose(); |
176 |
|
break; |
177 |
|
case ButtonPress: |
178 |
|
break; |
179 |
|
case ButtonRelease: |
180 |
|
break; |
181 |
|
} |
182 |
|
} |
183 |
|
time(&time1); |
184 |
|
if(difftime(time1, time0)>1) |
185 |
|
{ |
186 |
|
time(&time0); |
187 |
|
expose(); |
188 |
|
} |
189 |
|
else |
190 |
|
{ |
191 |
|
usleep(1000); |
192 |
|
} |
193 |
|
} |
194 |
|
} |
195 |
|
|
196 |
int |
int |
197 |
main(int argc, char **argv) |
main(int argc, char **argv) |
202 |
/*XTextProperty name;*/ |
/*XTextProperty name;*/ |
203 |
XGCValues gcv; |
XGCValues gcv; |
204 |
unsigned long gcm; |
unsigned long gcm; |
|
int done=0; |
|
|
/*XEvent event;*/ |
|
205 |
|
|
206 |
display=XOpenDisplay((char*)getenv("DISPLAY")); |
display=XOpenDisplay((char*)getenv("DISPLAY")); |
207 |
if(display == NULL) |
if(display == NULL) |
245 |
| PointerMotionMask | StructureNotifyMask | EnterWindowMask |
| PointerMotionMask | StructureNotifyMask | EnterWindowMask |
246 |
| LeaveWindowMask |
| LeaveWindowMask |
247 |
| KeyPressMask | KeyReleaseMask); |
| KeyPressMask | KeyReleaseMask); |
|
/*XSetWMName(display, window, &name);*/ |
|
|
|
|
248 |
gcm = GCForeground | GCBackground | GCGraphicsExposures; |
gcm = GCForeground | GCBackground | GCGraphicsExposures; |
249 |
gcv.foreground = BlackPixel(display, DefaultScreen(display)); |
gcv.foreground = BlackPixel(display, DefaultScreen(display)); |
250 |
gcv.background = WhitePixel(display, DefaultScreen(display)); |
gcv.background = WhitePixel(display, DefaultScreen(display)); |
257 |
mywmhints.window_group = window; |
mywmhints.window_group = window; |
258 |
mywmhints.flags = StateHint | IconWindowHint | IconPositionHint |
mywmhints.flags = StateHint | IconWindowHint | IconPositionHint |
259 |
| WindowGroupHint; |
| WindowGroupHint; |
260 |
|
XSetWMHints(display, window, &mywmhints); |
|
|
|
|
XSetWMHints(display, window, &mywmhints); |
|
|
|
|
|
|
|
261 |
XSetCommand(display, window, argv, argc); |
XSetCommand(display, window, argv, argc); |
262 |
XMapWindow(display, window); |
XMapWindow(display, window); |
|
|
|
263 |
expose(); |
expose(); |
264 |
|
event_loop(); |
|
while(!done) |
|
|
{ |
|
|
if(swap != NULL) |
|
|
{ |
|
|
free(swap); |
|
|
} |
|
|
swap= |
|
|
antiright_pipe_read("echo `free | grep Swap" |
|
|
" | awk '{print $4}'`/1024 | bc"); |
|
|
swap[strlen(swap)-1]='\0'; |
|
|
if(users != NULL) |
|
|
{ |
|
|
free(users); |
|
|
} |
|
|
users=antiright_pipe_read("users | wc | awk '{print $2}'"); |
|
|
users[strlen(users)-1]='\0'; |
|
|
expose(); |
|
|
sleep(1); |
|
|
} |
|
265 |
XCloseDisplay(display); |
XCloseDisplay(display); |
266 |
|
return(0); |
267 |
} |
} |