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);
60 int i = sl = strlen(block->icon);
61 while((c = fgetc(cmdf)) != EOF)
64 if (i == sl) { //return empty string if command has no output
68 if (delim[0] != '\0' && --i)
69 for (int j = 0; delim[j]; j++)
70 output[i++] = delim[j];
75 void getcmds(int time)
78 for(int i = 0; i < LENGTH(blocks); i++)
81 if ((current->interval != 0 && time % current->interval == 0) || time == -1)
82 getcmd(current,statusbar[i]);
86 void getsigcmds(int signal)
89 for (int i = 0; i < LENGTH(blocks); i++)
92 if (current->signal == signal)
93 getcmd(current,statusbar[i]);
99 for(int i = 0; i < LENGTH(blocks); i++)
101 if (blocks[i].signal > 0)
102 signal(SIGRTMIN+blocks[i].signal, sighandler);
107 void getstatus(char *str)
110 for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++]))
112 strcpy(str + j, statusbar[i]);
114 for (int i = 0; delim[i]; i++)
121 Display *d = XOpenDisplay(NULL);
125 screen = DefaultScreen(dpy);
126 root = RootWindow(dpy, screen);
127 getstatus(statusstr);
128 XStoreName(dpy, root, statusstr);
138 while(statusContinue)
153 void sighandler(int signum)
155 getsigcmds(signum-SIGRTMIN);
159 void termhandler(int signum)
165 int main(int argc, char** argv)
167 for(int i = 0; i < argc; i++)
169 if (!strcmp("-d",argv[i]))
172 signal(SIGTERM, termhandler);
173 signal(SIGINT, termhandler);