7 #define LENGTH(X) (sizeof(X) / sizeof (X[0]))
12 unsigned int interval;
15 void sighandler(int num);
16 void replace(char *str, char old, char new);
17 void getcmds(int time);
18 void getsigcmds(int signal);
20 void getstatus(char *str);
24 void sighandler(int signum);
25 void termhandler(int signum);
33 static char statusbar[LENGTH(blocks)][50] = {0};
34 static char statusstr[256];
35 static char *statuscat;
36 static const char *volupcmd[] = { "volup", NULL };
37 static const char *voldowncmd[] = { "voldown", NULL };
38 static const char *volmutecmd[] = { "volmute", NULL };
39 static int statusContinue = 1,volmuted = 0;
41 void replace(char *str, char old, char new)
44 for(int i = 0; i < N; i++)
49 //opens process *cmd and stores output in *output
50 void getcmd(const Block *block, char *output)
52 strcpy(output, block->icon);
53 char *cmd = block->command;
54 FILE *cmdf = popen(cmd,"r");
57 //int N = strlen(output);
59 int i = strlen(block->icon);
60 while((c = fgetc(cmdf)) != EOF)
62 if (delim != '\0' && --i)
68 void getcmds(int time)
71 for(int i = 0; i < LENGTH(blocks); i++)
74 if ((current->interval != 0 && time % current->interval == 0) || time == -1)
75 getcmd(current,statusbar[i]);
79 void getsigcmds(int signal)
82 for (int i = 0; i < LENGTH(blocks); i++)
85 if (current->signal == signal)
86 getcmd(current,statusbar[i]);
92 for(int i = 0; i < LENGTH(blocks); i++)
94 if (blocks[i].signal > 0)
95 signal(SIGRTMIN+blocks[i].signal, sighandler);
100 void getstatus(char *str)
103 for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++]))
105 strcpy(str + j, statusbar[i]);
113 Display *d = XOpenDisplay(NULL);
117 screen = DefaultScreen(dpy);
118 root = RootWindow(dpy, screen);
119 getstatus(statusstr);
120 XStoreName(dpy, root, statusstr);
130 while(statusContinue)
145 void sighandler(int signum)
147 getsigcmds(signum-SIGRTMIN);
151 void termhandler(int signum)
157 int main(int argc, char** argv)
159 for(int i = 0; i < argc; i++)
161 if (!strcmp("-d",argv[i]))
162 delim = argv[++i][0];
164 signal(SIGTERM, termhandler);
165 signal(SIGINT, termhandler);