7 #define LENGTH(X) (sizeof(X) / sizeof (X[0]))
11 unsigned int interval;
14 void sighandler(int num);
15 void replace(char *str, char old, char new);
16 void getcmds(int time);
17 void getsigcmds(int signal);
19 void getstatus(char *str);
23 void sighandler(int signum);
24 void termhandler(int signum);
32 static char statusbar[LENGTH(blocks)][50] = {0};
33 static char statusstr[256];
34 static char *statuscat;
35 static const char *volupcmd[] = { "volup", NULL };
36 static const char *voldowncmd[] = { "voldown", NULL };
37 static const char *volmutecmd[] = { "volmute", NULL };
38 static int statusContinue = 1,volmuted = 0;
40 void replace(char *str, char old, char new)
43 for(int i = 0; i < N; i++)
48 //opens process *cmd and stores output in *output
49 void getcmd(char *cmd, char *output)
51 FILE *cmdf = popen(cmd,"r");
54 int N = strlen(output);
57 while((c = fgetc(cmdf)) != EOF)
63 void getcmds(int time)
66 for(int i = 0; i < LENGTH(blocks); i++)
69 if ((current->interval != 0 && time % current->interval == 0) || time == -1)
70 getcmd(current->command,statusbar[i]);
74 void getsigcmds(int signal)
77 for (int i = 0; i < LENGTH(blocks); i++)
80 if (current->signal == signal)
81 getcmd(current->command,statusbar[i]);
87 for(int i = 0; i < LENGTH(blocks); i++)
89 if (blocks[i].signal > 0)
90 signal(SIGRTMIN+blocks[i].signal, sighandler);
95 void getstatus(char *str)
98 for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++]))
100 strcpy(str + j, statusbar[i]);
108 Display *d = XOpenDisplay(NULL);
112 screen = DefaultScreen(dpy);
113 root = RootWindow(dpy, screen);
114 getstatus(statusstr);
115 replace(statusstr,'\n',' ');//gets rid of newlines from output
116 replace(statusstr,EOF,' ');//gets rid of EOF from output
117 XStoreName(dpy, root, statusstr);
127 while(statusContinue)
142 void sighandler(int signum)
144 getsigcmds(signum-SIGRTMIN);
148 void termhandler(int signum)
156 signal(SIGTERM, termhandler);
157 signal(SIGINT, termhandler);